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
147 changes: 138 additions & 9 deletions your_code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,77 @@
"Based on these results, we create a Poisson distribution with the sample mean parameter = 2.435. Is there any reason to believe that at a .05 level the number of scores is a Poisson variable?"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# your answer here\n",
"\n",
"\n",
"from scipy.stats import poisson\n",
"import numpy as np\n",
"import scipy.stats as st\n",
"\n",
"from scipy.stats import binom"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"We can not reject the null hypothesis\n",
"p-value: 0.4836889068537269\n"
]
}
],
"source": [
"# H0: The number of scores is a Poisson variable (with a sample mean parameter = 2.435)\n",
"# H1: he number of scores is not a Poisson variable (with a sample mean parameter = 2.435)\n",
"\n",
"O = np.array([35, 99, 104, 110, 62, 25, 10, 3])\n",
"\n",
"population = O.sum() # population total\n",
"\n",
"mean = 2.435 # sample mean\n",
"\n",
"alpha = 0.05\n",
"\n",
"poisson_dist = poisson(mean)\n",
"\n",
"poisson_pmfs = np.array([poisson_dist.pmf(i) for i in range(0, 7)])\n",
"\n",
"tail = 1 - poisson_pmfs.sum()\n",
"\n",
"poisson_with_tail = np.append(poisson_pmfs, tail)\n",
"\n",
"E = poisson_with_tail * population\n",
"\n",
"chisquare_result = st.chisquare(f_obs = O, f_exp = E)\n",
"\n",
"if chisquare_result.pvalue < alpha:\n",
" print(\"We can reject the null hypothesis\")\n",
"else:\n",
" print(\"We can not reject the null hypothesis\")\n",
" \n",
"print(\"p-value:\", chisquare_result.pvalue)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your answer here"
"\"\"\"\n",
"There is reason to believe that the number of scores is a Poisson variable\n",
"\"\"\""
]
},
{
Expand Down Expand Up @@ -60,11 +124,49 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"We can reject the null hypothesis\n",
"p-value: 0.015715783395950887\n"
]
}
],
"source": [
"# your answer here"
"# your answer here\n",
"\n",
"# H0: The sample comes from a binomial population (with n = 10 and p = 0.05)\n",
"# H1: The sample does not come from a binomial population (with n = 10 and p = 0.05)\n",
"\n",
"O = np.array([138, 53, 9])\n",
"\n",
"population = O.sum()\n",
"n = 10\n",
"p = 0.05\n",
"alpha = 0.05 # assume\n",
"\n",
"binom_dist = binom(n, p)\n",
"\n",
"binom_pmfs = np.array([binom_dist.pmf(i) for i in range(0, 2)])\n",
"\n",
"tail = 1 - binom_pmfs.sum()\n",
"\n",
"binom_with_tail = np.append(binom_pmfs, tail)\n",
"\n",
"E = binom_with_tail * population\n",
"\n",
"chisquare_result = st.chisquare(f_obs = O, f_exp = E)\n",
"\n",
"if chisquare_result.pvalue < alpha:\n",
" print(\"We can reject the null hypothesis\")\n",
"else:\n",
" print(\"We can not reject the null hypothesis\")\n",
" \n",
"print(\"p-value:\", chisquare_result.pvalue)"
]
},
{
Expand All @@ -79,17 +181,44 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"We can reject the null hypothesis\n",
"p-value: 0.004719280137040844\n"
]
}
],
"source": [
"#your answer here"
"#your answer here\n",
"\n",
"# H0: there is no association between patterns of physical activity and the consumption of sugary drinks\n",
"# H1: there is an association between patterns of physical activity and the consumption of sugary drinks\n",
"\n",
"alpha = 0.05\n",
"\n",
"activity = np.array([[32, 12], \n",
" [14, 22], \n",
" [6, 9]])\n",
"\n",
"chiscquare_contigency_result = st.chi2_contingency(activity)\n",
"\n",
"if chiscquare_contigency_result.pvalue < alpha:\n",
" print(\"We can reject the null hypothesis\")\n",
"else:\n",
" print(\"We can not reject the null hypothesis\")\n",
" \n",
"print(\"p-value:\", chiscquare_contigency_result.pvalue)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -103,7 +232,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.10.9"
}
},
"nbformat": 4,
Expand Down