{ "cells": [ { "cell_type": "markdown", "id": "f038cfcb", "metadata": {}, "source": [ "# Tutorial exercises\n", "\n", "We again use the wellbeing dataset, to practice running permutation tests.\n", "\n", "### Set up Python libraries\n", "\n", "As usual, run the code cell below to import the relevant Python libraries" ] }, { "cell_type": "code", "execution_count": 1, "id": "e89735f8", "metadata": {}, "outputs": [], "source": [ "# Set-up Python libraries - you need to run this but you don't need to change it\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import scipy.stats as stats\n", "import pandas \n", "import seaborn as sns" ] }, { "cell_type": "markdown", "id": "661b65c2", "metadata": {}, "source": [ "## Colab users\n", "\n", "You need to use a more recent version of scipy.stats than the default. To do this run the following code block and *after* it has run, go to the menus at the top of colab and click `runtime-->Restart Runtime`" ] }, { "cell_type": "code", "execution_count": null, "id": "2fec5a73", "metadata": {}, "outputs": [], "source": [ "# Set-up Python libraries - you need to run this but you don't need to change it\n", "!pip install scipy==1.10.0\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import scipy.stats as stats\n", "import pandas \n", "import seaborn as sns" ] }, { "cell_type": "markdown", "id": "81aad7c0", "metadata": {}, "source": [ "### Import and view the data" ] }, { "cell_type": "code", "execution_count": 3, "id": "741e30af", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ID_codeCollegeSubjectScore_preVacScore_postVac
0247610LonsdalePPE6035
1448590LonsdalePPE4344
2491100Lonsdaleengineering7969
3316150LonsdalePPE5561
4251870Lonsdaleengineering6265
..................
296440570Beauforthistory7570
297826030Beaufortmaths5249
298856260BeaufortBiology8384
299947060Beaufortengineering6265
300165780BeaufortPPE4856
\n", "

301 rows × 5 columns

\n", "
" ], "text/plain": [ " ID_code College Subject Score_preVac Score_postVac\n", "0 247610 Lonsdale PPE 60 35\n", "1 448590 Lonsdale PPE 43 44\n", "2 491100 Lonsdale engineering 79 69\n", "3 316150 Lonsdale PPE 55 61\n", "4 251870 Lonsdale engineering 62 65\n", ".. ... ... ... ... ...\n", "296 440570 Beaufort history 75 70\n", "297 826030 Beaufort maths 52 49\n", "298 856260 Beaufort Biology 83 84\n", "299 947060 Beaufort engineering 62 65\n", "300 165780 Beaufort PPE 48 56\n", "\n", "[301 rows x 5 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "wb = pandas.read_csv('https://raw.githubusercontent.com/jillxoreilly/StatsCourseBook/main/data/WellbeingSample.csv')\n", "wb" ] }, { "cell_type": "markdown", "id": "58d05f94", "metadata": {}, "source": [ "### Questions\n", "\n", "In each case, you will need to decide:\n", " \n", "* what is our null hypothesis\n", "* what is our alternative hypothesis?\n", "\n", "Is it a paired or unpaired test for difference of means, or a correlation test?\n", "* therefore which `permutation_type` is needed, `samples`, `pairings` or `independent`?\n", " \n", "Is it a one- or two-tailed test?\n", "* therefore which `alternative` hypothesis type is needed, `two-sided`, `greater` or `less`?\n", "\n", "What $\\alpha$ value will you use?\n", "* what value must $p$ be smaller than, to reject the null hypothesis?\n", "* this is the experimenter's choice but usually 0.05 is used (sometimes 0.001 or 0.001)\n", "\n", "\n", "#### Test the following hypotheses:\n", " \n", "1. Wellbeing scores pre- and post-vac are correlated in engineering students\n", "2. There is a difference in the wellbeing scores of PPE students between Beaufort or Lonsdale (before the vacation)?\n", "3. Wellbeing over all students increases across the vacation\n", "\n", "#### Slightly harder one:\n", "\n", "4. Wellbeing increases more across the vacation for Beaufort students than Lonsdale students " ] }, { "cell_type": "code", "execution_count": null, "id": "0e3ac3e2", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.13" } }, "nbformat": 4, "nbformat_minor": 5 }