Could chance alone have done this? Shuffle the labels and see. The lady tasting tea, permutation tests, the t-test on Student’s own data, and what a p-value is the probability of
Something happened: the treated group did better, the lady named the cups. Before believing it, ask one question: how often would chance alone do as well? A hypothesis test answers that question by imagining the world in which nothing is going on, and seeing how unusual the result would be there.
Press Serve the tea a few times and compare her score with the sky bars, the scores a pure guesser would get. Then redesign the experiment with 6 or 12 cups, and press Repeat 1,000 times to see how often a taster of that skill convinces you.
Every cup looks the same; the word beneath it says what was really poured first. Amber rings mark the cups she names as milk-first, with a green tick or a red cross for each. Sky bars give the chance of each score for a pure guesser, as a count of selections out of 70; the rose bars are the scores at least as good as hers, and their total is the p-value. Violet dots are this taster’s own record over all the trays served so far. Her skill sets how strongly a milk-first cup stands out against her cup-to-cup noise; she always names the 4 that seem most milk-first.
R. A. Fisher described the experiment in The Design of Experiments (1935). A lady claims she can tell by taste whether the milk or the tea went into the cup first. Eight cups are prepared, four each way, and presented in random order; she is told the design and must pick out the four milk-first cups. The lady is said to have been the algologist Muriel Bristol, a colleague of Fisher’s at Rothamsted, and by one later account she identified every cup correctly. That part is an anecdote; the design is what matters.
A significance test has four steps. State a null hypothesis: here, that she cannot tell and is guessing. Choose a test statistic: the number of milk-first cups she names correctly. Find the distribution of that statistic if the null hypothesis is true. Then report how far out the observation lies: the p-value is the probability, under the null hypothesis, of a result at least as extreme as the one seen.
There are C(8, 4) = 70 ways to choose four cups from eight, and a guesser is equally likely to make any of them. Exactly k right means choosing k of the four milk-first cups and 4 − k of the four others, which can be done in C(4, k) × C(4, 4 − k) ways: 1, 16, 36, 16 and 1 ways for k = 0 to 4. This is the hypergeometric distribution. All four right has p = 1/70 ≈ 0.014. Three right has p = 17/70 ≈ 0.24, which is not convincing at all. With six cups even a perfect score has p = 1/20; with twelve, five right out of six still has p = 37/924 ≈ 0.04.
Randomising the order is what makes the calculation valid. Because chance decided which cups went where, “all 70 selections are equally likely” is a fact about the experiment and not an assumption about the lady, the cups or the tea. Fisher suggested 0.05 as a convenient threshold in Statistical Methods for Research Workers (1925). It is a convention, not a law of nature.
Press Step to deal the group labels out at random and watch the new difference drop into the histogram, then press × 5,000. Switch to Student’s sleep data and compare the two-group analysis with the paired one; drag any dot to change the data.
The default numbers are invented for illustration. Sky dots carry the control label and orange dots the treatment label; in the shuffled row the ring shows the group each number really came from. Amber is the statistic. The sky histogram is its distribution over shuffles, the null distribution, with the shuffles that count towards the p-value filled in rose. The dashed curve is Student’s t distribution redrawn on this axis (in its equal-variance form for two groups): the t-test’s shortcut for the histogram. A new dataset, statistic or dragged point starts a fresh pile of 400 shuffles; Reset starts an empty one.
If the treatment does nothing, the labels “control” and “treatment” are arbitrary, and any other way of dealing them out was just as likely to occur. So deal them out again, many times, and see how often the difference between the groups is as large as the one observed. That is a permutation test. It needs no formula and no bell curve, only the random assignment itself. For paired data, where each patient received both treatments, the labels are swapped within each pair, which flips the sign of that patient’s difference.
Student’s sleep data record the extra hours of sleep of ten patients on each of two drugs. Treated as two unrelated groups, the 184,756 ways of relabelling give a two-sided p of about 0.08. Treated correctly as pairs, only 4 of the 1,024 sign patterns do as well as the data: p ≈ 0.004. The numbers are the same; the paired test is sharper because each patient is their own control, so the large differences between patients drop out of the comparison.
Permutation tests go back to Fisher (1935) and Pitman (1937). They were impractical before computers, and the t-test and its relatives served as approximations that need only a table. The dashed curve in the demo is that approximation: Welch’s t-test gives p = 0.079 for the two groups and the paired t-test gives p = 0.0028. The classical test is a shortcut for the shuffle.
A p-value is the probability, computed assuming the null hypothesis, of a result at least as extreme as the one observed. It is not the probability that the null hypothesis is true, and it is not the probability that the result was “due to chance”. Nor does statistical significance say anything about the size or importance of an effect, so always report the estimate and its interval as well: here, a mean gain of 1.58 hours, with a 95% confidence interval from 0.70 to 2.46.
Slide the true effect down to zero and watch the histogram of p-values go flat, then raise it and watch them pile up near zero. Keep an eye on the strip of 25 consecutive p-values, and move the last slider to see how much a result just under 0.05 is worth.
How strong is a result with p just under 0.05? Suppose a share of all the hypotheses anyone tests are true nulls and the rest have exactly the effect above.
By simulation: 0 of 25 experiments with no effect landed in that band (about 1 in 100, always), against 2 of 25 with the effect. A p-value just under 0.05 is common under the null and not much more common under a real effect, so it moves the odds only a little. This share is not the p-value, and no p-value can supply it: it depends on how many of the hypotheses were true to begin with.
Each row at the top is one complete experiment: a control group (sky) and a treatment group (orange) drawn from normal populations one standard deviation wide, centred on the dashed lines, with the amber step joining the two sample means. Each experiment is reduced to a single two-sided p-value by Welch’s t-test. The middle strip shows the last 25 p-values on a logarithmic scale. In the histogram, each bar is one hundredth of the range from 0 to 1; violet bars are p-values under the alternative, and emerald marks the detections below α. A change to the effect or the sample size starts again and runs 2,000 experiments.
When the null hypothesis is true and the test statistic is continuous, the p-value is uniformly distributed between 0 and 1: p ≤ 0.05 happens 5% of the time, p ≤ 0.5 half the time. That is exactly what makes the rule “reject when p < α” have a false-alarm rate of α. For a discrete statistic, such as the number of cups in the first demo, only certain p-values can occur and the rate is at most α.
Jerzy Neyman and Egon Pearson (1933) framed testing as a decision between two hypotheses with two kinds of error: rejecting a true null, with probability α, and failing to reject a false one, with probability β. They called 1 − β the power of the test. Fisher treated the p-value differently, as a graded measure of the evidence against the null in a single experiment. Textbook practice is an uneasy mixture of the two.
Two things in the demo surprise most people. A p-value is itself a random quantity, and when power is moderate it varies enormously between exact replications of one experiment. And a p-value just under 0.05 is weak evidence: such results are nearly as common when there is no effect as when there is a modest one, so how many of them are false alarms depends mostly on how many of the hypotheses tested were true nulls to begin with, a number no p-value contains.
The American Statistical Association’s 2016 statement on p-values warns against the common misreadings: a p-value does not measure the probability that a hypothesis is true, or the size of an effect, and conclusions should not rest only on whether it passes a threshold. See also: When Tests Mislead.
Spot a mistake or have an idea?