01 / 20

Permutation
Tests

Understand randomization-based inference: how shuffling data under the null hypothesis lets us compute exact p-values without distributional assumptions.

AP Statistics

What Is a Permutation Test?

A permutation test (also called a randomization test) is a nonparametric method for hypothesis testing. Instead of relying on theoretical distributions like the \(t\) or \(\chi^2\) distribution, it builds a reference distribution by rearranging (permuting) the observed data itself.

Why Permutation Tests Matter

✓ No Distribution Assumptions
No need to assume normality, equal variances, or large samples. Works with any sample size.
✓ Exact p-values
The p-value is computed directly from the data's own distribution of permuted statistics: no approximation.
✓ Flexible Statistics
You can use any test statistic: difference in means, medians, ratios, or custom measures.

The Null Hypothesis & Exchangeability

Permutation tests rest on a single key assumption: under \(H_0\), the data labels (which group each observation belongs to) are exchangeable: swapping labels doesn't change the joint distribution.

1
Null hypothesis \(H_0\): The treatment has no effect. All observations come from the same underlying distribution.
2
Exchangeability: Under \(H_0\), any assignment of labels to data values is equally likely.
3
Consequence: Every permutation of labels produces a data set that is equally plausible under \(H_0\).

The Permutation Distribution

For \(N\) total observations split into groups of size \(n_1\) and \(n_2\), the total number of distinct permutations is:

observed
\(T_{\text{obs}}\)
Test Statistic \(T^*\)
Frequency p-value

Computing the p-value

The p-value is the proportion of permuted test statistics that are as extreme or more extreme than the observed statistic \(T_{\text{obs}}\).

Permutation vs. Bootstrap Tests

Permutation Test Bootstrap Test
Resampling Method Shuffle labels without replacement Resample observations with replacement
What It Tests Specific null hypothesis \(H_0\) Estimates sampling distribution of a statistic
Primary Output p-value Confidence interval
Assumption Exchangeability under \(H_0\) Sample is representative of population
Sample Size Works well even for \(n < 20\) Needs moderate \(n\) for reliable CIs

How to Conduct a Permutation Test

1
State hypotheses. Define \(H_0\) (no difference) and \(H_a\) (direction or two-sided).
2
Choose a test statistic. Common choices: difference in means \(\bar{X}_1 - \bar{X}_2\), difference in medians, or ratio of variances.
3
Compute \(T_{\text{obs}}\). Calculate the test statistic from the original (unpermuted) data.
4
Permute. Randomly shuffle the group labels and recompute the statistic. Repeat \(M\) times (or enumerate all permutations if feasible).
5
Compute p-value. \(p = \frac{\#\{|T^*| \geq |T_{\text{obs}}|\}}{M}\). Compare to significance level \(\alpha\).
6
Decide. If \(p \leq \alpha\), reject \(H_0\). Otherwise, fail to reject.

Worked Example: Drug Trial

A small clinical trial compares a new drug to a placebo. Recovery times (days) are recorded for each group:

Drug Group (\(n_1 = 4\))
5, 7, 3, 6
Mean: \(\bar{X}_1 = 5.25\)
Placebo Group (\(n_2 = 4\))
10, 12, 9, 11
Mean: \(\bar{X}_2 = 10.50\)

Permuting the Labels

Under \(H_0\), we pool all 8 values: {3, 5, 6, 7, 9, 10, 11, 12}. Then we randomly assign 4 to "Drug" and 4 to "Placebo" and compute \(T^*\).

Pooled Data 3 5 6 7 9 10 11 12 Shuffle labels "Drug" 3 7 10 11 "Placebo" 5 6 9 12
\(\bar{X}_1^* = 7.75\)
\(\bar{X}_2^* = 8.00\)
\(T^* = 7.75 - 8.00 = -0.25\)
Repeat for all 70 permutations (or sample randomly)

Example Result: p-value

After enumerating all 70 permutations, we count how many produce a difference as extreme as \(T_{\text{obs}} = -5.25\):

\(T^* = \bar{X}_1^* - \bar{X}_2^*\)
-5.25 -3.5 -1.75 0 1.75 3.5 5.25
\(T_{\text{obs}} = -5.25\)
\(-T_{\text{obs}} = 5.25\)

Larger Samples: Monte Carlo Approach

With larger groups, exact enumeration is infeasible. For \(n_1 = 20, n_2 = 25\), the number of permutations is:

1
Pool all 45 values. Compute \(T_{\text{obs}} = \bar{X}_1 - \bar{X}_2\) from the original data.
2
For each of \(M = 10{,}000\) iterations: Randomly shuffle labels. Assign first 20 to "Group 1" and next 25 to "Group 2". Compute \(T^*_i\).
3
Approximate p-value: \(p \approx \frac{\#\{|T^*_i| \geq |T_{\text{obs}} |\}}{M}\).

Monte Carlo Precision

The Monte Carlo p-value \(\hat{p}\) is itself a random variable. Its standard error depends on the number of permutations \(M\):

\(M = 1{,}000\)
SE \(\approx 0.0069\)
Rough estimate: suitable for exploratory analysis
\(M = 10{,}000\)
SE \(\approx 0.0022\)
Standard for most published research
\(M = 100{,}000\)
SE \(\approx 0.0007\)
High precision: needed for very small p-values

Exact vs. Approximate Permutation Tests

Exact Monte Carlo Approximate
Method Enumerate all \(\binom{N}{n_1}\) Random sample of \(M\) permutations
p-value Exact (no randomness) Approximate (with SE)
Feasible When \(\binom{N}{n_1} \lesssim 10^6\) Any sample size
Computation Can be slow for large \(N\) Fast, easily parallelizable
Reproducibility Always same result Set seed for reproducibility

Common Mistakes

✕ Resampling With Replacement
Permutation tests shuffle labels without replacement. Sampling with replacement is bootstrapping, which tests a different question.
✕ Ignoring Two-Sided Nature
If \(H_a\) is two-sided, count permutations where \(|T^*| \geq |T_{\text{obs}}|\), not just one tail. Forgetting this can result in a p-value that is half of what it should be.
✕ Too Few Permutations
Using \(M < 1{,}000\) in Monte Carlo yields imprecise p-values. Use at least 10,000 for publishable results.

Question 1 of 5

In a permutation test, what does the null hypothesis assume about the group labels?

Question 2 of 5

You have two groups of sizes \(n_1 = 5\) and \(n_2 = 5\). How many distinct permutations of group labels exist?

Question 3 of 5

A Monte Carlo permutation test with \(M = 10{,}000\) random shuffles finds that 320 permuted statistics exceed the observed statistic in absolute value. What is the two-sided p-value?

Question 4 of 5

Which of the following is the key difference between a permutation test and a bootstrap test?

Question 5 of 5

A researcher runs a Monte Carlo permutation test with \(M = 500\) and gets \(p = 0.048\). A colleague says this p-value is unreliable. Why?