For two independent groups and a two-sided test at level $\alpha$ with power $1 - \beta$, each group needs $n = [(z_{1-\alpha/2} + z_{1-\beta})/(\mu_1 - \mu_2)]^2(\sigma_1^2 + \sigma_2^2)$; with equal standard deviations and 80% power that is about $16(\sigma/(\mu_1 - \mu_2))^2$ per group, twice the one-sample total. For 5 mm Hg in adults aged 60 and over ($\sigma = 21.0$ mm Hg) the exact noncentral $t$ answer is 279 per group, one more than the $z$ formula, and NHANES simulation confirmed power 0.801. Groups sized in proportion to their standard deviations minimize the total (about 6% saved for the NHANES age groups); a $k$:1 allocation inflates it by $(1 + k)^2/(4k)$; a paired design needs $(1 - \rho)$ times one arm, 50 patients against 456 for Student's sleep trial.
Power and Sample Size for a Test of a Mean planned a study of adults aged 60 and over that would compare their mean systolic blood pressure with a known value, the mean of all adults. It found that 141 people give an 80% chance of detecting a difference of 5 mm Hg. Most clinical questions are not like that. A trial of a blood pressure drug compares a treated group with a control group, and neither group's mean is known in advance. Both have to be estimated, and both estimates carry error. How many older adults would such a trial need for the same 5 mm Hg?
About four times as many. For two independent groups with equal standard deviations, each group needs about twice as many subjects as the one-sample study needs in total: 279 per group, 558 in all, against 141. This article derives that answer and the choices that change it.
Here is the route. First we derive the per-group formula from the power of the two-sample test, and see where the factor of 2 comes from. Then we plan a two-arm trial, correct the answer for the $t$ distribution and check it by simulation from NHANES. Next we turn to the choices that move the answer: unequal standard deviations, unequal group sizes, and pairing. Worked problems close the article. The article assumes the power function, the noncentral $t$ distribution and the one-sample formula of Power and Sample Size for a Test of a Mean, and uses them without re-deriving them. The sample size formulas for paired designs and for two independent groups are those of the course text (Pagano, Gauvreau and Mattie, 2022), written in its notation; the allocation results are derived here.
The power of a two-sample test
Here is the idea in one sentence. The one-sample power calculation carries over unchanged, except that the standard error is now that of a difference between two means.
Consider two independent groups of $n$ subjects each, from populations with means $\mu_1$ and $\mu_2$ and standard deviations $\sigma_1$ and $\sigma_2$, and the two-sided test of $H_0: \mu_1 = \mu_2$ at level $\alpha$. As in the one-sample case, we start with the $z$ version, as if the standard deviations were known. From The Two-Sample t-Test, the difference in sample means has standard error
$$SE = \sqrt{\frac{\sigma_1^2}{n} + \frac{\sigma_2^2}{n}} = \frac{\sqrt{\sigma_1^2 + \sigma_2^2}}{\sqrt{n}},$$
and the test rejects when $|z| \ge z_{1-\alpha/2}$, where $z = (\bar{x}_1 - \bar{x}_2)/SE$.
The one-sample article showed that the power of a $z$ test depends on the design only through $\lambda$, the true difference measured in standard errors. The same argument applies here, and it is short enough to give in full. For normal populations, $(\bar{X}_1 - \bar{X}_2) - (\mu_1 - \mu_2)$ divided by $SE$ is a standard normal variable $Z_0$ (The Two-Sample t-Test), so the test statistic is
$$Z = \frac{\bar{X}_1 - \bar{X}_2}{SE} = Z_0 + \lambda, \qquad \lambda = \frac{\mu_1 - \mu_2}{SE} = \frac{(\mu_1 - \mu_2)\sqrt{n}}{\sqrt{\sigma_1^2 + \sigma_2^2}}.$$
The test rejects when $Z_0 + \lambda \ge z_{1-\alpha/2}$ or $Z_0 + \lambda \le -z_{1-\alpha/2}$, two events that cannot both happen. Writing $\Phi$ for the standard normal distribution function and using its symmetry, the power is
$$P(Z_0 \ge z_{1-\alpha/2} - \lambda) + P(Z_0 \le -z_{1-\alpha/2} - \lambda) = \Phi(\lambda - z_{1-\alpha/2}) + \Phi(-\lambda - z_{1-\alpha/2}),$$
the one-sample power function with the new $\lambda$.
Now solve for a target power $1 - \beta$, taking $\mu_1 > \mu_2$ so that $\lambda > 0$. The second term is the chance of rejecting in the wrong direction. It is below $\alpha/2$ for every $\lambda > 0$. Once $\lambda \ge z_{1-\alpha/2}$, where the first term is at least one half, it is at most $\Phi(-2z_{1-\alpha/2})$, which is 0.00004 at $\alpha = 0.05$. Dropping it, the power is at least $1 - \beta$ when $\Phi(\lambda - z_{1-\alpha/2}) \ge 1 - \beta$, that is, when $\lambda - z_{1-\alpha/2} \ge z_{1-\beta}$:
$$\frac{(\mu_1 - \mu_2)\sqrt{n}}{\sqrt{\sigma_1^2 + \sigma_2^2}} \ge z_{1-\alpha/2} + z_{1-\beta} \quad\Longleftrightarrow\quad n \ge \left(\frac{z_{1-\alpha/2} + z_{1-\beta}}{\mu_1 - \mu_2}\right)^2 (\sigma_1^2 + \sigma_2^2).$$
The smallest such $n$ is the right side rounded up. Dropping a positive term can only understate the power, so the $z$ test's power at this $n$ is at least $1 - \beta$. This is the course text's formula. Note that $n$ is the number of subjects in each group, so the study enrolls $2n$. The standard deviations need not be equal. For a one-sided test of $H_A: \mu_1 > \mu_2$, the test rejects when $Z \ge z_{1-\alpha}$, the power is exactly $\Phi(\lambda - z_{1-\alpha})$, and $z_{1-\alpha}$ replaces $z_{1-\alpha/2}$ in the formula.
The factor of 2
When the two populations have the same standard deviation $\sigma$, $\sigma_1^2 + \sigma_2^2 = 2\sigma^2$ and
$$n = 2\left[\frac{(z_{1-\alpha/2} + z_{1-\beta})\,\sigma}{\mu_1 - \mu_2}\right]^2 \text{ per group}.$$
The bracket is the one-sample formula. So each group needs twice the one-sample study's total, and the whole study four times as many subjects. The two factors of 2 have separate causes.
- Both means are estimated. The variance of $\bar{x}_1 - \bar{x}_2$ is $2\sigma^2/n$, twice the variance of a single mean compared with a known value.
- There are two groups to fill.
A one-sample design against a known value is cheaper because it borrows the comparison value from outside the study. That is legitimate only when the value really is known, as the all-adult NHANES mean was in the earlier article. When the comparison has to be measured, so does its uncertainty.
For 80% power at $\alpha = 0.05$, $2(z_{0.975} + z_{0.80})^2 = 2(1.9600 + 0.8416)^2 = 15.70$, so roughly
$$n \approx 16\left(\frac{\sigma}{\mu_1 - \mu_2}\right)^2 \text{ per group},$$
a rule of thumb worth remembering. For 90% power the multiplier is $2(1.9600 + 1.2816)^2 = 21.01$.
Planning a two-arm trial
Back to the older adults. Suppose a trial in adults aged 60 and over will randomize participants to a new treatment or to usual care. It wants an 80% chance of detecting a 5 mm Hg difference in mean systolic pressure with a two-sided test at 0.05. For planning, both arms are given the standard deviation of the NHANES adults aged 60 and over, $\sigma = 21.024$ mm Hg.
Example (twice the one-sample answer). The one-sample study, for the same difference and standard deviation, had a $z$-formula answer of 138.77. The two-group formula gives exactly twice as much per group, since the bracket is the same:
$$n = \left(\frac{1.9600 + 0.8416}{5}\right)^2 (21.024^2 + 21.024^2) = 277.54, \quad\text{so } 278 \text{ per group},$$
and 556 in all, a ratio to 138.77 of exactly 2.000 per group. For 90% power, $z_{0.90} = 1.2816$ gives 371.55, so 372 per group.
Correcting for t
The trial will be analyzed with the pooled two-sample $t$-test, so the $z$ answer needs the same check as in the one-sample case. Under the alternative, the pooled statistic has a noncentral $t$ distribution, as the one-sample statistic did, with two changes. It has $2n - 2$ degrees of freedom, and its noncentrality is $\lambda = (\mu_1 - \mu_2)/(\sigma\sqrt{2/n})$.
Here is why, for group sizes $n_1$ and $n_2$ that need not be equal. The noncentral $t$ distribution with $\nu$ degrees of freedom and noncentrality $\lambda$ is defined in Power and Sample Size for a Test of a Mean as the distribution of $(Z_0 + \lambda)/\sqrt{V/\nu}$, where $Z_0$ is standard normal, $V$ is chi-squared with $\nu$ degrees of freedom, and the two are independent. For two normal populations with a common $\sigma$, the pooled statistic computed under $H_0$ is
$$t = \frac{\bar{X}_1 - \bar{X}_2}{S_p\sqrt{1/n_1 + 1/n_2}} = \frac{Z_0 + \lambda}{\sqrt{V/(n_1 + n_2 - 2)}}, \qquad \lambda = \frac{\mu_1 - \mu_2}{\sigma\sqrt{1/n_1 + 1/n_2}},$$
where $Z_0 = [(\bar{X}_1 - \bar{X}_2) - (\mu_1 - \mu_2)]/(\sigma\sqrt{1/n_1 + 1/n_2})$ and $V = (n_1 + n_2 - 2)S_p^2/\sigma^2$. The proof of the pooled test in The Two-Sample t-Test shows that $Z_0$ is standard normal, that $V$ is chi-squared with $n_1 + n_2 - 2$ degrees of freedom, and that the two are independent, whatever the two means are. So $t$ is noncentral $t$ with $n_1 + n_2 - 2$ degrees of freedom and noncentrality $\lambda$. With $n_1 = n_2 = n$ these are $2n - 2$ and $(\mu_1 - \mu_2)/(\sigma\sqrt{2/n})$.
The power is the noncentral-$t$ tail sum of the one-sample article, with $t_{2n-2,\,1-\alpha/2}$ as the critical value:
$$1 - \beta = P(T' \ge t_{2n-2,\,1-\alpha/2}) + P(T' \le -t_{2n-2,\,1-\alpha/2}),$$
with $T'$ noncentral $t$ as scipy defines it (scipy.stats.nct).
Example (a smaller correction than for one sample). For one sample, the $t$ correction added two subjects (139 to 141). Here it adds fewer per group: one. With $2n - 2 = 554$ degrees of freedom instead of 138, the $t$ distribution is much closer to the normal. At 278 per group the power is 0.7993, a hair short of 0.80, and the smallest $n$ that reaches 0.80 is 279 (power 0.8007). The NIST/SEMATECH e-Handbook of Statistical Methods (§7.2.2.2) suggests iterating with $t$ quantiles for the one-sample case. Doing so here, $t_{554,\,0.975} = 1.9643$ and $t_{554,\,0.80} = 0.8423$ give 278.52, so 279, and the iteration stays there. For 90% power the exact answer is 373 per group. In every entry of the table below, the exact answer is the $z$ formula's plus one.
A simulation checks the plan against real data. The script drew two samples of 279 from the NHANES older adults, added 5 mm Hg to every value in one of them, and applied the pooled $t$-test, 10,000 pairs of samples for each of 30 seeds. The power was 0.801 (median; interquartile range 0.799 to 0.803). The skewness of real blood pressures makes no practical difference at this size.
A study that sized each arm by the one-sample formula, 139 per group, would have power 0.506 (0.508 in the simulation). That is a coin toss for a difference it was designed to detect.
A table
Sample size per group for the two-sided pooled $t$-test at $\alpha = 0.05$, by the standardized difference $(\mu_1 - \mu_2)/\sigma$:
| $(\mu_1 - \mu_2)/\sigma$ | 80% power, $z$ formula | exact $t$ | 90% power, $z$ formula | exact $t$ |
|---|---|---|---|---|
| 0.20 | 393 | 394 | 526 | 527 |
| 0.25 | 252 | 253 | 337 | 338 |
| 0.50 | 63 | 64 | 85 | 86 |
| 0.75 | 28 | 29 | 38 | 39 |
| 1.00 | 16 | 17 | 22 | 23 |
The total study is twice each entry. The standardized difference is the population value of the effect size $d$ of Effect Sizes and Standardized Differences, which puts the NHANES difference between men and women at about a tenth of a standard deviation, below the smallest row of this table. Compared with the one-sample table of the earlier article (8 at a standardized difference of 1, 197 at 0.2, for 80% power), each entry is about double.
So far both groups were alike. The next three sections take groups that differ: in spread, in size, and in whether they are separate groups at all.
Unequal standard deviations
The formula allows $\sigma_1 \ne \sigma_2$. Suppose a study will compare an outcome between a younger and an older group whose spreads are like those of systolic pressure in NHANES. Then $\sigma_1 = 21.024$ mm Hg for adults aged 60 and over and $\sigma_2 = 12.849$ for those aged 18 to 39. The study wants 80% power to detect a 5 mm Hg difference. With equal groups,
$$n = \left(\frac{1.9600 + 0.8416}{5}\right)^2 (21.024^2 + 12.849^2) = 190.60, \quad\text{so } 191 \text{ per group, 382 in all}.$$
The analysis would use Welch's test, since the variances are not assumed equal. Simulating it from the two NHANES groups, with the older group's values shifted so that the means differ by exactly 5 mm Hg, gave power 0.805.
The optimal allocation
Equal groups are not the most efficient design when the standard deviations differ.
Example (where the subjects should go). With 382 subjects to place, the more variable group should get more than half of them: its share is $\sigma_1/(\sigma_1 + \sigma_2) = 21.024/33.873 = 62\%$ for these two groups, by the derivation below. Its mean is the noisier of the two, so an extra subject there removes more variance.
Here is the plan of the derivation. The power of the $z$ test depends on the sample sizes only through $\lambda$, and so only through the standard error of the difference, $\sqrt{\sigma_1^2/n_1 + \sigma_2^2/n_2}$. So the question is how to make that standard error a given size $\sqrt{V}$ with the fewest subjects.
The formal version. Minimize $n_1 + n_2$ subject to
$$\frac{\sigma_1^2}{n_1} + \frac{\sigma_2^2}{n_2} = V.$$
With a Lagrange multiplier $\kappa$, set the derivatives of $n_1 + n_2 + \kappa(\sigma_1^2/n_1 + \sigma_2^2/n_2 - V)$ with respect to $n_1$ and $n_2$ to zero. That gives $1 = \kappa\sigma_i^2/n_i^2$, so $n_i = \sqrt{\kappa}\,\sigma_i$: each group's size should be proportional to its standard deviation,
$$\frac{n_1}{n_2} = \frac{\sigma_1}{\sigma_2}.$$
Substituting back, the constraint gives $\sigma_1/\sqrt{\kappa} + \sigma_2/\sqrt{\kappa} = V$, so $\sqrt{\kappa} = (\sigma_1 + \sigma_2)/V$ and
$$n_1 = \frac{\sigma_1(\sigma_1 + \sigma_2)}{V}, \qquad n_2 = \frac{\sigma_2(\sigma_1 + \sigma_2)}{V}, \qquad n_1 + n_2 = \frac{(\sigma_1 + \sigma_2)^2}{V}.$$
The multiplier finds a stationary point. That it is the minimum follows from the Cauchy–Schwarz inequality, applied to the pairs $(\sqrt{n_1}, \sqrt{n_2})$ and $(\sigma_1/\sqrt{n_1}, \sigma_2/\sqrt{n_2})$. For any positive $n_1$ and $n_2$ that meet the constraint,
$$(\sigma_1 + \sigma_2)^2 = \left(\sqrt{n_1}\cdot\frac{\sigma_1}{\sqrt{n_1}} + \sqrt{n_2}\cdot\frac{\sigma_2}{\sqrt{n_2}}\right)^2 \le (n_1 + n_2)\left(\frac{\sigma_1^2}{n_1} + \frac{\sigma_2^2}{n_2}\right) = (n_1 + n_2)\,V.$$
So $n_1 + n_2 \ge (\sigma_1 + \sigma_2)^2/V$ for every allocation, with equality exactly when the pairs are proportional, which is $n_1/n_2 = \sigma_1/\sigma_2$.
Equal groups of $m$ each meet the constraint when $(\sigma_1^2 + \sigma_2^2)/m = V$, a total of $2m = 2(\sigma_1^2 + \sigma_2^2)/V$. The ratio of the two totals,
$$\frac{2(\sigma_1^2 + \sigma_2^2)}{(\sigma_1 + \sigma_2)^2},$$
is at least 1, with equality only when $\sigma_1 = \sigma_2$, since $2(a^2 + b^2) - (a + b)^2 = (a - b)^2$.
For the age groups, $\sigma_1/\sigma_2 = 1.636$. With $V$ set by the target power, $V = [5/(z_{0.975} + z_{0.80})]^2$, the optimal sizes are $n_1 = 223.58$ older and $n_2 = 136.64$ younger adults. They round up to 224 and 137, a total of 361. Equal groups need $382/361 = 1.058$ times as many, about 6% more. The simulated Welch power at the optimal allocation was 0.800.
The saving is modest unless the standard deviations differ a great deal. It is also the reason to give a more variable group more subjects rather than fewer.
Unequal group sizes
Even with equal standard deviations, studies sometimes enroll more subjects in one group than the other. A trial may want more experience with a new treatment; one group may be cheaper to recruit; or the groups may be found rather than assigned, as in the comparison of men and women. The imbalance costs subjects: for the same standard error, a design with one group $k$ times the other needs $(1 + k)^2/(4k)$ times the balanced total.
Suppose the larger group is $k$ times the smaller, with $n$ in the smaller. The variance of the difference is $\sigma^2(1/n + 1/(kn)) = \sigma^2(1 + k)/(kn)$. Setting it equal to the variance $2\sigma^2/m$ of a balanced design with $m$ per group gives $(1 + k)/(kn) = 2/m$, so $n = m(1 + k)/(2k)$. The total, $n(1 + k)$, is
$$\frac{m(1 + k)^2}{2k} = \frac{(1 + k)^2}{4k} \times 2m,$$
the balanced total inflated by the factor $(1 + k)^2/(4k)$. The factor is 1 at $k = 1$ and exceeds 1 otherwise, since $(1 + k)^2 - 4k = (1 - k)^2$.
Example (a 2:1 trial). A 2:1 design is common in trials. Its total must be only 12.5% larger than a balanced design's, since $(1 + 2)^2/(4 \times 2) = 1.125$. The table shows how the cost grows:
| Allocation $k:1$ | 1:1 | 1.5:1 | 2:1 | 3:1 | 4:1 | 9:1 |
|---|---|---|---|---|---|---|
| Total sample ÷ balanced total | 1.000 | 1.042 | 1.125 | 1.333 | 1.563 | 2.778 |
For the trial in older adults, a 2:1 allocation by the $z$ formula needs a smaller arm of 208.16, so 209, with 418 in the larger arm, and the exact $t$ calculation confirms 209 (power 0.8004). The total, 627, is 1.124 times the balanced 558.
Mild imbalance is cheap, which is why 2:1 trials are common. But the factor grows without limit, since $(1 + k)^2/(4k) > k/4$. The smaller group's variance $\sigma^2/n$ always remains in the standard error, and adding subjects to the larger group cannot remove it.
Unequal groups cost subjects. A paired design saves them.
Paired designs need far fewer subjects
For a paired design, such as a crossover trial in which every patient receives both treatments, the comparison is a one-sample test on the differences (The Paired Samples t-Test). So the number of pairs comes from the one-sample formula with the standard deviation of the differences, $\sigma_d$, in place of $\sigma$:
$$n = \left[\frac{(z_{1-\alpha/2} + z_{1-\beta})\,\sigma_d}{\delta}\right]^2 \text{ pairs},$$
where $\delta$ is the mean difference to be detected. What is new here is the comparison with a parallel design. Suppose the two measurements on a subject each have standard deviation $\sigma$ and correlation $\rho$. The variance identity of the paired article gives $\sigma_d^2 = 2\sigma^2(1 - \rho)$, so
$$n_{\text{pairs}} = 2\left[\frac{(z_{1-\alpha/2} + z_{1-\beta})\,\sigma}{\delta}\right]^2(1 - \rho) = (1 - \rho) \times n_{\text{per group}}.$$
A paired study needs $(1 - \rho)$ times as many subjects as one arm of a parallel-group study, and so $(1 - \rho)/2$ times the parallel study's total.
- When $\rho = 0$, it needs half as many subjects, because each subject provides two measurements.
- When $\rho = 0.5$, it needs a quarter as many.
- When $\rho = 0.8$, it needs a tenth as many.
Student's sleep data show what this means in practice. The crossover trial planned in the one-sample article, for 0.5 hours at 80% power with $\sigma_d = 1.23$ hours from Student's ten differences (Student, 1908), needed 50 patients (48 by the $z$ formula).
A parallel-group trial of the same question, with each drug given to a different group, faces the variation between patients in full. The standard deviations of the two drugs' values in Student's table are 1.789 and 2.002 hours, with pooled variance $s_p^2 = 3.6048$ ($s_p = 1.899$), and
$$n = \left(\frac{1.9600 + 0.8416}{0.5}\right)^2 \times 2 \times 3.6048 = 31.396 \times 7.2096 = 226.35, \quad\text{so } 227 \text{ per group}.$$
The exact $t$ calculation gives 228 per group: 456 patients against 50, more than nine times as many. The correlation between the drugs in Student's data, 0.80, accounts for the saving: $(1 - 0.80)/2 = 0.10$, close to the actual ratio of 50 to 456, which is 0.110. Two things separate the two numbers. First, the two drugs' standard deviations are not quite equal, so $\sigma_d^2$ is not exactly $2\sigma^2(1 - \rho)$: the $z$ formulas give $47.50$ pairs against $226.35$ per group, a ratio of 0.210 where $1 - r = 0.205$. Second, the $t$ correction adds proportionally more to the small paired study (from 48 to 50) than to the large parallel one (from 227 to 228).
The saving rests on assumptions that the parallel design does not need. The crossover has to be possible at all, which requires a condition that is stable over the course of the trial, and treatments whose effects wear off between periods. And the planning value of $\rho$, or of $\sigma_d$, comes from earlier data that may be as small as Student's ten patients. When those conditions hold, pairing is the single most effective way to reduce the size of a study.
What moves the sample size
As in the one-sample case, the standard deviation and the difference to be detected enter squared and dominate. The baseline is the trial in older adults with 279 per group (80% power for 5 mm Hg, two-sided at 0.05):
| Change | Effect |
|---|---|
| One-sided test at 0.05 instead of two-sided | Power at 279 rises to 0.877; 220 per group suffice for 80% |
| $\alpha = 0.01$ instead of 0.05 | Power at 279 falls to 0.589; 80% needs 415 per group |
| True $\sigma$ 10% larger than planned | Power falls to 0.722 |
| True $\sigma$ 25% larger than planned | Power falls to 0.612 |
| True difference 2.5 mm Hg instead of 5 | Power falls to 0.289; 80% needs 1,112 per group |
| 15% of participants expected to drop out | Recruit $279/(1 - 0.15) = 328.2$, so 329 per group |
The power figures match the one-sample article's almost exactly. Both baselines were sized for 80% power, so they start from nearly the same $\lambda$. A change in $\sigma$ or in the difference rescales $\lambda$ by the same factor in both, and a change in $\alpha$ or in the number of sides moves the critical value by almost the same amount. The cautions carry over unchanged:
- the difference $\mu_1 - \mu_2$ should be the smallest one that would matter, not the one the investigators hope for;
- the planning standard deviation is itself an estimate, and a cautious, larger value protects the power;
- a one-sided test is a choice for the protocol, not for the analysis, as One-Sided Confidence Bounds and Sample Size explains;
- power is a property of the design, and computing it afterwards from the observed difference adds nothing to the $p$-value, as Power and Sample Size for a Test of a Mean showed.
Summary
| Design | Sample size for power $1 - \beta$, two-sided at $\alpha$ |
|---|---|
| One sample against a known mean | $n = [(z_{1-\alpha/2} + z_{1-\beta})\,\sigma/(\mu_1 - \mu_0)]^2$ |
| Paired (number of pairs) | $n = [(z_{1-\alpha/2} + z_{1-\beta})\,\sigma_d/\delta]^2$ |
| Two independent groups (each group) | $n = [(z_{1-\alpha/2} + z_{1-\beta})/(\mu_1 - \mu_2)]^2(\sigma_1^2 + \sigma_2^2)$ |
| Two groups, equal $\sigma$ | $n = 2[(z_{1-\alpha/2} + z_{1-\beta})\,\sigma/(\mu_1 - \mu_2)]^2$; about $16(\sigma/(\mu_1-\mu_2))^2$ for 80% power |
| Optimal allocation, unequal $\sigma$ | $n_1/n_2 = \sigma_1/\sigma_2$ |
| Allocation $k:1$, equal $\sigma$ | total inflated by $(1 + k)^2/(4k)$ |
Always round up, and check the $z$ answer against the exact $t$ power, which added one subject per group in every balanced two-group design computed in this article. The same reasoning extends to proportions, where the variance of each group depends on its own proportion, in Comparing Two Proportions.
Worked problems
These four problems are posed here, on the blood pressure populations of the unit; none is taken from the course text. Each uses one of the article's results once. The script recomputes every number.
Problem 1 (men and women). In the NHANES population, men's mean systolic pressure is 2.04 mm Hg above women's, with standard deviations 18.37 and 21.60 mm Hg (The Two-Sample t-Test). Find the number of men and of women, in equal groups, that gives a two-sided test at 0.05 an 80% chance of detecting that difference. Find also the power of the $z$ test with the 20 men and 20 women of that article.
Solution. The study needs 1,517 per group, 3,034 in all. With 20 per group the power is 0.062.
The standard deviations differ, so the formula with $\sigma_1^2 + \sigma_2^2$ applies:
$$n = \left(\frac{1.9600 + 0.8416}{2.04}\right)^2(18.37^2 + 21.60^2) = 1.8860 \times (337.46 + 466.56) = 1.8860 \times 804.02 = 1516.40,$$
which rounds up to 1,517 per group. For 20 per group, the standard error is $\sqrt{804.02/20} = 6.340$ mm Hg, so $\lambda = 2.04/6.340 = 0.3217$ and the power is
$$\Phi(0.3217 - 1.9600) + \Phi(-0.3217 - 1.9600) = \Phi(-1.6383) + \Phi(-2.2817) = 0.0507 + 0.0113 = 0.062.$$
A study of 40 people had a 6% chance of detecting the difference, barely above the 5% chance of a false alarm when there is no difference at all. Its non-significant result ($p = 0.504$) was the expected outcome. Here the wrong-direction term, 0.0113, is not negligible, because $\lambda$ is far below $z_{1-\alpha/2}$.
Problem 2 (the best allocation for the same comparison). For the comparison of Problem 1, find the allocation that reaches the same power with the fewest subjects, and the saving over equal groups.
Solution. The best allocation is 1,385 men and 1,629 women, 3,014 in all: 20 fewer than equal groups, a saving of about 0.7%.
The target standard error is set by the power: $V = [2.04/(1.9600 + 0.8416)]^2 = 0.53022$. The optimal sizes are proportional to the standard deviations, $n_1/n_2 = 18.37/21.60 = 0.8505$, and
$$n_1 = \frac{18.37 \times 39.97}{0.53022} = 1384.81, \qquad n_2 = \frac{21.60 \times 39.97}{0.53022} = 1628.30,$$
where $39.97 = 18.37 + 21.60$. Rounded up, 1,385 men and 1,629 women. The check: $18.37^2/1385 + 21.60^2/1629 = 0.53006$, which is below $V$. The totals are $(\sigma_1 + \sigma_2)^2/V = 3013.11$ before rounding against $2 \times 1516.40 = 3032.79$ for equal groups, a ratio of
$$\frac{2(\sigma_1^2 + \sigma_2^2)}{(\sigma_1 + \sigma_2)^2} = \frac{2 \times 804.02}{39.97^2} = 1.0065.$$
With standard deviations in a ratio of 1.18 the saving is under 1%. The age groups of the article, with a ratio of 1.64, saved about 6%. The gain from unequal allocation is small unless the spreads differ a great deal.
Problem 3 (a 3:1 allocation). The trial in older adults ($\sigma = 21.024$ mm Hg, a difference of 5 mm Hg, 80% power, two-sided at 0.05) is to give the new treatment to three participants for each one on usual care. Find the group sizes.
Solution. 186 on usual care and 558 on the new treatment, 744 in all, one third more than the balanced trial's 558.
The balanced $z$ answer is $m = 277.54$ per group. With $k = 3$ the smaller group needs
$$n = \frac{m(1 + k)}{2k} = \frac{277.54 \times 4}{6} = 185.03,$$
which rounds up to 186, and the larger group is $3 \times 186 = 558$. The exact calculation confirms it. With group sizes 558 and 186, the pooled statistic is noncentral $t$ with $558 + 186 - 2 = 742$ degrees of freedom and noncentrality $5/(21.024\sqrt{1/558 + 1/186})$, and the power is 0.8010; 186 is the smallest usual-care group that reaches 0.80. The total is $4 \times 186 = 744$, and $744/558 = 1.333$, the inflation factor $(1 + 3)^2/(4 \times 3) = 16/12$. The treated arm alone is as large as the whole balanced trial.
Problem 4 (a paired design on repeated readings). In the NHANES population of The Paired Samples t-Test, the first systolic reading exceeds the third by 0.786 mm Hg on average. The differences have standard deviation 5.629 mm Hg, the two readings have standard deviations 19.65 and 19.35 mm Hg, and their correlation is 0.9584. Find the number of adults a paired study needs for 80% power to detect the difference, two-sided at 0.05, and the size of a study that measured the first reading on one group and the third on another.
Solution. The paired study needs 403 adults by the $z$ formula and 405 by the exact $t$ calculation. The two-group study needs 9,663 adults per group, 19,326 in all, about 48 times as many.
For the paired design, the one-sample formula applies with $\sigma_d = 5.629$:
$$n = \left[\frac{(1.9600 + 0.8416) \times 5.629}{0.786}\right]^2 = 20.064^2 = 402.55,$$
so 403 pairs. The exact power of the paired $t$-test, from the noncentral $t$ with $n - 1$ degrees of freedom, is 0.7986 at 403 pairs, and 405 is the smallest number that reaches 0.80. That agrees with the paired article's simulation, in which samples of 400 had power 0.797.
For two independent groups,
$$n = \left(\frac{1.9600 + 0.8416}{0.786}\right)^2(19.65^2 + 19.35^2) = 12.7046 \times 760.55 = 9662.5,$$
so 9,663 per group. The ratio of pairs to subjects per group is $402.55/9662.5 = 0.0417$. It equals $\sigma_d^2/(\sigma_1^2 + \sigma_2^2) = 31.686/760.55$ exactly, because the two formulas differ only in that factor, and it is close to $1 - \rho = 0.0416$, as the variance identity predicts for nearly equal standard deviations. Blood pressure varies so much more between people than between two readings of one person that the unpaired study is larger by a factor of about 48 ($19326/403 = 48.0$ by the $z$ formulas).
What we have learned
Comparing two independent groups doubles the variance of the estimate, so each group needs twice the one-sample total: 279 per group for the older-adult trial, against 141 for one sample. The $t$ correction adds about one per group. When the standard deviations differ, groups sized in proportion to them save a little, about 6% for the age groups. Unequal allocation costs little at 2:1 and grows without limit beyond. Pairing saves the most: Student's crossover trial needs 50 patients where a parallel trial needs 456.
This closes the unit on two means. Many studies compare three or more groups: several doses, several diets, several age bands. Running a two-sample test on every pair inflates the Type I error rate, and the pooled variance needs extending to $k$ groups. The next topic, Analysis of Variance, does both, starting with One-Way Analysis of Variance.
In Python
import math
from statistics import NormalDist
from scipy import stats
def two_sample_power(d_over_sigma, n1, n2, alpha=0.05):
"""Power of the two-sided pooled two-sample t test (normal populations, common sigma)."""
df = n1 + n2 - 2
nc = d_over_sigma / math.sqrt(1 / n1 + 1 / n2)
c = stats.t.ppf(1 - alpha / 2, df)
return stats.nct.sf(c, df, nc) + stats.nct.cdf(-c, df, nc)
z = NormalDist().inv_cdf
d = 5 / 21.024
n = math.ceil(2 * ((z(0.975) + z(0.80)) / d) ** 2)
print(n, two_sample_power(d, n, n)) # 278, about 0.7993
while two_sample_power(d, n, n) < 0.80:
n += 1
print(n, two_sample_power(d, n, n)) # 279, about 0.8007
Every number in this article is computed by tools/experiments/applied-statistics/sample-size-for-comparing-two-means.py in the site's repository. The script implements the noncentral $t$ distribution directly and was checked against scipy 1.17.1.
References
- National Center for Health Statistics (2020). National Health and Nutrition Examination Survey 2017–2018: Demographic Variables and Sample Weights (DEMO_J) and Blood Pressure (BPX_J) data files. Centers for Disease Control and Prevention. https://wwwn.cdc.gov/nchs/nhanes/continuousnhanes/default.aspx?BeginYear=2017 record · 109 pages
- NIST/SEMATECH. e-Handbook of Statistical Methods, §7.2.2.2 (Sample sizes required). National Institute of Standards and Technology. https://www.itl.nist.gov/div898/handbook/ record · 37 pages
- Pagano, M., Gauvreau, K., and Mattie, H. (2022). Principles of Biostatistics (3rd ed.). CRC Press. The course text. record · 48 pages
- SciPy documentation.
scipy.stats.nct: a non-central Student's t continuous random variable. https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.nct.html record · 2 pages - Student (1908). The probable error of a mean. Biometrika, 6(1), 1–25. record · 17 pages
Reviewed: verified, 16 Nov 2026 · citations checked, 16 Nov 2026 · editorial review, 23 Nov 2026 · 6 revisions