{ "cells": [ { "cell_type": "markdown", "id": "e5a4bea8", "metadata": {}, "source": [ "# Permutation test for unpaired or independent samples data\n", "\n", "We now look at the case of unpaired data - data in which we wish to compare two groups but there are no particular links between individuals in one group and individuals in another group\n", "\n", "Examples of experimental designs using independent samples would be (say) a comparison of science and humanities students, or first- and final-year students, where the individuals in each group are distinct.\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": "83b773a6", "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": "8d4519d3", "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", "\n", "#### Question & design\n", "\n", "We hypothesise that cat owners eat more yoghurt than dog owners \n", "\n", "We decide on an **independent samples** design in which a group of cat owners are compared to an unrelated group of dog owners. \n", "\n", "#### Hypotheses\n", "\n", "We can state our hypotheses as follows:\n", "\n", "$\\mathcal{H_o}:$ The difference in the mean number of yoghurts eaten by cat owners and dog owners is zero\n", "* mean(cat owners' yoghurt consumption) - mean(dog owners' yoghurt consumption) = 0\n", "\n", "$\\mathcal{H_a}:$ Cat owners eat more yoghurt\n", "* mean(cat owners' yoghurt consumption) > mean(dog owners' yoghurt consumption) = 0\n", "\n", "This is a one-tailed (directional) alternative hypothesis\n", "\n", "#### Data\n", "\n", "We survey five cat owners and four dog owners and ask how many times in the last week they ate yogurt. We obtain the following data:" ] }, { "cell_type": "code", "execution_count": 2, "id": "7a66358a", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", " | Pet | \n", "Yoghurt | \n", "
---|---|---|
0 | \n", "cat | \n", "0 | \n", "
1 | \n", "cat | \n", "7 | \n", "
2 | \n", "cat | \n", "5 | \n", "
3 | \n", "cat | \n", "2 | \n", "
4 | \n", "cat | \n", "13 | \n", "
5 | \n", "cat | \n", "1 | \n", "
6 | \n", "cat | \n", "8 | \n", "
7 | \n", "cat | \n", "6 | \n", "
8 | \n", "cat | \n", "3 | \n", "
9 | \n", "cat | \n", "5 | \n", "
10 | \n", "dog | \n", "0 | \n", "
11 | \n", "dog | \n", "0 | \n", "
12 | \n", "dog | \n", "6 | \n", "
13 | \n", "dog | \n", "4 | \n", "
14 | \n", "dog | \n", "1 | \n", "
15 | \n", "dog | \n", "4 | \n", "
16 | \n", "dog | \n", "3 | \n", "
17 | \n", "dog | \n", "2 | \n", "