From a68a81a311aa8bba4a10a362c096c17bf3965039 Mon Sep 17 00:00:00 2001 From: Alexandre Garanhao Date: Tue, 23 May 2023 11:06:12 +0100 Subject: [PATCH] lab done --- your_code/main.ipynb | 97 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 85 insertions(+), 12 deletions(-) diff --git a/your_code/main.ipynb b/your_code/main.ipynb index 7810ccf..95b0cd2 100644 --- a/your_code/main.ipynb +++ b/your_code/main.ipynb @@ -1,6 +1,7 @@ { "cells": [ { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -14,14 +15,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "Power_divergenceResult(statistic=6.491310681109786, pvalue=0.483688906853731)" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your answer here" + "# your answer here\n", + "\n", + "from scipy.stats import poisson\n", + "from scipy.stats import chisquare\n", + "\n", + "observed = [35, 99, 104, 110, 62, 25, 10, 3]\n", + "\n", + "expected = [poisson.pmf(0, 2.435)*448, \n", + " poisson.pmf(1, 2.435)*448, \n", + " poisson.pmf(2, 2.435)*448, \n", + " poisson.pmf(3, 2.435)*448, \n", + " poisson.pmf(4, 2.435)*448, \n", + " poisson.pmf(5, 2.435)*448, \n", + " poisson.pmf(6, 2.435)*448, \n", + " (1-poisson.cdf(6, 2.435))*448]\n", + "\n", + "chisquare(f_obs= observed, f_exp= expected)" ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -41,14 +70,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "Power_divergenceResult(statistic=6.248550837473296, pvalue=0.012429495465327692)" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "# your code here\n", + "observed = [32, 15, 13]\n", + "estimated_mean = (32*0+15*1+9*3+4*4)/60\n", + "\n", + "expected = [poisson.pmf(0, estimated_mean)*60,\n", + " poisson.pmf(1, estimated_mean)*60,\n", + " (1-poisson.cdf(1, estimated_mean))*60]\n", + "\n", + "chisquare(f_obs= observed, f_exp= expected, ddof= 1)" ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -60,14 +109,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ - "# your answer here" + "# your answer here\n", + "\n", + "from scipy.stats import binom\n", + "observed = [138, 53, 9]\n", + "expected = [binom.pmf(0, 10, 0.05)*200, \n", + " binom.pmf(1, 10, 0.05)*200, \n", + " (1-binom.cdf(1, 10, 0.05))*200]" ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -79,11 +135,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "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": [ - "#your answer here" + "#your answer here\n", + "import numpy as np\n", + "from scipy.stats import chi2_contingency\n", + "table = np.array([[32, 12], [14, 22], [6, 9]])\n", + "chi2_contingency(table)" ] } ], @@ -103,7 +176,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.3" + "version": "3.11.2" } }, "nbformat": 4,