Permutation Test
The Permutation Test: Exchangeable Labels, a Reference Distribution You Build, and an Exact p-Value
A permutation test answers a two-group comparison without asking the data to be normal, without a table of critical values, and without an asymptotic approximation.
It asks instead a question you can answer by counting: if the group labels carried no information, how unusual would the observed separation be among all the ways the labels could have been attached?
What licenses the shuffling depends on the design
Relabelling is legitimate when the labels are exchangeable under the null: every assignment of the labels to the observed set of values is equally likely, so the observed labelling is just one member of an equally likely collection and the rest form the reference distribution.
Two quite different setups deliver that condition, and they should not be run together.
- A randomised experiment. Here the null is sharp: the treatment has no effect on any unit, so each observation's value would have been exactly what it was regardless of which group that unit had been assigned to. The sharp null fixes the values; the randomisation supplies the probabilities, because the assignment was drawn uniformly from the assignments giving the observed group sizes. Neither half works alone - a sharp null laid over an assignment mechanism nobody controlled says nothing about how likely the labellings that did not occur were.
- Two independent samples. With no randomised assignment, the null is that the two groups' values are independent draws from one and the same distribution, so the label carries no information about the sampling distribution. Exchangeability then follows from the iid sampling model rather than from a design, which makes it a modelling assumption that has to be argued for.
These are different hypotheses, and what a small p-value is evidence against differs accordingly. Note also what neither of them assumes: nothing is said about normality, about the shape of the distribution, or about large samples.
The recipe
- Choose a test statistic T that measures the separation you care about - the difference in group means is the usual choice, but a difference in medians or in trimmed means works the same way.
- Compute Tobs on the data as observed.
- For every way of splitting the pooled values into groups of the observed sizes, recompute T. The collection of those values is the permutation distribution.
- The two-sided p-value is the proportion of relabellings with ∣T∣≥∣Tobs∣.
A tiny example you can check by hand
Group A has values 7 and 9; group B has 2 and 4, so Tobs=8−3=5. There are (24)=6 ways to choose which two of {2,4,7,9} are labelled A, giving differences −5,−2,0,0,2,5. Two of the six have ∣T∣≥5, so
The data are as separated as they possibly could be, and the p-value is still a third. That is not a failure of the method; it is the design telling the truth.
With two observations per group there are only six relabellings, and equal group sizes make them come in mirror-image pairs - relabelling A as B negates the statistic - so no outcome of this comparison can have a two-sided p-value below 2/6. The smallest reportable p-value is bounded below by the number of permutations, and therefore by the sample sizes, before any data are collected.
That bound is always at least 1/(n1n1+n2); how much higher it sits depends on how many relabellings tie for the largest ∣T∣, which equal group sizes force to be at least two and which unequal group sizes leave to the values themselves.
A larger example, and the shape of the distribution
Now take group A ={11,13,14,18} and group B ={5,7,10,12}. The group means are 14.0 and 8.5, so Tobs=5.5. There are (48)=70 relabellings; the accompanying chart shows how many produce each value of the difference.
The distribution is symmetric about zero - as it must be, since swapping which side is called A negates the statistic - and it is concentrated near zero with thin tails. Exactly four of the seventy relabellings reach ∣T∣≥5.5 (the values ±5.5 and ±6.0), so
Lesson example - all 70 permutation values of the difference in means
At the conventional 0.05 level this does not reach significance, and the honest report is the p-value together with the observed difference of 5.5 units, not a verdict dressed up as a discovery.
When you cannot enumerate: Monte Carlo
Complete enumeration becomes impossible quickly - (2040) is already about 1.4×1011. The standard remedy is to sample B relabellings at random and estimate
The added 1 in each position is not a fudge. It counts the observed labelling itself, which is a legitimate member of the permutation distribution, and it is what keeps the test valid: without it the estimate can be exactly zero, which would assert more evidence than any finite simulation can supply.
The cost is a slight conservatism that vanishes as B grows, and B is chosen for the resolution required - with B=999 no estimate can fall below 1/1000.
Exchangeability is a real assumption
The method is often described as assumption-free. It is not; it has one assumption, and it is load-bearing. Labels must be exchangeable under the null, which fails whenever the design imposes structure that free shuffling would destroy:
- Paired measurements. Two readings on the same subject are linked, so free shuffling is wrong. What replaces it is a within-pair scheme - flip the label independently inside each subject, giving 2n relabellings rather than all splits of the pooled readings - but that scheme needs a licence of its own. If the order of the two conditions was randomised within each subject, the design supplies it. If the labels are a fixed before-and-after order that nobody randomised, it does not: sign flipping then rests on an explicit assumption that the paired differences are exchangeable under sign reversal, and a drift or time trend over the study period is a concrete way for that assumption to fail.
- Clustered or stratified sampling. Permute within cluster or stratum, not across.
- Serial dependence. Observations in time are not freely interchangeable, and a block or cyclic scheme is needed.
There is also a subtler point about what rejection means, and it splits along the same two settings.
In a randomised experiment a small p-value is evidence against the sharp null of no effect on any unit, which is not a statement about means, since any pattern of unit-level effects can produce it.
In an iid two-sample comparison the null is that the two sampling distributions are identical, so a difference in spread or in shape can produce a small p-value just as a difference in location can - and when the groups differ in variance and in size, a permutation test of the difference in means is not an exact test of equal means, because the exactness belongs to the identical-distributions null rather than to the means.
Neither null says "the mean changed". Say what was rejected.
Finally, keep the roles of the tools straight. A permutation test assesses a hypothesis; forming an interval estimate for the size of the effect is the business of the bootstrap, which is a separate concept.
Each of 20 subjects is measured under a control condition and under an active condition, with the order of the two conditions drawn independently at random for each subject, giving 40 measurements in all. A student pools all 40 values, shuffles the "control" and "active" labels freely across the whole pooled set, and computes a permutation distribution of the difference in the two label means. What is the problem with this procedure?
A two-group comparison gives
group A: 12, 15, 17; group B: 8, 9, 11.
The test statistic is the difference in group means, T=xˉA−xˉB, and the two-sided p-value is the proportion of relabellings with ∣T∣≥∣Tobs∣. All (36)=20 ways of choosing which three of the six pooled values are labelled A are enumerated.
Compute the exact two-sided permutation p-value. Enter a decimal number to four decimal places.
Give your answer as a number.