Estimate how many pairs you need so that the confidence interval for the mean difference in a before/after (or repeated-measures) design reaches the precision you set.
Calculator
Calculate the minimum number of pairs to estimate the mean difference with a target precision.
Explanation
This calculator determines the minimum number of pairs of observations needed to estimate the population mean difference \(\mu_d\) with a maximum absolute margin of error \(E\) and a given confidence level. It is used when the study design pairs each observation in one group with a specific observation in the other: a before/after measurement on the same subjects, two methods applied to the same samples, or pairs matched on relevant characteristics.
The formula is mathematically identical to the one for a single mean, but applied to the differences. The key parameter you need to know beforehand is \(\sigma_d\), the standard deviation of the individual differences \(d_i = x_{i,\text{after}} - x_{i,\text{before}}\). This value is not the standard deviation of each group separately, but the spread of the individual changes.
The formula uses the normal quantile Z, which assumes that \(\sigma_d\) is known or that the sample is large enough. For small samples (< 30 pairs) with unknown \(\sigma_d\), the real n may be somewhat larger; you can iterate by replacing Z with the t quantile with n−1 degrees of freedom.
Sample size formula
\( n = \left(\dfrac{Z \cdot \sigma_d}{E}\right)^2 \)
- n: minimum number of pairs (rounded up to the nearest integer).
- Z: normal quantile — 1.645 (90%), 1.960 (95%), 2.576 (99%).
- \(\sigma_d\): standard deviation of the individual differences \(d_i\).
- E: maximum tolerable absolute margin of error for \(\mu_d\) (in the same units as the differences).
Relationship between σ_d, E and n
The sample size grows quadratically with the required precision: halving E quadruples n. It also grows quadratically with \(\sigma_d\): if the variability of the individual changes doubles, you need four times as many pairs. A key feature of the paired design is that \(\sigma_d\) is usually smaller than the standard deviation of each group separately when the measurements are correlated, which makes this design more efficient than comparing two independent groups.
Quick setup
- Standard deviation of the differences (σ_d): take it from pilot studies, the literature, or historical data for the same type of measurement. Don't confuse σ_d with the standard deviation of each group.
- If you don't have σ_d: run a pilot study of 10–20 pairs and calculate the standard deviation of the differences. As a conservative alternative, use the standard deviation of the individual measurements (it tends to overestimate σ_d when the pairs are correlated).
- Confidence level: 95% is the standard in most scientific disciplines.
- Maximum error E: define it in the same units as the differences and in practical terms: from what difference in the mean change would you make a different decision?
- Expected dropout: divide n by (1 − expected dropout rate). In longitudinal studies it is common to reserve an extra 10–20%.
Worked example
A clinical team wants to estimate the mean decrease in systolic blood pressure (mmHg) after 8 weeks of treatment with a new drug. From a pilot study with 15 patients they find that the standard deviation of the individual differences (before − after) is \(\sigma_d \approx 8.0\) mmHg. The team decides that the estimate must be precise within \(E = 2\) mmHg with a 95% confidence level (\(Z = 1.960\)).
We apply the formula directly:
\( n = \left(\dfrac{Z \cdot \sigma_d}{E}\right)^2 = \left(\dfrac{1.960 \times 8.0}{2.0}\right)^2 = (7.84)^2 = 61.47 \rightarrow n = 62 \text{ pairs} \)
At least 62 patients with valid before-and-after measurements are needed. With an expected 15% dropout, the number of patients to recruit initially is:
\( n_{\text{recruit}} = \frac{62}{1 - 0.15} = \frac{62}{0.85} \approx 73 \text{ patients} \)
Sensitivity analysis: if the team accepted a margin of error of \(E = 3\) mmHg, the sample would shrink considerably: \( n = (1.960 \times 8.0 / 3.0)^2 = (5.227)^2 = 27.3 \rightarrow n = 28\). Correctly defining the tolerable margin of error has a huge impact on the feasibility of the study.
Model assumptions
- The pairs are independent of each other (but the two observations within each pair are not, and that is exactly what the design exploits).
- The distribution of the differences \(d_i\) is approximately normal, or n is large enough for the CLT to guarantee normality of the estimator.
- The standard deviation \(\sigma_d\) is known or reliably estimated.
- The margin of error \(E\) applies to the mean difference \(\mu_d\), not to each group separately.
Common uses
- Clinical intervention trials with pre- and post-measurement on the same subjects.
- Validation studies of measurement methods (comparing instrument A vs. B on the same samples).
- Educational or psychological experiments with a before/after design.
- Quality control with samples measured by two operators or at two points in time.
How to interpret the result
The value \(n\) is the minimum number of valid pairs (subjects with both measurements complete) needed so that the confidence interval for the within-subject mean difference has a maximum half-width of \(E\) at the specified confidence level. Always round up. If you expect some pairs to be incomplete (loss of one of the two measurements), add a margin: divide \(n\) by \((1 - \text{loss rate})\) to get the number of pairs you should start with.
The most influential and hardest-to-know-in-advance parameter is \(\sigma_d\), the standard deviation of the paired differences. This quantity is not the standard deviation of each individual measurement, but the variability of the difference \(d_i = x_{i,\text{post}} - x_{i,\text{pre}}\) for each subject. If you have pilot data, estimate it directly from the observed differences. In the absence of prior data, use the relationship \(\sigma_d \approx \sigma\sqrt{2(1-\rho)}\) where \(\sigma\) is the standard deviation of a single measurement and \(\rho\) is the expected test-retest correlation. Run a sensitivity analysis with \(\sigma_d - 25\%\), \(\sigma_d\) and \(\sigma_d + 25\%\) and plan using the largest value.
The advantage of the paired design over independent groups is that it eliminates between-subject variability, which can substantially reduce \(n\) when the within-subject correlation is high (\(\rho > 0.5\)). If the resulting CI will be used to make a clinical decision, check that the value of \(E\) has a clear practical interpretation (e.g., the minimum clinically relevant difference). Once you have collected the pairs, use the hypothesis-test calculator for paired means if you want to run a hypothesis test, or build the CI directly with the confidence interval calculator for the difference of means.
References and further reading
- Altman, D. G. (1991). Practical Statistics for Medical Research. Chapman & Hall. — paired study design and sample size calculation.
- Machin, D., Campbell, M. J., Tan, S. B., & Tan, S. H. (2018). Sample Sizes for Clinical, Laboratory and Epidemiology Studies (4th ed.). Wiley-Blackwell.
- Wikipedia: Sample size determination — derivation for means and other variants.
Frequently asked questions
- What happens if σ_d is larger than expected? The real margin of error will be larger than E. That's why it's wise to be conservative when estimating σ_d and, if in doubt, run a sensitivity analysis with different values.
- When should I use t instead of Z? When n < 30 and σ_d is unknown. Iterate: calculate n with Z, then replace Z with t(n−1) and recalculate until convergence.
- Does this calculation work for hypothesis testing? Not directly. To detect a difference with a given power and significance level, use the paired means calculator for hypothesis testing.
- Why can the paired design need fewer subjects than two independent groups? Because \(\sigma_d\) is usually smaller than \(\sqrt{\sigma_1^2 + \sigma_2^2}\) when the measurements within each pair are positively correlated. The higher that correlation, the more efficient the paired design is.