{ "cells": [ { "cell_type": "markdown", "id": "c1062de3", "metadata": {}, "source": [ "# Permutation testing - more practice\n", "\n", "The aim of these exercises is to give you some practice running permutation tests and deciding what to permute and what your test statistic is in each case!" ] }, { "cell_type": "markdown", "id": "994e0b88", "metadata": {}, "source": [ "### 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": "56b8c893", "metadata": { "tags": [] }, "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 as pd\n", "import seaborn as sns\n", "sns.set_theme(style='white')\n", "import statsmodels.api as sm\n", "import statsmodels.formula.api as smf\n", "import warnings \n", "warnings.simplefilter('ignore', category=FutureWarning)" ] }, { "cell_type": "markdown", "id": "3f3652ec", "metadata": {}, "source": [ "### Import and view the data\n", "\n", "We will work with a fictional dataset containing wellbeing scores pre- and post the vacation for 300 Oxford students. \n", "\n", "For each student was also have the following information:\n", "* subject studied\n", "* college" ] }, { "cell_type": "code", "execution_count": 2, "id": "ecc6605d", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", " | ID_code | \n", "College | \n", "Subject | \n", "Score_preVac | \n", "Score_postVac | \n", "
---|---|---|---|---|---|
0 | \n", "247610 | \n", "Lonsdale | \n", "PPE | \n", "60 | \n", "35 | \n", "
1 | \n", "448590 | \n", "Lonsdale | \n", "PPE | \n", "43 | \n", "44 | \n", "
2 | \n", "491100 | \n", "Lonsdale | \n", "engineering | \n", "79 | \n", "69 | \n", "
3 | \n", "316150 | \n", "Lonsdale | \n", "PPE | \n", "55 | \n", "61 | \n", "
4 | \n", "251870 | \n", "Lonsdale | \n", "engineering | \n", "62 | \n", "65 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
296 | \n", "440570 | \n", "Beaufort | \n", "history | \n", "75 | \n", "70 | \n", "
297 | \n", "826030 | \n", "Beaufort | \n", "maths | \n", "52 | \n", "49 | \n", "
298 | \n", "856260 | \n", "Beaufort | \n", "Biology | \n", "83 | \n", "84 | \n", "
299 | \n", "947060 | \n", "Beaufort | \n", "engineering | \n", "62 | \n", "65 | \n", "
300 | \n", "165780 | \n", "Beaufort | \n", "PPE | \n", "48 | \n", "56 | \n", "
301 rows × 5 columns
\n", "\n", " | ID_code | \n", "College | \n", "Subject | \n", "Score_preVac | \n", "Score_postVac | \n", "
---|---|---|---|---|---|
2 | \n", "491100 | \n", "Lonsdale | \n", "engineering | \n", "79 | \n", "69 | \n", "
4 | \n", "251870 | \n", "Lonsdale | \n", "engineering | \n", "62 | \n", "65 | \n", "
6 | \n", "841260 | \n", "Lonsdale | \n", "engineering | \n", "71 | \n", "58 | \n", "
7 | \n", "960120 | \n", "Lonsdale | \n", "engineering | \n", "54 | \n", "54 | \n", "
15 | \n", "670880 | \n", "Lonsdale | \n", "engineering | \n", "70 | \n", "69 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
266 | \n", "842870 | \n", "Beaufort | \n", "engineering | \n", "52 | \n", "58 | \n", "
278 | \n", "414020 | \n", "Beaufort | \n", "engineering | \n", "76 | \n", "82 | \n", "
291 | \n", "384240 | \n", "Beaufort | \n", "engineering | \n", "78 | \n", "89 | \n", "
294 | \n", "457900 | \n", "Beaufort | \n", "engineering | \n", "72 | \n", "62 | \n", "
299 | \n", "947060 | \n", "Beaufort | \n", "engineering | \n", "62 | \n", "65 | \n", "
61 rows × 5 columns
\n", "