{ "cells": [ { "cell_type": "markdown", "id": "572fb94e", "metadata": {}, "source": [ "# Permutation test for paired data\n", "\n", "Turning to the permutation test itself, we first look at the case of paired data - data in which we wish to compare two groups and each datapoint in one group has a counterpart in the other\n", "\n", "Experimental designs using paired data include matched pairs (eg brothers and sisters) and repeated measures (measurements of the same individual before- and after- an intervention, or on- and off-drug).\n" ] }, { "cell_type": "markdown", "id": "2c4eabfd", "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": 3, "id": "3286b373", "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" ] }, { "cell_type": "markdown", "id": "df221c50", "metadata": {}, "source": [ "## Toy example\n", "\n", "[A toy example is an example with a very small dataset, just to show how it works]\n", "\n", "#### Question & design\n", "\n", "We suspect men own ore socks than women. \n", "\n", "We decide on a **matched pairs design** in which husbands are compared to their wives, as it is hypothesised that lifestyle factors such as the size of the home in which people live and the duration of holidays taken will affect the number of pairs that can be reasonably justified, and these lifestyle factors are generally shared by both members of a married couple.\n", "\n", "\n", "#### Hypotheses\n", "\n", "We can state our hypotheses as follows:\n", "\n", "$\\mathcal{H_o}:$ The mean sex difference quantity of socks owned is zero \n", "* on average a wife and her husband have the same number of pairs of socks\n", "\n", "$\\mathcal{H_a}:$ The mean sex difference [husband-wife] quantity of socks owned greater than zero\n", "* on average a husband has more socks than his wife\n", "\n", "#### Data\n", "\n", "We obtain sock-counts for the following informal sample of 14 couples:" ] }, { "cell_type": "code", "execution_count": 4, "id": "e0483d68", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", " | Husband | \n", "Wife | \n", "
---|---|---|
0 | \n", "10 | \n", "12 | \n", "
1 | \n", "17 | \n", "13 | \n", "
2 | \n", "48 | \n", "20 | \n", "
3 | \n", "28 | \n", "25 | \n", "
4 | \n", "23 | \n", "18 | \n", "
5 | \n", "16 | \n", "14 | \n", "
6 | \n", "18 | \n", "13 | \n", "
7 | \n", "34 | \n", "26 | \n", "
8 | \n", "27 | \n", "22 | \n", "
9 | \n", "22 | \n", "14 | \n", "
10 | \n", "12 | \n", "10 | \n", "
11 | \n", "13 | \n", "17 | \n", "
12 | \n", "22 | \n", "21 | \n", "
13 | \n", "15 | \n", "16 | \n", "