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
130 changes: 123 additions & 7 deletions your_code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,48 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"# your answer here"
"# your answer here\n",
"import scipy.stats as st\n",
"import numpy as np\n",
"from scipy.stats import poisson\n",
"\n",
"mean = 2.435"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Power_divergenceResult(statistic=191.93184027673232, pvalue=5.85583627060059e-38)"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"poisson_dist = poisson(mean)\n",
"\n",
"O = np.array([35,99,104,110,62,25,10,3])\n",
"\n",
"poisson_pmfs = (np.array([poisson_dist.pmf(i) for i in range(1,8)]))\n",
"more = 1 - poisson_pmfs.sum()\n",
"\n",
"E = np.append(poisson_pmfs, more)*448\n",
"\n",
"st.chisquare(f_obs = O, f_exp=E)\n",
"\n",
"#As the p-value is less than alpha, we can reject the H0"
]
},
{
Expand Down Expand Up @@ -60,11 +97,46 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"# your answer here"
"# your answer here\n",
"from scipy.stats import binom\n",
"\n",
"n = 10\n",
"p = 0.05\n",
"\n",
"binomial_dist = binom(n,p)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Power_divergenceResult(statistic=291.0127591046915, pvalue=6.417742364737099e-64)"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"O = np.array([138,53,9])\n",
"\n",
"poisson_pmfs = (np.array([binomial_dist.pmf(i) for i in range(1,3)]))\n",
"more = 1 - poisson_pmfs.sum()\n",
"\n",
"E = np.append(poisson_pmfs, more)*200\n",
"\n",
"st.chisquare(f_obs = O, f_exp=E)\n",
"\n",
"#The p-value is less than the alpha, so we can reject the H0"
]
},
{
Expand All @@ -77,19 +149,63 @@
"![](table4.png)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"#your answer here\n",
"\n",
"##H0: there is no association between patterns of physical activity & consumption of sugary drinks\n",
"##H1: there is an association between patterns of physical activity & consumption of sugary drinks\n",
"\n",
"##significance level\n",
"alpha = 0.05\n",
"\n",
"##we need to create a variable with the observed values \n",
"fifth_grade_table = np.array([\n",
" [32, 12],\n",
" [14,22],\n",
" [6,9],\n",
" ])"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Chi2ContingencyResult(statistic=10.712198008709638, pvalue=0.004719280137040844, dof=2, expected_freq=array([[24.08421053, 19.91578947],\n",
" [19.70526316, 16.29473684],\n",
" [ 8.21052632, 6.78947368]]))"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"st.chi2_contingency(fifth_grade_table)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#your answer here"
"#alpha is greater than the p-value, so, we can not reject the H0\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -103,7 +219,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.9.13"
}
},
"nbformat": 4,
Expand Down