From 8a23f4e015ebb70858638eb81c580bca2e491382 Mon Sep 17 00:00:00 2001 From: AnaCarvalho84 <131803922+AnaCarvalho84@users.noreply.github.com> Date: Fri, 11 Aug 2023 22:35:28 +0100 Subject: [PATCH] Lab done --- your-code/main.ipynb | 104 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 94 insertions(+), 10 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 332f496..d2fce6c 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -9,11 +9,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ - "# Libraries" + "# Libraries\n", + "import scipy.stats as st\n", + "import numpy as np\n" ] }, { @@ -32,11 +34,55 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "(172.14308590115726, 174.79024743217607)" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "heights = np.array([167, 167, 168, 168, 168, 169, 171, 172, 173, 175, 175, 175, 177, 182, 195])\n", + "\n", + "alpha = 0.80\n", + "std = 4\n", + "mean = np.mean(heights)\n", + "n = len(heights)\n", + "\n", + "st.norm.interval(0.80, loc=mean, scale = std/np.sqrt(n))" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(170.9117270472475, 176.02160628608584)" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#This is using t distribution, we dont have more than 30 observations\n", + "\n", + "s = heights.std(ddof=1)\n", + "mean = heights.mean()\n", + "n = len(heights)\n", + "\n", + "st.t.interval(0.80, n-1, loc=mean, scale=s/np.sqrt(n))\n" ] }, { @@ -51,11 +97,49 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Our CI for porpotion is [0.20248138545542083,0.3118043288302934]\n" + ] + } + ], "source": [ - "# your code here" + "losses= 27\n", + "p=losses/n\n", + "n=105\n", + "#80% confidence\n", + "z_value = st.norm.ppf(1-(1-0.80)/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", + "print(f\"Our CI for porpotion is [{lower_bound},{upper_bound}]\")" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(0.20248138545542083, 0.3118043288302934)" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#with st.norm - we dont need here the z value \n", + "st.norm.interval(0.80, loc = p, scale = se)" ] }, { @@ -131,7 +215,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -145,7 +229,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.10.9" } }, "nbformat": 4,