Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 134 additions & 11 deletions your_code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,55 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"Power_divergenceResult(statistic=191.93184027673232, pvalue=5.85583627060059e-38)"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# your answer here"
"# your answer here\n",
"from scipy.stats import poisson\n",
"from scipy.stats import chisquare\n",
"import numpy as np\n",
"f_obs = np.array([35,99,104,110,62,25,10,3])\n",
"mean = 2.435\n",
"poisson_dist = poisson(mean)\n",
"poisson_pmfs = np.array([poisson_dist.pmf(i) for i in range(1,8)]) \n",
"poisson_pmfs\n",
"with_tail = np.append(poisson_pmfs,1- poisson_pmfs.sum())\n",
"with_tail\n",
"f_exp = with_tail*448\n",
"f_exp\n",
"chisquare(f_exp = f_exp, f_obs = f_obs)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"5.85583627060059e-38 < 0.05 #REJECT "
]
},
{
Expand Down Expand Up @@ -60,11 +104,36 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"Power_divergenceResult(statistic=336.43955678670346, pvalue=8.771593494342625e-74)"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# your answer here"
"# your answer here\n",
"from scipy.stats import chisquare\n",
"\n",
"observed_frequencies = [138, 53, 9]\n",
"expected_proportion = 0.05\n",
"total_samples = 200\n",
"categories = 3\n",
"\n",
"expected_probabilities = [expected_proportion**i * (1 - expected_proportion)**(categories - i) for i in range(categories)]\n",
"\n",
"expected_frequencies = [total_samples * prob for prob in expected_probabilities]\n",
"\n",
"expected_frequencies_adjusted = [freq * (total_samples / sum(expected_frequencies)) for freq in expected_frequencies]\n",
"\n",
"chisquare(f_obs=observed_frequencies, f_exp=expected_frequencies_adjusted)\n"
]
},
{
Expand All @@ -79,17 +148,71 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 25,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"0.0047192801370408155"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#your answer here"
"#your answer here\n",
"import numpy as np\n",
"from scipy.stats import chi2\n",
"f_obs = np.array([[32, 12], [14, 22], [6, 9]])\n",
"\n",
"row_totals = [44,36,15]\n",
"col_totals = [52,43]\n",
"grand_total = [95]\n",
"\n",
"f_exp = np.outer(row_totals, col_totals) / grand_total\n",
"\n",
"chi2_statistic = np.sum((f_obs - f_exp)**2 / f_exp)\n",
"\n",
"degrees_of_freedom = (f_obs.shape[0] - 1) * (f_obs.shape[1] - 1)\n",
"\n",
"p_value = 1 - chi2.cdf(chi2_statistic, degrees_of_freedom)\n",
"p_value"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"0.0047192801370408155 < 0.05 #Don't Reject"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -103,7 +226,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down