diff --git a/.ipynb_checkpoints/Solutions-checkpoint.ipynb b/.ipynb_checkpoints/Solutions-checkpoint.ipynb new file mode 100644 index 0000000..03287dd --- /dev/null +++ b/.ipynb_checkpoints/Solutions-checkpoint.ipynb @@ -0,0 +1,208 @@ +{ + "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": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import numpy as np\n", + "import datetime\n", + "import warnings\n", + "import matplotlib.pyplot as plt\n", + "import seaborn as sns\n", + "import math\n", + "from scipy.stats import ttest_ind\n", + "warnings.filterwarnings('ignore')" + ] + }, + { + "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": "markdown", + "metadata": {}, + "source": [ + "see below" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 1.2 Write down all the steps followed for setting up the test." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "https://www.scribbr.com/statistics/hypothesis-testing/\n", + "
\n", + "Hypothesis testing is a formal procedure for investigating our ideas about the world using statistics. It is most often used by scientists to test specific predictions, called hypotheses, that arise from theories.\n", + "
\n", + "There are 5 main steps in hypothesis testing:
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### State your research hypothesis as null (H0) and alternate (Ha) hypothesis." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Ho: Systolic blood pressure, on average, not higher than regular population.
\n", + "Ha: Systolic blood pressure, on average, higher than regular population." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Collect data in a way designed to test the hypothesis." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "mean systolic blood pressure is μ = 120 mm Hg
\n", + "a sample of n = 100 people had an average systolic blood pressure of 130.1 mm Hg
\n", + "with a standard deviation of 21.21 mm Hg." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Perform an appropriate statistical test." + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4.7619" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mean_population = 120\n", + "sample_mean = 130.1\n", + "stdev = 21.21\n", + "n = 100\n", + "\n", + "t = ((sample_mean - mean_population) / (stdev / math.sqrt(n)))\n", + "\n", + "round(t,5)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Decide whether the null hypothesis is supported or refuted." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Present the findings in your results and discussion section." + ] + }, + { + "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": "markdown", + "metadata": {}, + "source": [ + "see 1.1.2.3" + ] + }, + { + "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" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": true, + "sideBar": true, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/Solutions.ipynb b/Solutions.ipynb index b3e2431..03287dd 100644 --- a/Solutions.ipynb +++ b/Solutions.ipynb @@ -2,7 +2,6 @@ "cells": [ { "cell_type": "markdown", - "id": "e00a11f1", "metadata": {}, "source": [ "# Lab | Inferential statistics" @@ -10,15 +9,30 @@ }, { "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": 29, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import numpy as np\n", + "import datetime\n", + "import warnings\n", + "import matplotlib.pyplot as plt\n", + "import seaborn as sns\n", + "import math\n", + "from scipy.stats import ttest_ind\n", + "warnings.filterwarnings('ignore')" + ] + }, { "cell_type": "markdown", - "id": "120875d3", "metadata": {}, "source": [ "## 1. Is the group significantly different (with respect to systolic blood pressure!) from the regular population?" @@ -26,55 +40,131 @@ }, { "cell_type": "markdown", - "id": "d26c43d4", "metadata": {}, "source": [ "### 1.1 Set up the hypothesis test." ] }, { - "cell_type": "code", - "execution_count": null, - "id": "39c6f717", + "cell_type": "markdown", "metadata": {}, - "outputs": [], - "source": [] + "source": [ + "see below" + ] }, { "cell_type": "markdown", - "id": "17c9988a", "metadata": {}, "source": [ "### 1.2 Write down all the steps followed for setting up the test." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "https://www.scribbr.com/statistics/hypothesis-testing/\n", + "
\n", + "Hypothesis testing is a formal procedure for investigating our ideas about the world using statistics. It is most often used by scientists to test specific predictions, called hypotheses, that arise from theories.\n", + "
\n", + "There are 5 main steps in hypothesis testing:
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### State your research hypothesis as null (H0) and alternate (Ha) hypothesis." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Ho: Systolic blood pressure, on average, not higher than regular population.
\n", + "Ha: Systolic blood pressure, on average, higher than regular population." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Collect data in a way designed to test the hypothesis." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "mean systolic blood pressure is μ = 120 mm Hg
\n", + "a sample of n = 100 people had an average systolic blood pressure of 130.1 mm Hg
\n", + "with a standard deviation of 21.21 mm Hg." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Perform an appropriate statistical test." + ] + }, { "cell_type": "code", - "execution_count": null, - "id": "b09ce149", + "execution_count": 36, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "4.7619" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mean_population = 120\n", + "sample_mean = 130.1\n", + "stdev = 21.21\n", + "n = 100\n", + "\n", + "t = ((sample_mean - mean_population) / (stdev / math.sqrt(n)))\n", + "\n", + "round(t,5)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Decide whether the null hypothesis is supported or refuted." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Present the findings in your results and discussion section." + ] }, { "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", + "cell_type": "markdown", "metadata": {}, - "outputs": [], - "source": [] + "source": [ + "see 1.1.2.3" + ] }, { "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 ." @@ -98,6 +188,19 @@ "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": true, + "sideBar": true, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": false } }, "nbformat": 4,