{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Lady Tasting Tea - An Investigation\n", "\n", "![Ronald Fisher](https://upload.wikimedia.org/wikipedia/commons/a/aa/Youngronaldfisher2.JPG)\n", "\n", "The Lady Tasting Tea problem was first described by [Ronald A. Fisher](http://www-history.mcs.st-andrews.ac.uk/Biographies/Fisher.html) in his book The Design of Experiments.\n", "\n", "He described the problem as follows.\n", "\n", "> A lady declares that by tasting a cup of tea made with milk she can discriminate whether the milk or the tea infusion was first added to the cup: We will consider the problem of designing an experiment by means of which this assertion can be tested. For this purpose let us first lay down a simple form of experiment with a view to studying its limitations and its characteristics, both those which appear to be essential to the experimental method, when well developed, and those which are not essential but auxiliary.\n", "\n", "> Our experiment consists in mixing eight cups of tea, four in one way and four in the other, and presenting them to the subject for judgment in a random order. The subject has been told in advance of what the test will consist, namely that she will be asked to taste eight cups, that these shall be four of each kind, and that they shall be presented to her in a random order, that is in an order not determined arbitrarily by human choice, but by the actual manipulation of the physical apparatus used in games of chance, cards, dice, roulettes, etc., or, more expeditiously, from a published collection of random sampling numbers purporting to give the actual results of such manipulation. Her task is to divide the 8 cups into two sets of 4, agreeing, if possible, with the treatments received." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Number of ways of selecting cups\n", "\n", "In this section we investigate the number of ways in which the lady can arrange the eight cups into two sets of four - the cups with milk first and the cups with tea first. To begin we give each of the eight cups a label from 0 to 7. Note that the cups have no order in the experiment, we are labelling them with integers simply for convenience." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/plain": [ "[0, 1, 2, 3, 4, 5, 6, 7]" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# The eight cups.\n", "cups = list(range(8))\n", "cups" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Suppose the subject is trying to pick the four cups with milk in first. If the subject is picking the cups randomly (i.e. if they can't really tell which cups have the milk in first), then they are randomly picking one of seventy different options. Therefore they have only a probability of 1/70 of getting the right answer.\n", "\n", "The number of ways of selecting four unordered items from eight is given by the [Choose](http://mathworld.wolfram.com/Choose.html) function in mathematics." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/plain": [ "70.0" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(8*7*6*5)/(4*3*2*1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "These possibilities can be enumerated using the combinations function from the itertools Python package. it takes a list $l$ of items and a number $n$. It returns/generates each way of selecting $n$ unordered items from $l$." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "[(0, 1, 2, 3),\n", " (0, 1, 2, 4),\n", " (0, 1, 2, 5),\n", " (0, 1, 2, 6),\n", " (0, 1, 2, 7),\n", " (0, 1, 3, 4),\n", " (0, 1, 3, 5),\n", " (0, 1, 3, 6),\n", " (0, 1, 3, 7),\n", " (0, 1, 4, 5),\n", " (0, 1, 4, 6),\n", " (0, 1, 4, 7),\n", " (0, 1, 5, 6),\n", " (0, 1, 5, 7),\n", " (0, 1, 6, 7),\n", " (0, 2, 3, 4),\n", " (0, 2, 3, 5),\n", " (0, 2, 3, 6),\n", " (0, 2, 3, 7),\n", " (0, 2, 4, 5),\n", " (0, 2, 4, 6),\n", " (0, 2, 4, 7),\n", " (0, 2, 5, 6),\n", " (0, 2, 5, 7),\n", " (0, 2, 6, 7),\n", " (0, 3, 4, 5),\n", " (0, 3, 4, 6),\n", " (0, 3, 4, 7),\n", " (0, 3, 5, 6),\n", " (0, 3, 5, 7),\n", " (0, 3, 6, 7),\n", " (0, 4, 5, 6),\n", " (0, 4, 5, 7),\n", " (0, 4, 6, 7),\n", " (0, 5, 6, 7),\n", " (1, 2, 3, 4),\n", " (1, 2, 3, 5),\n", " (1, 2, 3, 6),\n", " (1, 2, 3, 7),\n", " (1, 2, 4, 5),\n", " (1, 2, 4, 6),\n", " (1, 2, 4, 7),\n", " (1, 2, 5, 6),\n", " (1, 2, 5, 7),\n", " (1, 2, 6, 7),\n", " (1, 3, 4, 5),\n", " (1, 3, 4, 6),\n", " (1, 3, 4, 7),\n", " (1, 3, 5, 6),\n", " (1, 3, 5, 7),\n", " (1, 3, 6, 7),\n", " (1, 4, 5, 6),\n", " (1, 4, 5, 7),\n", " (1, 4, 6, 7),\n", " (1, 5, 6, 7),\n", " (2, 3, 4, 5),\n", " (2, 3, 4, 6),\n", " (2, 3, 4, 7),\n", " (2, 3, 5, 6),\n", " (2, 3, 5, 7),\n", " (2, 3, 6, 7),\n", " (2, 4, 5, 6),\n", " (2, 4, 5, 7),\n", " (2, 4, 6, 7),\n", " (2, 5, 6, 7),\n", " (3, 4, 5, 6),\n", " (3, 4, 5, 7),\n", " (3, 4, 6, 7),\n", " (3, 5, 6, 7),\n", " (4, 5, 6, 7)]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import itertools\n", "\n", "poss = list(itertools.combinations(cups, 4))\n", "poss" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Hypthoeses\n", "\n", "In the book, Fisher describes the *null hypothesis*. It is the statement to be countered by the experiment. In this case it is the hypothesis that the subject cannot tell the difference between a cup of coffee that had milk in it first and one that had the tea in it first.\n", "\n", "**Null Hypothesis:** the subject can not tell if the cup had milk in it first or last.\n", "\n", "Once we collect the experimental data we evaluate how likely we were to see such data if the null hypothesis is true. If it is very unlikely, then we may reject the null hypothesis. Typically we have an alternative hypothesis that we suggest rejecting the null hypothesis is evidence for.\n", "\n", "\n", "**Alternative Hypothesis:** the subject can tell.\n", "\n", "Should the subject pick the correct four cups with milk in them first, these is only a 1 in 70 (~1.4%) chance of them having done that if they were simply guessing. Fisher considered that unlikely enough to reject the null hypothesis if they manage it." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/plain": [ "0.014285714285714285" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1 / 70" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Distribution\n", "\n", "We may be tempted to allow the possibility of rejecting the null hypothesis if the subject gets three cups right. That would be a mistake, as the following plot shows. It shows the null distribution, the number of ways of guessing for each number of correct cups. We can see from the plot that there is ~20% chance of guessing at least three correct cups. I don't think that's unlikely enough to reject the null hypothesis." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "scrolled": false }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAD4CAYAAADrRI2NAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAOhklEQVR4nO3df6xfdX3H8efLUoMbGGt6YZXC6ggxEjbKdtORNVGHulQ2RY2akcDIxlL+kEUS9oP5x4ZblpgMdEaNSR1IUedGhk407kfTiURHYLeuQLEajWEM7NqLjAD7g6XlvT++h/Tae2/v9zY933NvP89HcvI95/M953zeOWlf33PP9/M9J1WFJKkdLxu6AEnSZBn8ktQYg1+SGmPwS1JjDH5JasxpQxcwjvXr19emTZuGLkOSVpU9e/Y8VVVTx7aviuDftGkTMzMzQ5chSatKkv9cqN1LPZLUGINfkhpj8EtSYwx+SWqMwS9JjTH4JakxBr8kNcbgl6TGGPyS1JhV8ctdabm2fnzr0CWcdN/6vW8NXYJOEZ7xS1Jjegv+JKcneTDJQ0keTfKhrv3mJE8m2dtNl/dVgyRpvj4v9bwAXFZVzydZC3wzyT927320qm7psW9J0iJ6C/4aPcX9+W5xbTf5ZHdJGliv1/iTrEmyFzgE7KqqB7q3rk/ycJLbk6xbZNvtSWaSzMzOzvZZpiQ1pdfgr6ojVbUZ2AhsSXIR8CngfGAzcAC4dZFtd1TVdFVNT03Ne46AJOkETWRUT1U9A9wLbKuqg90HwovAp4Etk6hBkjTS56ieqSSv6uZfAbwF+G6SDXN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j8ktQYg1+SGmPwS1JjDH5JaozBL0mN+X8BlZ31r0wx2wAAAABJRU5ErkJggg==\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "import random\n", "import seaborn as sns\n", "\n", "# Pick a random correct answer from the list of 70 to simulate the experiment.\n", "milkfirst = set(random.choice(poss))\n", "\n", "# Count the overlap between the correct answer, and each of the 70 possiblities.\n", "counts = [len(milkfirst & set(i)) for i in itertools.combinations(cups, 4)]\n", "\n", "# Creat the plot.\n", "sns.countplot(x=counts);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## End" ] } ], "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.8.12" } }, "nbformat": 4, "nbformat_minor": 2 }