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
18 changes: 18 additions & 0 deletions .ipynb_checkpoints/ReadME-checkpoint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
![logo_ironhack_blue 7](https://user-images.githubusercontent.com/23629340/40541063-a07a0a8a-601a-11e8-91b5-2f13e4e6b441.png)

# Lab | Inferential statistics


### Instructions

1. 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. Is the group significantly different (with respect to systolic blood pressure!) from the regular population?

- Set up the hypothesis test.
- Write down all the steps followed for setting up the test.
- 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.

2. If you finished the previous question, please go through the code for `principal_component_analysis_example` provided in the `files_for_lab` folder .




172 changes: 172 additions & 0 deletions .ipynb_checkpoints/Solutions-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
{
"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": "code",
"execution_count": 22,
"id": "0cd42a8b-2496-4c4a-8556-e957cd80ea30",
"metadata": {},
"outputs": [],
"source": [
"import math"
]
},
{
"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."
]
},
{
"cell_type": "markdown",
"id": "f31fb41a-fa46-42cc-ba83-11bd5b4e82d9",
"metadata": {},
"source": [
"- the mean systolic blood pressure is `μ = 120 mm Hg`.\n",
"- a sample of `n = 100`.\n",
"- average systolic blood pressure of `130.1 mm Hg`.\n",
"- standard deviation of `21.21 mm Hg`."
]
},
{
"cell_type": "markdown",
"id": "6b51262b",
"metadata": {},
"source": [
"The null hypothesis is that the mean blood pressure of people in Honolulu is not significantly different from the population mean and the alternate hypothesis is that the blood pressure of people in Honolulu is significantly different, hence we can use the Z-test to test this hypothesis."
]
},
{
"cell_type": "markdown",
"id": "17c9988a",
"metadata": {},
"source": [
"### 1.2 Write down all the steps followed for setting up the test."
]
},
{
"cell_type": "markdown",
"id": "079381b2-efeb-4942-8764-4c66d4f1f738",
"metadata": {},
"source": [
"- Specify the Null Hypothesis\n",
"- Specify the Alternative Hypothesis\n",
"- Set the Significance Level\n",
"- Calculate the Test Statistic (t | Z test) \n",
"- Calculate the corresponding P-Value\n",
"- Conclusion"
]
},
{
"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": 18,
"id": "97f73e20",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The test statistic is: 4.76190\n"
]
}
],
"source": [
"sample_mean = 130.1\n",
"pop_mean = 120\n",
"sample_std = 21.21\n",
"n = 100\n",
"\n",
"#Z = ((130.1 - 120) / (21.21 / 10))\n",
"test_statistic = ( (130.1 - 120) / (21.21 / (n**0.5)) )\n",
"print(f\"The test statistic is: {statistic:.5f}\")"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "afcc7acd",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The Z test is: 4.76190\n"
]
}
],
"source": [
"sample_mean = 130.1\n",
"pop_mean = 120\n",
"sample_std = 21.21\n",
"n = 100\n",
"\n",
"Z = ( (sample_mean - pop_mean) / (sample_std / math.sqrt(n)) )\n",
"print(f\"The Z test is: {Z:.5f}\")"
]
},
{
"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 ."
]
}
],
"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.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
95 changes: 81 additions & 14 deletions Solutions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
"- 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": "code",
"execution_count": 22,
"id": "0cd42a8b-2496-4c4a-8556-e957cd80ea30",
"metadata": {},
"outputs": [],
"source": [
"import math"
]
},
{
"cell_type": "markdown",
"id": "120875d3",
Expand All @@ -33,12 +43,23 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "39c6f717",
"cell_type": "markdown",
"id": "f31fb41a-fa46-42cc-ba83-11bd5b4e82d9",
"metadata": {},
"outputs": [],
"source": []
"source": [
"- the mean systolic blood pressure is `μ = 120 mm Hg`.\n",
"- a sample of `n = 100`.\n",
"- average systolic blood pressure of `130.1 mm Hg`.\n",
"- standard deviation of `21.21 mm Hg`."
]
},
{
"cell_type": "markdown",
"id": "6b51262b",
"metadata": {},
"source": [
"The null hypothesis is that the mean blood pressure of people in Honolulu is not significantly different from the population mean and the alternate hypothesis is that the blood pressure of people in Honolulu is significantly different, hence we can use the Z-test to test this hypothesis."
]
},
{
"cell_type": "markdown",
Expand All @@ -49,12 +70,17 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b09ce149",
"cell_type": "markdown",
"id": "079381b2-efeb-4942-8764-4c66d4f1f738",
"metadata": {},
"outputs": [],
"source": []
"source": [
"- Specify the Null Hypothesis\n",
"- Specify the Alternative Hypothesis\n",
"- Set the Significance Level\n",
"- Calculate the Test Statistic (t | Z test) \n",
"- Calculate the corresponding P-Value\n",
"- Conclusion"
]
},
{
"cell_type": "markdown",
Expand All @@ -66,11 +92,52 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"id": "97f73e20",
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The test statistic is: 4.76190\n"
]
}
],
"source": [
"sample_mean = 130.1\n",
"pop_mean = 120\n",
"sample_std = 21.21\n",
"n = 100\n",
"\n",
"#Z = ((130.1 - 120) / (21.21 / 10))\n",
"test_statistic = ( (130.1 - 120) / (21.21 / (n**0.5)) )\n",
"print(f\"The test statistic is: {statistic:.5f}\")"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "afcc7acd",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The Z test is: 4.76190\n"
]
}
],
"source": [
"sample_mean = 130.1\n",
"pop_mean = 120\n",
"sample_std = 21.21\n",
"n = 100\n",
"\n",
"Z = ( (sample_mean - pop_mean) / (sample_std / math.sqrt(n)) )\n",
"print(f\"The Z test is: {Z:.5f}\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -97,7 +164,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.8.8"
}
},
"nbformat": 4,
Expand Down
Loading