Skip to content
Open
Show file tree
Hide file tree
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
173 changes: 173 additions & 0 deletions .ipynb_checkpoints/Solutions-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Lab | Inferential statistics"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- It is assumed that the mean systolic blood pressure is `μ = 120 mm Hg`. In the Honolulu Heart Study, a sample of `n = 100` people had an average systolic blood pressure of 130.1 mm Hg with a standard deviation of 21.21 mm Hg. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. Is the group significantly different (with respect to systolic blood pressure!) from the regular population?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1.1 Set up the hypothesis test."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"H0 = 120\n",
"HA =! 120"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1.2 Write down all the steps followed for setting up the test."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"import math\n",
"\n",
"sample_mean = 130.1\n",
"pop_mean = 120\n",
"sample_std = 21.21\n",
"n = 100"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"from scipy.stats import ttest_ind, norm\n",
"sample = norm.rvs(loc=sample_mean, scale=sample_std, size=n)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([125.87272186, 147.33041173, 148.31785028, 112.04380437,\n",
" 109.29670776, 142.88049757, 89.87184986, 144.59255735,\n",
" 143.98751965, 164.13942162, 150.14885634, 148.8038505 ,\n",
" 128.61028065, 97.73265084, 138.41288628, 148.81005023,\n",
" 89.80889773, 155.34525738, 94.20433297, 118.01147848,\n",
" 140.33613584, 98.86538375, 120.84419938, 125.50754501,\n",
" 169.98167304, 141.64637665, 122.23356583, 118.33330743,\n",
" 136.95867209, 138.49118087, 156.95988839, 98.2508438 ,\n",
" 105.38052451, 136.69245243, 127.63471356, 121.13244895,\n",
" 123.20426934, 130.25377353, 139.0563798 , 92.73221543,\n",
" 116.59123023, 131.78706465, 160.76714288, 150.08038636,\n",
" 138.16101622, 147.63416238, 115.39205312, 154.02299445,\n",
" 71.19098511, 167.47047571, 131.10517644, 113.06360969,\n",
" 143.55792341, 132.26443597, 82.90132016, 120.84780507,\n",
" 134.02454364, 98.29619475, 126.99829157, 144.19791731,\n",
" 145.6729652 , 148.25716342, 123.13796532, 99.30986144,\n",
" 156.64771966, 137.99025548, 116.97487254, 130.85454744,\n",
" 138.81399206, 127.17536482, 140.91634457, 109.51305907,\n",
" 145.28927328, 152.36994104, 115.37969632, 121.37670788,\n",
" 152.46644509, 136.32657518, 153.70028065, 116.50992758,\n",
" 139.82744355, 145.91862428, 101.27965477, 134.87463457,\n",
" 114.09559859, 152.65867141, 128.41457124, 128.41892265,\n",
" 136.86075007, 153.13865868, 141.7593169 , 110.19926965,\n",
" 120.78665058, 106.86669336, 114.7615379 , 125.5866693 ,\n",
" 132.16603016, 103.11045235, 80.66212071, 125.76824276])"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sample"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1.3 Calculate the test statistic by hand and also code it in Python. It should be 4.76190. We will take a look at how to make decisions based on this calculated value."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4.761904761904759"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"statistic = (sample_mean - pop_mean)/(sample_std/math.sqrt(n))\n",
"statistic"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2. If you finished the previous question, please go through the code for principal_component_analysis_example provided in the files_for_lab folder ."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
100 changes: 84 additions & 16 deletions Solutions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,27 @@
"cells": [
{
"cell_type": "markdown",
"id": "e00a11f1",
"metadata": {},
"source": [
"# Lab | Inferential statistics"
]
},
{
"cell_type": "markdown",
"id": "2c813f0a",
"metadata": {},
"source": [
"- It is assumed that the mean systolic blood pressure is `μ = 120 mm Hg`. In the Honolulu Heart Study, a sample of `n = 100` people had an average systolic blood pressure of 130.1 mm Hg with a standard deviation of 21.21 mm Hg. "
]
},
{
"cell_type": "markdown",
"id": "120875d3",
"metadata": {},
"source": [
"## 1. Is the group significantly different (with respect to systolic blood pressure!) from the regular population?"
]
},
{
"cell_type": "markdown",
"id": "d26c43d4",
"metadata": {},
"source": [
"### 1.1 Set up the hypothesis test."
Expand All @@ -35,46 +31,118 @@
{
"cell_type": "code",
"execution_count": null,
"id": "39c6f717",
"metadata": {},
"outputs": [],
"source": []
"source": [
"H0 = 120\n",
"HA =! 120"
]
},
{
"cell_type": "markdown",
"id": "17c9988a",
"metadata": {},
"source": [
"### 1.2 Write down all the steps followed for setting up the test."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b09ce149",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": []
"source": [
"import math\n",
"\n",
"sample_mean = 130.1\n",
"pop_mean = 120\n",
"sample_std = 21.21\n",
"n = 100"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"from scipy.stats import ttest_ind, norm\n",
"sample = norm.rvs(loc=sample_mean, scale=sample_std, size=n)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([125.87272186, 147.33041173, 148.31785028, 112.04380437,\n",
" 109.29670776, 142.88049757, 89.87184986, 144.59255735,\n",
" 143.98751965, 164.13942162, 150.14885634, 148.8038505 ,\n",
" 128.61028065, 97.73265084, 138.41288628, 148.81005023,\n",
" 89.80889773, 155.34525738, 94.20433297, 118.01147848,\n",
" 140.33613584, 98.86538375, 120.84419938, 125.50754501,\n",
" 169.98167304, 141.64637665, 122.23356583, 118.33330743,\n",
" 136.95867209, 138.49118087, 156.95988839, 98.2508438 ,\n",
" 105.38052451, 136.69245243, 127.63471356, 121.13244895,\n",
" 123.20426934, 130.25377353, 139.0563798 , 92.73221543,\n",
" 116.59123023, 131.78706465, 160.76714288, 150.08038636,\n",
" 138.16101622, 147.63416238, 115.39205312, 154.02299445,\n",
" 71.19098511, 167.47047571, 131.10517644, 113.06360969,\n",
" 143.55792341, 132.26443597, 82.90132016, 120.84780507,\n",
" 134.02454364, 98.29619475, 126.99829157, 144.19791731,\n",
" 145.6729652 , 148.25716342, 123.13796532, 99.30986144,\n",
" 156.64771966, 137.99025548, 116.97487254, 130.85454744,\n",
" 138.81399206, 127.17536482, 140.91634457, 109.51305907,\n",
" 145.28927328, 152.36994104, 115.37969632, 121.37670788,\n",
" 152.46644509, 136.32657518, 153.70028065, 116.50992758,\n",
" 139.82744355, 145.91862428, 101.27965477, 134.87463457,\n",
" 114.09559859, 152.65867141, 128.41457124, 128.41892265,\n",
" 136.86075007, 153.13865868, 141.7593169 , 110.19926965,\n",
" 120.78665058, 106.86669336, 114.7615379 , 125.5866693 ,\n",
" 132.16603016, 103.11045235, 80.66212071, 125.76824276])"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sample"
]
},
{
"cell_type": "markdown",
"id": "63df3700",
"metadata": {},
"source": [
"### 1.3 Calculate the test statistic by hand and also code it in Python. It should be 4.76190. We will take a look at how to make decisions based on this calculated value."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "97f73e20",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"data": {
"text/plain": [
"4.761904761904759"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"statistic = (sample_mean - pop_mean)/(sample_std/math.sqrt(n))\n",
"statistic"
]
},
{
"cell_type": "markdown",
"id": "4a7564e5",
"metadata": {},
"source": [
"## 2. If you finished the previous question, please go through the code for principal_component_analysis_example provided in the files_for_lab folder ."
Expand Down
Loading