What is a randomization test? Shuffle and count

By Jude Wallis · Published

A randomization test builds the null distribution by hand instead of from a formula: shuffle the group labels at random, recompute the statistic, repeat many times, then count how many shuffles are at least as extreme as the result you really got. That count divided by the total is the p-value.

AP Statistics: Unit 2 (topics 2.3 Estimating Probabilities Using Simulation). Simulation appears once in the Fall 2026 topic list, as Unit 2 topic 2.3, and no topic in the five-unit course is titled randomization test or randomization distribution. The tests you carry out are the named procedures in Units 3 and 4, so treat this page as the idea behind the p-value rather than as an exam procedure.

What a randomization test does

Every hypothesis test needs one thing: a distribution of the statistic assuming the null hypothesis is true. A tt test gets that distribution from a formula and a named curve. A randomization test gets it by rebuilding it out of your own data.

The procedure is short enough to state in a sentence. Take the response values you collected, throw the group labels back in a hat, deal them out at random, recompute the statistic, and write it down. Do that a few thousand times and the numbers you wrote down form a picture of what the statistic looks like when the labels mean nothing. Then see where your real result falls in that picture.

Nothing in there requires a normal population, a large sample, or a memorized standard error. The only thing it requires is that the labels were assigned at random in the first place, which is exactly what a randomized experiment guarantees. That is the trade: you give up a closed-form formula and you get a test whose validity rests on the design of the study rather than on assumptions about a population. Where a tt procedure is robust to mild non-normality but still leaning on the condition, a randomization test never leaned on it at all.

The logic: under the null, the labels are arbitrary

Here is the idea the whole method turns on, and it is worth reading twice.

Suppose the null hypothesis is true and the treatment does nothing at all. Then each subject's response would have been exactly the same number no matter which group that subject landed in. The response belongs to the subject; the label was assigned by a coin flip. So the split you actually observed is just one of the many splits the randomization could have produced, and every other split was equally likely.

That makes the reshuffling honest rather than a trick. You are not inventing data. You are listing the other outcomes your own random assignment could have delivered, under the assumption that the treatment changed nothing. If your real difference sits comfortably inside that crowd of possible differences, the randomization alone explains it. If almost none of the reshuffles reach as far as your result, then either something unlikely happened or the assumption of no effect is wrong.

Notice what the assumption buys and what it does not. Random assignment of labels is what licenses the shuffle, so a randomization test on an experiment supports a conclusion about cause. Generalizing beyond the subjects still needs random selection, exactly as in scope of inference.

The four steps

  1. Compute the statistic on the real data. Usually a difference in means or a difference in proportions. Call it the observed value and keep its sign.
  2. Pool and reshuffle. Put every response into one pile, ignoring which group it came from. Deal the responses back out into groups of the original sizes, at random.
  3. Recompute and record. Work out the same statistic on the shuffled groups and record it. Repeat a few thousand times. The recorded values are the randomization distribution, and it will be centred near zero, because you built it under the assumption of no effect.
  4. Count. Count how many recorded values are at least as extreme as the observed one, and divide by the number of shuffles. For a two-sided alternative, count both tails by using absolute values.

Step 4 is where students slip. "At least as extreme" means at or beyond the observed value, so the count includes ties, and the comparison is against the observed value itself rather than against any cutoff. The direction comes from the alternative hypothesis, the same way it does in a formula-based test. You can build the same habit on ordinary probability problems in how to design and run a simulation.

It is the definition of a p-value, run literally

A p-value is the probability of getting a result at least as extreme as the observed one, assuming the null hypothesis is true. Students memorize that sentence and then compute p-values with a calculator that hides every word of it.

A randomization test hides nothing. Read the definition and the procedure side by side:

The definition saysThe randomization test does
assuming the null hypothesis is trueshuffle the labels, which is what no effect means
a result at least as extremecount shuffles at or beyond the observed value
the probability ofdivide that count by the number of shuffles

The p-value stops being a number that appears on a screen and becomes a fraction you could count on your fingers if you had the patience. That is the real reason to learn the method even if you never run one on an exam: it makes what a p-value means concrete, and it makes the classic misreadings visibly wrong. The fraction is computed inside a world where the null hypothesis is assumed true, so it can never be the probability that the null hypothesis is true.

Small studies: you can list every possible shuffle

With a small experiment you do not have to simulate at all. You can enumerate every reassignment and get an exact answer.

Take five subjects in each group, ten in total. The number of ways to choose which five subjects get the treatment label is

(105)=252\binom{10}{5} = 252

So the randomization distribution has exactly 252 members, one for each possible assignment, and the p-value is a fraction with 252 in the denominator. In the worked example below, 7 of those 252 assignments produce a difference in means of 5.2 or more, giving a one-sided p-value of 7/252=0.02787/252 = 0.0278, and 14 reach 5.2 or more in absolute value, giving a two-sided p-value of 14/252=0.055614/252 = 0.0556.

The distribution built this way has two features worth noticing. It is centred exactly at 0, because the null hypothesis of no effect is what you assumed while building it. And because the two groups are the same size here, it is symmetric: every assignment has a mirror image that swaps the groups and flips the sign of the difference. That symmetry is why the two-sided count is exactly double the one-sided count here. With groups of different sizes the mirror image is not another assignment of the required shape, and the distribution need not be symmetric.

Enumeration stops being possible fast. Ten subjects per group already gives (2010)=184,756\binom{20}{10} = 184{,}756 assignments, and 15 per group gives more than 155 million. That is why the practical version is simulation: a random sample of the possible shuffles rather than all of them.

How many shuffles is enough

A simulated p-value is an estimate, so it carries its own error, and the source of that error is the number of shuffles rather than the number of subjects.

On the same ten-subject experiment, three runs of 1,000 shuffles each gave two-sided p-values of 0.052, 0.051 and 0.065, against the exact answer of 0.0556. Two of the estimates land 0.0036 and 0.0046 below the exact 0.0556 and the third lands 0.0094 above it, so the scatter runs to about a hundredth, not a thousandth. That does not matter when the p-value is 0.30 or 0.001, and it matters a great deal when the p-value is near 0.05 and someone is about to decide which side of the line it falls on.

The rule of thumb: the standard error of a simulated p-value near pp is p(1p)/N\sqrt{p(1-p)/N} for NN shuffles, so it shrinks like 1/N1/\sqrt{N}. At N=1000N = 1000 with pp near 0.0556 that is 0.0556(0.9444)1000=0.0072\sqrt{\frac{0.0556(0.9444)}{1000}} = 0.0072, which is the size of the scatter above. A thousand shuffles is enough for a classroom illustration, ten thousand for a result you intend to report, and if the answer sits near your significance level, run more rather than argue about the third decimal.

One more caution about counting. A simulated p-value can come out as 0 out of 10,000, and it is wrong to report it as zero. No number of shuffles can prove a probability is zero. Report it as less than 0.0001, which is what the simulation actually established.

What the Fall 2026 AP course does and does not ask for

This section sticks to what the Fall 2026 course framework lists, because the difference between what is taught and what is tested matters here.

The course has five units. Its topic list contains exactly one topic on simulation: Unit 2 topic 2.3, Estimating Probabilities Using Simulation. No topic in the five-unit list is titled randomization test or randomization distribution.

The tests you are asked to carry out are named for their formulas. Topic 3.7 is Carrying Out a Test for a Population Proportion, 3.13 is Carrying Out a Test for the Difference Between Two Population Proportions, 3.15 is Carrying Out a Chi-Square Test for Homogeneity or Independence, 4.5 is Carrying Out a Test for a Population Mean or Population Mean Difference, and 4.10 is Carrying Out a Test for the Difference Between Two Population Means. Free-response question 3 on the exam is an inference question, a hypothesis test or a confidence interval.

So, honestly: build and read simulated distributions, because that is topic 2.3 and it is where a p-value stops being a formula and becomes a count. Learn to look at a dotplot of simulated results, count the dots at or beyond the observed value, and divide. But the topic list gives no basis for expecting a question to ask you to run a randomization test in place of one of the named procedures. Treat this as the idea behind the p-value rather than as a procedure you will be asked to execute, and use the named test when the question says test.

Every possible shuffle, counted exactly

Ten volunteers are randomly assigned, five to a training program and five to a control group. Scores are: treatment 22, 25, 27, 29, 32; control 18, 20, 21, 24, 26. Carry out a two-sided randomization test of the null hypothesis that the training has no effect, using every possible reassignment. Then compare with a two-sample tt test.

  1. Compute the observed statistic. Treatment mean =22+25+27+29+325=1355=27= \frac{22+25+27+29+32}{5} = \frac{135}{5} = 27. Control mean =18+20+21+24+265=1095=21.8= \frac{18+20+21+24+26}{5} = \frac{109}{5} = 21.8. Observed difference =2721.8=5.2= 27 - 21.8 = 5.2.

  2. State the null model. If the training does nothing, each score belongs to its volunteer regardless of label, so any 5 of the 10 scores could equally well have been the treatment group.

  3. Count the possible reassignments: (105)=252\binom{10}{5} = 252. That is the whole randomization distribution, so no simulation is needed.

  4. Simplify the counting. The ten scores add to 244, so a group with sum SS gives a difference of S5244S5=2S2445\frac{S}{5} - \frac{244 - S}{5} = \frac{2S - 244}{5}. A difference of at least 5.2 therefore means 2S244262S - 244 \geq 26, that is S135S \geq 135.

  5. List the assignments with a group sum of 135 or more. There are 7 of them, with sums 139, 138, 137, 136, 136, 135, 135, giving differences 6.8, 6.4, 6.0, 5.6, 5.6, 5.2 and 5.2.

  6. One-sided p-value: 7/252=0.02787/252 = 0.0278.

  7. For the two-sided version, add the mirror-image assignments in the lower tail. The distribution is symmetric about 0, so there are 7 more, giving 14/252=0.055614/252 = 0.0556.

  8. Compare with a two-sample tt test. The sample standard deviations are s1=3.807887s_1 = 3.807887 and s2=3.193744s_2 = 3.193744, so the standard error is 14.55+10.25=4.94=2.222611\sqrt{\frac{14.5}{5} + \frac{10.2}{5}} = \sqrt{4.94} = 2.222611.

  9. t=5.22.222611=2.3396t = \frac{5.2}{2.222611} = 2.3396 with df=7.7647df = 7.7647 from the calculator's formula, giving a two-sided p-value of 0.0484.

The exact two-sided randomization p-value is 14/252=0.055614/252 = 0.0556, so at α=0.05\alpha = 0.05 you fail to reject the null hypothesis of no effect. The two-sample tt test on the same data gives t=2.3396t = 2.3396, df=7.7647df = 7.7647, p=0.0484p = 0.0484, which rejects. The two differ by 0.0072, less than a hundredth, and the exact randomization p-value is a fraction with 252 in the denominator, so it cannot move in steps finer than 1/252=0.0041/252 = 0.004. Neither answer is the wrong one. When two valid analyses straddle 0.05 like this, the honest report is that the evidence is borderline.

Reading a simulated randomization distribution

Twenty patients are randomly assigned, ten to a new therapy and ten to a placebo. Eight of the ten on the therapy improve, against two of the ten on the placebo. Run a two-sided randomization test of the null hypothesis of no treatment effect, first by simulation and then exactly.

  1. Observed statistic: p^1p^2=810210=0.800.20=0.60\hat{p}_1 - \hat{p}_2 = \frac{8}{10} - \frac{2}{10} = 0.80 - 0.20 = 0.60.

  2. The null model: 10 of the 20 patients would have improved no matter what, and 10 would not. Reshuffling means dealing those 20 fixed outcomes into two groups of 10 at random.

  3. Simulate. In one run of 1,000 shuffles, 23 produced a difference in proportions of 0.60 or more in absolute value.

  4. Simulated two-sided p-value: 231000=0.023\frac{23}{1000} = 0.023.

  5. Now the exact version. The number of ways to choose the therapy group is (2010)=184,756\binom{20}{10} = 184{,}756.

  6. A difference of 0.60 or more in absolute value means the therapy group holds at least 8 of the 10 improvers, or at most 2 of them.

  7. Counting those assignments gives 2,126 in the upper tail and 2,126 in the lower tail, so 4,252 in total.

  8. Exact two-sided p-value: 4252184756=0.0230\frac{4252}{184756} = 0.0230, which the 1,000-shuffle simulation estimated as 0.023.

  9. Decide: 0.0230<0.050.0230 < 0.05, so reject the null hypothesis of no treatment effect.

The simulated p-value is 23/1000=0.02323/1000 = 0.023 and the exact p-value is 4252/184756=0.02304252/184756 = 0.0230. Both are below 0.05, so there is convincing statistical evidence that the improvement rate differs between the therapy and the placebo, and the observed difference favours the therapy. Because the treatment was randomly assigned, the conclusion is causal for the 20 patients studied; generalizing to a wider population would need random selection as well.

Frequently asked questions

How is a randomization test different from a t test?

They answer the same question with different null distributions. A tt test assumes a shape for the population and reads the p-value off a named curve. A randomization test builds the null distribution from your own data by reshuffling the labels, so it needs no assumption about the population, only that the assignment was random. On borderline data the two can land on opposite sides of 0.05.

Why shuffle the group labels instead of resampling the data?

Because shuffling is what the null hypothesis of no effect literally claims: the label had no bearing on the response. Resampling values with replacement is a different method, the bootstrap, which estimates a sampling distribution for building an interval rather than testing a claim of no effect. The bootstrap is not in the Fall 2026 topic list.

How many shuffles do I need?

A thousand is enough to see the shape and pin the p-value to about a hundredth; ten thousand is better if you plan to report it. The standard error of a simulated p-value near pp is p(1p)/N\sqrt{p(1-p)/N}, so accuracy improves like 1/N1/\sqrt{N}. Three separate 1,000-shuffle runs on the same small experiment gave 0.052, 0.051 and 0.065 against an exact answer of 0.0556.

Can a simulated p-value be zero?

No. If 0 of 10,000 shuffles reach your observed value, the honest report is that the p-value is less than 0.0001, not that it is 0. A simulation can only bound a probability from above by the resolution of the run, and a probability of exactly zero would mean the result was impossible under the null hypothesis, which reshuffling never establishes.

Is a randomization test on the AP Statistics exam?

The Fall 2026 course lists one simulation topic, 2.3 Estimating Probabilities Using Simulation, and no topic titled randomization test or randomization distribution. The tests you are asked to carry out are the named z, t and chi-square procedures in Units 3 and 4. Expect to build and read simulated distributions; use the named procedure when a question says to test.