Unit 6, lesson 44

Randomization and Permutation Tests

How a randomization test uses the actual random assignment under a sharp null hypothesis, when exchangeability makes a permutation test valid, and how restricted permutations and plus-one Monte Carlo p-values work.

  • Video 44
  • The Logic of Hypothesis Tests

Six participants take part in a small experiment, and chance picks three of them for a new treatment. The treated three score 4, 5 and 6 points and the other three score 1, 2 and 3, so the treatment mean is 3 points higher. With so few people a normal model for the scores is hard to defend, yet the question remains whether random assignment alone could easily produce a gap this large. This lesson answers it by recomputing the difference for every assignment the design could have made, and it explains which rearrangements are legitimate, why, and what to do when there are too many to list.

Key terms

Sharp null hypothesis

Definition In an experiment with units i=1,…,ni = 1, \dots, n, let Yi(1)Y_i(1) and Yi(0)Y_i(0) be the potential responses of unit ii under treatment and under control, assuming that each unit’s response depends only on its own assignment. Only one of the two is observed. A sharp null hypothesis specifies every unit’s treatment effect Yi(1)−Yi(0)Y_i(1) - Y_i(0), so that under it the missing potential response of every unit can be computed from the observed one. The most common is the sharp null of no effect,

H0: Yi(1)=Yi(0)for every unit i.\begin{gathered} H_0: \ Y_i(1) = Y_i(0) \\[0.4em] \text{for every unit } i . \end{gathered}

A constant effect, Yi(1)−Yi(0)=τ0Y_i(1) - Y_i(0) = \tau_0 for every ii with a number τ0\tau_0 fixed in advance, is also a sharp null. The weak null hypothesis that the average effect τˉ\bar{\tau} is zero is not sharp, because many different sets of individual effects have average zero.

In plain words Under the sharp null of no effect, each participant would have produced the same response in either group. The responses are then fixed numbers, and the only thing chance could have changed is which labels they carry. A zero average effect is a weaker claim, since gains for some units could cancel losses for others.

Example In the six-participant experiment the treated responses are 44, 55 and 66 and the control responses are 11, 22 and 33. Under the sharp null of no effect, the participant who scored 66 under treatment would also have scored 66 under control, and the participant who scored 11 under control would also have scored 11 under treatment, so all twelve potential responses are known. Now suppose instead that two of the six units have effects +2+2 and −2-2 and the other four have none. The average effect is zero, so the weak null holds, while the sharp null of no effect is false. Knowing only that the average is zero would not tell us any unit’s missing response.

Randomization test

Definition A randomization test of a sharp null hypothesis needs three ingredients fixed before the responses are examined. They are the assignment mechanism the experiment actually used, which gives each allowed assignment ww a known probability, a test statistic TT, and a rule saying which values count as at least as extreme as the observed one. Under the sharp null every unit’s response under every allowed assignment is known, so the statistic T(w)T(w) can be computed for each ww. With WW a random assignment drawn from the mechanism and wobsw_{\text{obs}} the assignment that occurred, the upper-tail p-value is

p=P(T(W)≥T(wobs)),p = P\bigl(T(W) \ge T(w_{\text{obs}})\bigr),

and a two-sided rule uses ∣T∣\lvert T \rvert in place of TT. When all allowed assignments are equally likely, the p-value is the proportion of them whose statistic is at least as extreme as the observed one, the observed assignment included. If the sharp null is true, then P(p≤α)≤αP(p \le \alpha) \le \alpha for every α\alpha between 00 and 11, without any model for how the responses arose, because the only randomness the test uses is the randomness the investigator created.

In plain words Chance produced the observed split, so the fair comparison is with the other splits the same chance mechanism could have produced. If the sharp null is true, the observed statistic is just one draw from that collection, and a value far in its tail is surprising. A small p-value is evidence that the treatment changed the response of at least one unit in the study. It does not measure how large the effect is, and it does not show that every unit was affected.

Example Choosing 33 of the 66 participants uniformly at random gives (63)=20\binom{6}{3} = 20 equally likely assignments. Take the statistic T=yˉ1−yˉ0T = \bar{y}_1 - \bar{y}_0, the treatment mean minus the control mean, whose observed value is 5−2=35 - 2 = 3. Treating the participants who scored 44, 55 and 66 is the only assignment with T=3T = 3, treating those who scored 11, 22 and 33 is the only one with T=−3T = -3, and every other assignment gives a value strictly between. For a two-sided question with the rule ∣T∣≥3\lvert T \rvert \ge 3, chosen in advance,

p=220=0.10,p = \frac{2}{20} = 0.10,

and for an upper alternative stated in advance the p-value is 1/20=0.051/20 = 0.05. Swapping the two groups of any assignment changes the sign of TT, so in this design no two-sided p-value can be smaller than 0.100.10. Picking the upper direction only after seeing the result would not keep the stated error rate.

Permutation test and permutation distribution

Definition A permutation test fixes a set of rearrangements of the data, such as all reassignments of the group labels that keep the group sizes, recomputes the test statistic for each rearrangement and compares the observed value with the recomputed ones. The permutation distribution is the distribution of the statistic over that set, with equal weight on each rearrangement, or with the design’s probabilities in a randomization test. The p-value is the proportion of rearrangements, weighted by those probabilities when they differ, whose statistic is at least as extreme as the observed value, counting ties as extreme. The test is valid, with P(p≤α)≤αP(p \le \alpha) \le \alpha for every α\alpha when the null hypothesis is true, if that hypothesis makes every rearrangement in the set leave the joint distribution of the data unchanged and the set is closed under composition, so that one rearrangement followed by another is again in the set. All label shuffles, all shuffles within blocks and all sign changes within pairs are such sets. The next card calls this invariance of the distribution exchangeability. A randomization test is the permutation test whose rearrangements are exactly the assignments the experiment could have produced.

In plain words Shuffle the labels in every allowed way, recompute the same statistic each time, and see where the real value falls among the results. The list of shuffled values plays the part that a normal or t curve plays in other tests, but it is built from the observed data and needs no formula for the shape of the population.

Example For the six participants the 2020 assignments give the following values of the mean difference.

Mean difference±13\pm\tfrac13±1\pm 1±53\pm\tfrac53±73\pm\tfrac73±3\pm 3
Assignments for each sign33211

The counts add to 2×10=202 \times 10 = 20, and the distribution is symmetric around 00 because each assignment and its mirror image, with the groups swapped, have opposite differences. The observed value 33 sits at the upper end, which gives the p-values 0.100.10 and 0.050.05 of the previous card. Every entry is recomputed from the actual responses, so the permutation distribution is conditional on these six numbers rather than read from a general table.

Exchangeability

Definition Random variables X1,…,XNX_1, \dots, X_N are exchangeable if for every permutation π\pi of the indices 1,…,N1, \dots, N the rearranged vector (Xπ(1),…,Xπ(N))(X_{\pi(1)}, \dots, X_{\pi(N)}) has the same joint distribution as (X1,…,XN)(X_1, \dots, X_N). Independent observations from one distribution are exchangeable. Suppose the n1n_1 observations of one group and the n2n_2 observations of the other are all independent. Then the null hypothesis that both groups come from the same distribution makes all N=n1+n2N = n_1 + n_2 observations independent and identically distributed. Given the pooled values, each of the (Nn1)\binom{N}{n_1} ways of splitting them into groups of the original sizes is then equally likely, and the permutation test of that hypothesis is valid. In a randomized experiment the equal probabilities come from the design instead, and the sharp null fixes the responses, so no sampling model is needed. A null hypothesis saying only that two means are equal does not make the labels exchangeable when the groups can differ in spread or shape.

In plain words Exchangeable labels carry no information under the null hypothesis, so a shuffled data set is exactly as plausible as the real one. Whether that holds depends on the hypothesis and on how the data were produced, and a histogram cannot settle it.

Example Take two groups of sizes 1010 and 4040 from normal populations with the same mean 00 but standard deviations 44 and 11. The difference in sample means has variance 16/10+1/40=1.62516/10 + 1/40 = 1.625. Shuffling the labels spreads the noisy values over both groups, and the shuffled differences have variance S2(1/10+1/40)S^2(1/10 + 1/40), where S2S^2 is the sample variance of all 5050 values. Since S2S^2 averages 44, this variance is 0.50.5 on average, and the permutation distribution is much too narrow. In a simulation of 40004000 such data sets, a two-sided permutation test of the difference in means at level 0.050.05, each run with 999999 random shuffles and the plus-one correction, rejected the true null hypothesis of equal means in nearly 3030 percent of them. With the standard deviations swapped between the groups it almost never rejected, and with equal standard deviations, where the labels are exchangeable, it rejected in about 55 percent, matching the nominal level.

Restricted permutation

Definition A restricted permutation scheme allows only the rearrangements that respect the structure imposed by the design or by the null hypothesis, such as swaps within blocks or within pairs, or reassignments of whole clusters. In a randomization test the allowed rearrangements must be exactly the assignments the randomization could have produced, with their probabilities. In a randomized block design that treats mbm_b of the nbn_b units in block bb, chosen uniformly and independently across blocks, there are

∏b(nbmb)\prod_{b} \binom{n_b}{m_b}

equally likely assignments. For mm matched pairs in which an independent fair coin chooses the treated member of each pair, there are 2m2^m equally likely assignments, and under the sharp null of no effect each one keeps or reverses the sign of each within-pair difference did_i, pair by pair, with did_i taken as treatment minus control.

In plain words Shuffle only in the ways the chance mechanism could have shuffled. An assignment the design could never have produced is not a possible alternative result of this experiment, so it does not belong in the reference distribution. If whole classrooms were assigned, whole classrooms are shuffled, not individual students.

Example Suppose the six participants had been formed into three matched pairs before the study, and a coin chose the treated member of each pair. The treated members scored 22, 44 and 66 and their partners 11, 33 and 55, so every pair difference is 11 and the mean difference is 11. The 23=82^3 = 8 allowed sign patterns give mean differences 11 and −1-1 once each and 13\tfrac13 and −13-\tfrac13 three times each, so the exact two-sided p-value is 2/8=0.252/8 = 0.25. Shuffling all six labels freely would use 2020 splits, 1212 of which the design could never produce, such as treating both members of the pair that scored 55 and 66. That free shuffle would give 14/20=0.7014/20 = 0.70 for the same statistic, an answer about an experiment that was never run.

Monte Carlo p-value and plus-one correction

Definition When the allowed rearrangements are too many to list, a Monte Carlo p-value is computed from BB rearrangements drawn independently at random from the null reference distribution, for example from the experiment’s assignment mechanism. Let bb be the number of draws whose statistic is at least as extreme as the observed one. The ratio b/Bb/B estimates the exact p-value. The plus-one correction reports instead

pMC=b+1B+1,p_{\text{MC}} = \frac{b + 1}{B + 1},

counting the observed data as one more member of the reference set. Under the null hypothesis the observed statistic and the BB simulated ones are exchangeable, so P(pMC≤α)≤αP(p_{\text{MC}} \le \alpha) \le \alpha for every α\alpha and every BB, and the test keeps its stated level despite the simulation. The corrected value is never below 1/(B+1)1/(B + 1). A complete enumeration already contains the observed assignment and needs no correction. A report states BB, bb, the convention, the random seed and the Monte Carlo standard error, which is about p(1−p)/B\sqrt{p(1 - p)/B} when the exact p-value is pp.

In plain words Sampling the reference set adds a second, purely numerical source of randomness on top of the experiment. The extra one keeps a finite simulation from reporting a p-value of zero just because it missed a rare tail, and it makes the procedure valid at its stated level. More draws make the answer more stable, but they cannot repair a reference set that breaks the design.

Example With B=999B = 999 draws, of which b=99b = 99 are at least as extreme,

pMC=99+1999+1=0.10.p_{\text{MC}} = \frac{99 + 1}{999 + 1} = 0.10 .

If the exact p-value is near 0.100.10, the Monte Carlo standard error is about 0.1×0.9/999≈0.0095\sqrt{0.1 \times 0.9 / 999} \approx 0.0095, so a run with another seed could easily differ by about 0.010.01. Had no draw been as extreme, the report would be 1/1000=0.0011/1000 = 0.001, not 00. For the six participants all 2020 assignments can be listed, and the exact two-sided p-value is 2/20=0.102/20 = 0.10. Adding one there would wrongly give 3/21≈0.1433/21 \approx 0.143.

Check yourself

  1. In the six-participant experiment with three treated, suppose the treated participants had scored 33, 55 and 66 and the control participants 11, 22 and 44. Find the observed mean difference and the exact two-sided p-value with the rule ∣T∣≥∣Tobs∣\lvert T \rvert \ge \lvert T_{\text{obs}} \rvert.
Show the answer

The treatment mean is 14/314/3 and the control mean is 7/37/3, so the observed difference is Tobs=7/3T_{\text{obs}} = 7/3. The six responses add to 2121, so if the treated responses add to SS,

T=S3−21−S3=2S−213.\begin{aligned} T &= \frac{S}{3} - \frac{21 - S}{3} \\[0.4em] &= \frac{2S - 21}{3} . \end{aligned}

The condition ∣T∣≥7/3\lvert T \rvert \ge 7/3 holds exactly when S≥14S \ge 14 or S≤7S \le 7. The treated sets with these sums are {4,5,6}\{4, 5, 6\} and {3,5,6}\{3, 5, 6\}, with sums 1515 and 1414, and {1,2,3}\{1, 2, 3\} and {1,2,4}\{1, 2, 4\}, with sums 66 and 77. So the exact two-sided p-value is 4/20=0.204/20 = 0.20.

  1. Three pairs of participants were matched before a study, and in each pair an independent fair coin chose the treated member. The treatment-minus-control differences were 11, 22 and 33 points. How many assignments did the design allow, and what is the exact two-sided p-value for the mean difference? A colleague instead pools the six responses and shuffles them freely into two groups of three. What is wrong with that?
Show the answer

Each pair has two possible assignments, so the design allows 23=82^3 = 8 equally likely assignments. Under the sharp null of no effect each assignment keeps or reverses the sign of each difference. The observed mean difference is (1+2+3)/3=2(1 + 2 + 3)/3 = 2. The signed sums are ±6\pm 6, ±4\pm 4 and ±2\pm 2 once each and 00 twice, so the possible mean differences are ±2\pm 2, ±43\pm\tfrac43 and ±23\pm\tfrac23 once each and 00 twice. Only the all-positive and all-negative patterns reach an absolute mean of 22, so the exact two-sided p-value is 2/8=0.252/8 = 0.25.

The free shuffle uses 2020 splits, and 1212 of them put both members of some pair in the same group, which this design could never do. Its reference distribution therefore describes a different experiment. It also brings the differences between pairs back into the comparison, the very variation the pairing was meant to remove.

  1. A large randomized experiment has far too many possible assignments to list. A program draws B=4999B = 4999 assignments from the design and finds b=24b = 24 whose mean difference is at least as extreme as the observed one. Report the p-value with the plus-one correction and its approximate Monte Carlo standard error. What should be reported if bb had been 00?
Show the answer

The corrected p-value is

pMC=24+14999+1=0.005.p_{\text{MC}} = \frac{24 + 1}{4999 + 1} = 0.005 .

Its Monte Carlo standard error is about 0.005×0.995/4999≈0.001\sqrt{0.005 \times 0.995 / 4999} \approx 0.001, so the report gives 0.0050.005 together with B=4999B = 4999, b=24b = 24, the plus-one convention and the seed. The uncorrected ratio 24/4999≈0.004824/4999 \approx 0.0048 is a fine estimate of the exact p-value, but used as a p-value it does not guarantee the stated level. With b=0b = 0 the report would be 1/5000=0.00021/5000 = 0.0002, not 00. The exact p-value is never zero, because the observed assignment always counts as at least as extreme as itself, and more draws would locate it more precisely.

How this lesson connects