From 6cc6bd464a634c7e3110a4ae118ee2c3003ed398 Mon Sep 17 00:00:00 2001 From: Marisan13 <96127669+Marisan13@users.noreply.github.com> Date: Mon, 20 Nov 2023 12:46:36 +0000 Subject: [PATCH] Lab done --- your_code/main.ipynb | 102 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 97 insertions(+), 5 deletions(-) diff --git a/your_code/main.ipynb b/your_code/main.ipynb index 7810ccf..9e0a3b8 100644 --- a/your_code/main.ipynb +++ b/your_code/main.ipynb @@ -12,13 +12,45 @@ "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": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Power_divergenceResult(statistic=6.491310681109821, pvalue=0.4836889068537269)" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import numpy as np\n", + "import scipy.stats as st \n", + "from scipy.stats import poisson\n", + "\n", + "f_obs = [35,99,104,110,62,25,10,3]\n", + "mu = 2.435\n", + "\n", + "poisson_dist = poisson(mu) \n", + "poisson_pmfs = np.array([poisson_dist.pmf(i) for i in range(0,7)])\n", + "with_tail = np.append(poisson_pmfs, 1 - poisson_pmfs.sum())\n", + "f_exp = with_tail * 448\n", + "\n", + "st.chisquare(f_exp = f_exp, f_obs = f_obs)" + ] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "# your answer here" + "# I can not reject the claim (there is reason to believe) that the number of scores follows a poisson distribution." ] }, { @@ -58,13 +90,46 @@ "![](table3.png)\n" ] }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Power_divergenceResult(statistic=8.306179519542805, pvalue=0.015715783395950887)" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from scipy.stats import binom \n", + "\n", + "f_obs = [138,53,9]\n", + "\n", + "p = 0.05\n", + "n = 10\n", + "\n", + "binomial_dist = binom(n,p)\n", + "binomial_pmfs = np.array([binomial_dist.pmf(i) for i in range(0,2)])\n", + "with_tail = np.append(binomial_pmfs, 1 - binomial_pmfs.sum())\n", + "f_exp = with_tail * 200\n", + "\n", + "st.chisquare(f_exp = f_exp, f_obs = f_obs)" + ] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "# your answer here" + "# We can reject the null hypothesis. \n", + "# The data suggests that the observed frequencies significantly differ from the expected frequencies based on the assumption that 5% of all tires have defects." ] }, { @@ -77,19 +142,46 @@ "![](table4.png)" ] }, + { + "cell_type": "code", + "execution_count": 7, + "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": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "table = [[32,12],\n", + " [14,22],\n", + " [6,9]]\n", + "\n", + "st.chi2_contingency(table)" + ] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "#your answer here" + "# We can reject the null hypothesis.\n", + "# There is a significant association between patterns of physical activity and the consumption of sugary drinks among the fifth-grade children in this school." ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -103,7 +195,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.3" + "version": "3.11.3" } }, "nbformat": 4,