Estimating sample size for an RT experiment with permutation tests

How many trials each subject completes changes how many subjects you need. Drag the sliders to watch the noise shrink, and to see why the number of people eventually stops falling.

How many trials per person, and how many people?

Paired (within-subject) design, two-sided α = 0.05, target power = 0.80. The parameters are assumptions; see “The generative model” below.

30

subjects reach power 0.80 at the current n

16

subjects is the floor with unlimited trials

The blue dashed line is the floor set by between-subject variance. The vermilion area is what more trials can still save.

This page uses a flanker- or Stroop-style reaction-time (RT) experiment to show how to estimate the number of subjects you need with simulation and a permutation test, and why the number of trials per subject changes the answer.

Every parameter here (the RT distribution, the effect size, the between-subject variability) is an assumption of mine, not an estimate from real data. Before using this to plan your own study, replace them with values from pilot data or the literature, and run at least one effect size smaller than you expect.

Keep the decision rule and the effect separate

There is no ready-made power formula for a permutation test. It builds its null distribution by reshuffling labels or signs in the data you already have, and that step never produces data in which an effect really exists. So estimating power splits into two jobs: the permutation test supplies the decision rule that says whether a dataset counts as significant, and a generative model you assume supplies the effect. Permuting data washes the effect out, so permutation cannot be used to create H1 data.

Connect the two, repeat many times, and the share of significant results is the power.

  1. Data generation: your assumptionsAssume a true effectMean δ, between-subject SD σb
  2. Data generation: your assumptionsSimulate trialsn RTs per condition for every subject
  3. Decision rule: permutation testOne difference per subjectIncongruent mean minus congruent mean gives di
  4. Decision rule: permutation testSign-flip permutationB flips build the null distribution and give a p value
  5. IterateRepeat S timesThe share of significant runs is power. Change N and go again

The generative model

Each subject has n trials in each of two conditions (congruent, incongruent). Baseline RT is the same in both conditions, so it cancels in the subtraction and does not affect power; in real data, slower people often show larger effects, a correlation not simulated here. Subject i’s true effect θi is normal with mean δ and standard deviation σb.

Each subject is reduced to one number:

di = RTincongruent, i − RTcongruent, i

After averaging n trials, di is approximately normal and can be written as the true effect plus estimation error:

di ≈ θi + εi, Var(εi) = 2σ2tn
δ
Mean effect. Simulated at 25 ms and 15 ms.
σb = 20 ms
Standard deviation of the true effect across subjects.
σt ≈ 89.4 ms
SD of a single-trial RT. RT is Gaussian (SD 40 ms) plus an exponential tail (τ = 80 ms), the usual right-skewed ex-Gaussian, so σt = √(40² + 80²).
Baseline RT
Mean 550 ms, SD 60 ms, identical in both conditions.
B = 2000, S = 1000
2000 permutations per experiment; 1000 simulated experiments per setting.

What the permutation test does

The null hypothesis in a paired design is that the distribution of the differences di is symmetric around 0. If that holds, flipping the sign of any subject’s difference leaves the data just as probable. So keep every |di|, choose each subject’s sign at random, recompute the group mean, and repeat B times. The result is the distribution of group means you would see if the null were true.

The p value is the proportion of that distribution whose absolute value is at least the observed one, with 1 added to numerator and denominator so p is never 0.

The demo below uses one simulated experiment: 12 subjects, 40 trials per condition, a true mean effect of 25 ms, and an observed group mean of 26.3 ms.

Flip it yourself

Filled dots keep their original sign; hollow dots were flipped; small grey dots mark the original position. The right panel accumulates the group mean after every flip, and the hatched areas are the tails at least as extreme as the observed mean. The 12 differences come from one simulated experiment (random seed 2, group mean close to the true effect, so a typical result).

di for 12 subjects

Null distribution of the group mean

Sweeping N to get power

Hold every subject at 40 trials per condition, run 1000 simulated experiments for each candidate N, and use true mean effects of 25 ms and 15 ms.

For comparison there is also an analytic approximation that holds when di is roughly normal: the standardized effect below, plugged into the power of a paired t-test (noncentral t distribution). It is not the permutation test itself, but the two agree closely when di is near normal, so it works as a check on the simulation and a fast way to scan many parameter sets.

dz = δ√σ2b + 2σ2t / n
Permutation (simulated), δ = 25 ms Permutation (simulated), δ = 15 ms Paired-t approximation, δ = 25 ms Paired-t approximation, δ = 15 ms
Power against number of subjects at 40 trials per condition. Each simulated point is 1000 experiments; dashed lines are the analytic approximation; the dotted line marks 0.80.
Show the data table
Simulated power of the permutation test (1000 simulated experiments per cell)
Nδ = 25 msδ = 15 ms
80.5190.223
100.7150.298
120.7950.346
150.8950.471
180.9460.570
200.9650.614
250.9870.758
300.9970.798
401.0000.915

With 0.80 as the target: at an effect of 25 ms, the simulation gives 0.795 at N = 12 and 0.895 at N = 15, and the analytic approximation puts the smallest N at 13. At 15 ms the simulation gives 0.798 at N = 30, and the analytic smallest N is 30. For the same design, shrinking the true effect from 25 ms to 15 ms raises the required number from about 13 to about 30, more than double. The assumed effect size matters more than any other setting.

Simulation and approximation agree closely, except at N = 8, where the simulation (0.519) is clearly below the approximation (0.576). My guess is that with so few subjects there are only 28 = 256 sign patterns, p values are coarse, and the test is conservative; this is a guess I have not checked. Each simulated point carries a Monte Carlo error of about 0.01 to 0.016 (S = 1000), so smaller differences should not be read into.

Why the number of trials matters

The permutation test sees one difference di per subject and does not know how many trials stand behind it. Trial count affects power only through the noise in di. From the model above, the variance of di has two terms:

Var(di) = σ2b + 2σ2tn

The blue term is the real difference between people and does not change with n; the vermilion term is trial noise and shrinks as n grows. The explorer at the top of the page draws exactly these two terms. When n is small the vermilion part dominates and more trials shrink the total variance a lot; once n is large only the blue part is left, dz approaches its ceiling δ / σb, and no number of extra trials can get past it.

The two sources of Var(di), and dz at δ = 15 ms and δ = 25 ms
n (trials per condition)σb² (ms²)2σt²/n (ms²)SD(di) (ms)dz, δ = 15dz, δ = 25
5400320060.00.250.42
10400160044.70.340.56
2040080034.60.430.72
4040040028.30.530.88
8040020024.50.611.02
16040010022.40.671.12
3204005021.20.711.18
6404002520.60.731.21

The figure below checks this: N = 20 and δ = 15 ms are fixed, and only the trial count varies.

Permutation (simulated) Paired-t approximation Ceiling with unlimited trials Power taken by trial noise
Power against trials per condition at N = 20 and δ = 15 ms. The dotted line marks 0.80.
Show the data table
N = 20, δ = 15 ms; 1000 simulated experiments per row
nPermutation (simulated)Paired-t approximation
100.3030.297
200.4390.452
400.6300.614
800.7380.738
1600.8440.812
3200.8430.851

Power climbs fast as trials go from 10 to 80 (0.30 to 0.74) and then flattens. The simulation gives almost the same value at 160 and 320 (0.844 and 0.843), while the approximation gives 0.812 and 0.851. That gap is within Monte Carlo error (about 0.011); it does not mean power stops rising after 160, only that it rises slowly.

The blue dashed line is the power that corresponds to dz reaching its ceiling of 0.75 (about 0.89). At N = 20 and δ = 15 ms, power cannot exceed this no matter how many trials each person completes; to go higher you need more subjects.

More subjects or more trials?

Plugging the dz formula into the analytic approximation gives the smallest N that reaches 80% power at each trial count. The curve in the explorer at the top is a continuous version of this table.

Smallest number of subjects for 80% power (two-sided α = 0.05) at each trial count (analytic approximation). The shaded row is the 40 trials per condition used in the simulations above.
n (trials per condition)δ = 25 msδ = 15 ms
102872
201844
401330
801023
160920
320818
640817
Unlimited816

Taking δ = 15 ms: 10 trials per condition needs about 72 subjects, 40 trials needs 30, 160 trials needs 20, and even unlimited trials needs 16. At δ = 25 ms the matching numbers are 28, 13, 9 and 8.

When planning, pick a combination of subjects and trials per subject first, then check the table to see whether power is enough. If recruiting is expensive, adding trials can save subjects, but the saving has a floor: 16 and 8 subjects for the two effect sizes. The table comes from the analytic approximation, so before relying on it, run power() from the source file on the combination you plan to use.

In practice

  1. Swap in your own generative model. With pilot data you can bootstrap subjects instead of generating them from a parametric model, then compare with the results here. A large gap means the assumed distribution shape is off. A bootstrap cannot extrapolate to an N larger than the pilot.
  2. Swap in the statistic you will actually use. If your analysis uses a median difference, a trimmed mean, or max-statistic correction, change only the statistic inside perm_p; the rest of the pipeline stays the same. This is the main advantage of simulation over an analytic formula.
  3. Run a range of effect sizes. Effect sizes from pilots are usually inflated. Run at least one shrunken value (for example half to two-thirds of the pilot estimate) and report a range of N.
  4. Watch Monte Carlo error. With power near 0.8, S = 1000 gives a standard error of about 0.013; do not read into differences between neighboring values of N that are smaller than that.
  5. Check B. The smallest possible permutation p value is 1/(B+1). With a stricter α (after multiple-comparison correction, for instance), B must grow with it.

Limits

  • Everything depends on the assumed model: independent trials, approximately normal effects across subjects, and no correlation between baseline RT and effect size. Real RT data often show practice effects, fatigue, and serial dependence, which stop trial noise from shrinking as 1/n.
  • σb = 20 ms is an assumption. The smaller the between-subject variability, the longer extra trials keep paying off; the larger it is, the sooner the ceiling arrives.
  • The permutation unit here is the subject (sign flips on subject-level differences). If your real analysis is trial-level (a mixed-effects model, or permuting condition labels within subjects), the exchangeable unit and the simulation have to be redesigned, and these results do not carry over directly.
  • The analytic approximation is only a check. With very few subjects, clearly skewed differences, or outliers, the power of a permutation test and a t-test can differ, and the simulation should be trusted.