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
89 changes: 79 additions & 10 deletions your-code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"# Libraries"
"import pandas as pd\n",
"import numpy as np\n",
"import scipy.stats as stats\n",
"import statistics\n",
"import math"
]
},
{
Expand All @@ -32,11 +36,47 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 28,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"left end: 172.53715066357688\n",
"right end: 174.39618266975646\n"
]
},
{
"data": {
"text/plain": [
"'confidence interval for 80%: (172.14308590115726, 174.79024743217607)'"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# your code here"
"# data given\n",
"heights = [167, 167, 168, 168, 168, 169, 171, 172, 173, 175, 175, 175, 177, 182, 195]\n",
"sigma = 4\n",
"n = len(heights)\n",
"mean = np.mean(heights)\n",
"z = (1-((1-0.80)/2))\n",
"\n",
"#calculating the interval\n",
"print(\"left end: \", mean - z* (sigma/np.sqrt(n)))\n",
"print(\"right end: \", mean + z* (sigma/np.sqrt(n)))\n",
"\n",
"### python way\n",
"\n",
"#converting heights into an array\n",
"a = np.array(heights)\n",
"\n",
"#calcularing the interval\n",
"f'confidence interval for 80%: {st.norm.interval(0.80, loc=mean, scale=sigma/np.sqrt(n))}'"
]
},
{
Expand All @@ -51,11 +91,40 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 22,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"confidence interval 80% = (0.20248138545542083, 0.3118043288302934)\n",
"confidence interval 90% = (0.18698561776452813, 0.3273000965211861)\n"
]
}
],
"source": [
"# your code here"
"shops = 105\n",
"shops_losses = 27\n",
"\n",
"#mean\n",
"mean = shops_with_losses / total_shops\n",
"\n",
"#calculting standard error\n",
"std_error = math.sqrt((sample_proportion * (1 - sample_proportion)) / total_shops)\n",
"\n",
"# prob for 80% and 90%\n",
"z1 = stats.norm.ppf((1 + 0.8) / 2)\n",
"z2 = stats.norm.ppf((1 + 0.9) / 2)\n",
"\n",
"# margin of error for confidence levels\n",
"margin80 = zscore_80 * std_error\n",
"margin90 = zscore_90 * std_error\n",
"\n",
"# confidence intervals\n",
"print(f'confidence interval 80% = {(mean - margin80, mean + margin80)}')\n",
"print(f'confidence interval 90% = {(mean - margin90, mean + margin90)}')\n",
"\n"
]
},
{
Expand Down Expand Up @@ -131,7 +200,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -145,7 +214,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.10.9"
}
},
"nbformat": 4,
Expand Down