diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 332f496..15b7e89 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -9,11 +9,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ - "# Libraries" + "# Libraries\n", + "import pandas as pd\n", + "import numpy as np\n", + "import scipy.stats as st" ] }, { @@ -32,11 +35,50 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "(172.14308590115726, 174.79024743217607)" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "# your code here\n", + "heights = np.array([167, 167, 168, 168, 168, 169, 171, 172, 173, 175, 175, 175, 177, 182, 195])\n", + "alpha=0.8\n", + "mean=np.mean(heights)\n", + "std=4\n", + "n=(len(heights)-1)\n", + "st.norm.interval(0.8,loc=mean,scale=std/np.sqrt(len(heights)))" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(170.9019616724727, 176.03137166086063)" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#With t distribuiton because we dont have more than 30 \n", + "std=heights.std(ddof=1)\n", + "st.t.interval(0.8,n-1,loc=mean,scale=std/np.sqrt(len(heights)))" ] }, { @@ -51,11 +93,51 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Our CI for 80% proportion is [0.20248138545542083] [0.3118043288302934]\n", + "Our CI for 90% proportion is [0.18698561776452813] [0.3273000965211861]\n", + "Python Way (0.20248138545542083, 0.3118043288302934) \n", + " (0.1869856177645281, 0.3273000965211861)\n" + ] + } + ], "source": [ - "# your code here" + "# your code \n", + "n=105\n", + "losses=27\n", + "p=losses/n\n", + "confidence_levels=[0.80, 0.90]\n", + "ste=2\n", + "#80% confidence\n", + "\n", + "z_value=st.norm.ppf(1-(1-0.80)/2)\n", + "\n", + "margin_of_error= z_value*np.sqrt((p*(1-p))/n)\n", + "lower_bound= p-margin_of_error\n", + "upper_bound=p+margin_of_error\n", + "\n", + "print(f'Our CI for 80% proportion is [{lower_bound}] [{upper_bound}]')\n", + "#90% confidence\n", + "\n", + "z_value=st.norm.ppf(1-(1-0.90)/2)\n", + "se=np.sqrt((p*(1-p))/n)\n", + "margin_of_error= z_value*se\n", + "lower_bound= p-margin_of_error\n", + "upper_bound=p+margin_of_error\n", + "\n", + "print(f'Our CI for 90% proportion is [{lower_bound}] [{upper_bound}]')\n", + "\n", + "#python way\n", + "\n", + "print('Python Way',\n", + " st.norm.interval(0.80, loc = p, scale = se),'\\n',\n", + " st.norm.interval(0.90, loc = p, scale = se))" ] }, { @@ -76,7 +158,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -94,7 +176,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -121,7 +203,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -145,7 +227,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.11.4" } }, "nbformat": 4,