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
76 changes: 66 additions & 10 deletions your_code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,38 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"chi-square statistic: 9.221114758837274\n",
"p-value: nan\n"
]
}
],
"source": [
"# your answer here"
"# your answer here\n",
"import pandas as pd\n",
"import numpy as np \n",
"import math\n",
"\n",
"\n",
"observed = np.array([35, 99, 104, 110, 62, 25, 10, 3])\n",
"total_observed = np.sum(observed)\n",
"expected = np.zeros_like(observed)\n",
"\n",
"for i in range(len(observed) - 1):\n",
" expected[i] = total_observed * np.exp(-2.435) * (2.435 ** i) / np.math.factorial(i)\n",
"\n",
"expected[-1] = total_observed - np.sum(expected[:-1])\n",
"\n",
"chi2_statistic, p_value = chisquare(observed, f_exp=expected, ddof=len(observed) - 1)\n",
"\n",
"print(\"chi-square statistic:\", chi2_statistic)\n",
"print(\"p-value:\", p_value)"
]
},
{
Expand Down Expand Up @@ -60,11 +87,38 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Reject the null hypothesis\n",
"p-value: 2.836275601197004e-31\n"
]
}
],
"source": [
"# your answer here"
"# your answer here\n",
"\n",
"from scipy.stats import binom_test\n",
"\n",
"observed_defective = 10 \n",
"total_days = 200\n",
"n = 10 \n",
"p = 0.05 \n",
"\n",
"p_value = binom_test(observed_defective, n=total_days * n, p=p)\n",
"\n",
"alpha = 0.05 \n",
"\n",
"if p_value < alpha:\n",
" print(\"Reject the null hypothesis\")\n",
"else:\n",
" print(\"Fail to reject the null hypothesis.\")\n",
"\n",
"print(\"p-value:\", p_value)"
]
},
{
Expand All @@ -79,17 +133,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"#your answer here"
"#your answer here\n",
"from scipy.stats import chi2_contingency\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -103,7 +159,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.9.13"
}
},
"nbformat": 4,
Expand Down