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
133 changes: 116 additions & 17 deletions your-code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"# Libraries"
"import pandas as pd\n",
"import numpy as np\n",
"import scipy.stats as st\n",
"import math "
]
},
{
Expand All @@ -32,11 +35,34 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"heights = [167, 167, 168, 168, 168, 169, 171, 172, 173, 175, 175, 175, 177, 182, 195]"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Confidence Interval: (171.0323076132764, 175.90102572005694)\n"
]
}
],
"source": [
"sample_mean = np.mean(heights)\n",
"sample_std = np.std(heights, ddof=1) \n",
"confidence_level = 0.80\n",
"sample_size = len(heights)\n",
"margin_of_error = st.norm.ppf((1 + confidence_level) / 2) * (sample_std / np.sqrt(sample_size))\n",
"confidence_interval = (sample_mean - margin_of_error, sample_mean + margin_of_error)\n",
"print(\"Confidence Interval:\", confidence_interval)"
]
},
{
Expand All @@ -51,11 +77,29 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Confidence Interval (level 0.8): (0.20248138545542083, 0.3118043288302934)\n",
"Confidence Interval (level 0.9): (0.18698561776452813, 0.3273000965211861)\n"
]
}
],
"source": [
"# your code here"
"total_shops = 105\n",
"shops_with_losses = 27\n",
"sample_proportion = shops_with_losses / total_shops\n",
"confidence_levels = [0.80, 0.90]\n",
"\n",
"for confidence_level in confidence_levels:\n",
" \n",
" margin_of_error = st.norm.ppf((1 + confidence_level) / 2) * np.sqrt((sample_proportion * (1 - sample_proportion)) / total_shops)\n",
" confidence_interval = (sample_proportion - margin_of_error, sample_proportion + margin_of_error)\n",
" print(f\"Confidence Interval (level {confidence_level}):\", confidence_interval)"
]
},
{
Expand All @@ -76,11 +120,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"heights = [167, 167, 168, 168, 168, 169, 171, 172, 173, 175, 175, 175, 177, 182, 195]"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Required Sample Size: 425\n"
]
}
],
"source": [
"z_alpha_2 = 2.576 \n",
"sigma = 4 \n",
"error_level = 0.5 \n",
"required_sample_size = math.ceil((z_alpha_2 * sigma / error_level)**2)\n",
"print(\"Required Sample Size:\", required_sample_size)"
]
},
{
Expand All @@ -94,11 +159,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Required Sample Size: 3140\n"
]
}
],
"source": [
"# your code here"
"z_alpha_2 = 1.282 \n",
"error_level = 0.01 \n",
"n_total = 105\n",
"n_losses = 27\n",
"p = n_losses / n_total\n",
"q = 1 - p\n",
"required_sample_size = math.ceil((z_alpha_2 ** 2 * p * q) / (error_level ** 2))\n",
"print(\"Required Sample Size:\", required_sample_size)"
]
},
{
Expand All @@ -121,17 +201,36 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Confidence Interval: (6.303419026585921, 25.69658097341408)\n"
]
}
],
"source": [
"# your code here"
"mean_X = 418\n",
"mean_Y = 402\n",
"stddev_X = 26\n",
"stddev_Y = 22\n",
"sample_size_X = 40\n",
"sample_size_Y = 50\n",
"confidence_level = 0.94\n",
"SE = math.sqrt((stddev_X**2 / sample_size_X) + (stddev_Y**2 / sample_size_Y))\n",
"z_score = abs(st.norm.ppf((1 + confidence_level) / 2))\n",
"margin_of_error = z_score * SE\n",
"confidence_interval = (mean_X - mean_Y - margin_of_error, mean_X - mean_Y + margin_of_error)\n",
"print(\"Confidence Interval:\", confidence_interval)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -145,7 +244,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.10.9"
}
},
"nbformat": 4,
Expand Down