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
113 changes: 103 additions & 10 deletions your_code/main.ipynb → your_code/GoodnessFitLab.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,46 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# your answer here"
"import scipy.stats as st\n",
"import numpy as np\n",
"from scipy.stats import geom\n",
"from scipy.stats import poisson"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Power_divergenceResult(statistic=nan, pvalue=nan)"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"p = 2.435\n",
"\n",
"geom_dist = geom(p)\n",
"\n",
"geom_pmfs = np.array([geom_dist.pmf(i) for i in range(0, 7)])\n",
"\n",
"geom_pmfs_tail = np.append(geom_pmfs, 1 - geom_dist.cdf(7)) \n",
"\n",
"f_exp = geom_pmfs_tail* 200 # WHAT IS THIS 200???\n",
"\n",
"f_obs = np.array([35, 99, 104, 110, 62, 25, 10, 3])\n",
"\n",
"st.chisquare(f_obs=f_obs, f_exp=f_exp)"
]
},
{
Expand Down Expand Up @@ -60,11 +95,45 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"We CAN reject the null hypothesis\n",
"p-value: 0.011503557379296871\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/var/folders/d9/783c_j055nj0b0y037qm_1zc0000gn/T/ipykernel_37151/92150982.py:13: DeprecationWarning: 'binom_test' is deprecated in favour of 'binomtest' from version 1.7.0 and will be removed in Scipy 1.12.0.\n",
" p_value = st.binom_test(defective_tires, n, p)\n"
]
}
],
"source": [
"# your answer here"
"n = 10\n",
"p = 0.05\n",
"\n",
"# σ = sqrt(n * p * (1 - p)) = sqrt(10 * 0.05 * (1 - 0.05)) ≈ 0.71\n",
"# z = (x - μ) / σ\n",
"# Expected number of defective tires (μ) = p * n = 0.05 * 10 = 0.5\n",
"# The observed number of defective tires x = 14 (recorded over 200 days).\n",
"\n",
"z = (14 - 0.5) / 0.71\n",
"\n",
"defective_tires = 3\n",
"\n",
"p_value = st.binom_test(defective_tires, n, p)\n",
"if p_value < alpha:\n",
" print(\"We CAN reject the null hypothesis\")\n",
"else:\n",
" print(\"We CAN NOT reject the null hypothesis\")\n",
"print(\"p-value:\", p_value)"
]
},
{
Expand All @@ -79,17 +148,41 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"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": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"kids_table = [[32, 12], [14, 22], [6, 9]]\n",
"\n",
"alpha = 0.05\n",
"\n",
"st.chi2_contingency(kids_table)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"#your answer here"
"Hypothesis Rejected "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -103,7 +196,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.10.9"
}
},
"nbformat": 4,
Expand Down