Sample size for a 2-sample t test: how many per group
Sample size for a 2-sample t test is the number of units to take from each of two groups so that a 2-sample t test detects a given difference between their means with a chosen power. It depends on the significance level, the power, the difference that matters and the standard deviation within each group. The exact answer uses the noncentral t distribution; a normal approximation gets you within a unit or two.
When to use it
- You plan to compare two suppliers, machines, materials or methods on a measured characteristic.
- The units in the two groups are different (independent). If the same units are measured twice, plan a paired t test instead, which usually needs far fewer.
- You want to know whether a proposed sample size can detect a difference that matters, before you spend the parts.
How it works
With n units per group, a common standard deviation σ and a true difference δ, the pooled t statistic follows a noncentral t distribution with 2n − 2 degrees of freedom and noncentrality
λ = δ / (σ √(2/n))The two-sided power is P(T′ > t₁₋α/₂, 2n−2) + P(T′ < −t₁₋α/₂, 2n−2). Increase n until the power reaches the target.
A normal approximation gives a starting point:
n per group ≈ 2 ( (z₁₋α/₂ + z₁₋β) σ / δ )²Adding z²₁₋α/₂ / 4 (Guenther's correction) usually hits the exact answer. For α = 0.05 and 80% power, the approximation reduces to a handy rule: n per group ≈ 16 / (δ/σ)². For 90% power, use 21 instead of 16.
Equal group sizes give the most power for a fixed total. If one group is cheaper to sample, unequal sizes are fine; the power depends on 1/n₁ + 1/n₂.
Example
A forge buys bar stock from two mills and wants to know whether their tensile strengths differ. From past certificates, σ ≈ 4 MPa within each mill. A difference of 3 MPa or more would change which grade the forge orders. The plan: a two-sided test at α = 0.05 with 90% power (δ/σ = 0.75).
- Normal approximation: 2 × ((1.960 + 1.282) × 4 / 3)² = 37.36, so 38 bars per mill. The exact power with 38 is 0.897, just short.
- With Guenther's correction: 37.36 + 1.960²/4 = 38.32, so 39.
- Exact noncentral t: 39 bars per mill give power 0.905. That is 78 tensile tests in all.
Simulation check: 200,000 pairs of samples of 39 bars, with means 3 MPa apart and σ = 4 MPa (NumPy, seed 7), tested with the pooled t test, rejected in 90.5% of the pairs.
How to read the results
- Each curve is one sample size. Find the difference that matters on the horizontal axis and read the chance of detecting it.
- Small samples only find large differences. With 10 bars per mill, a 3 MPa difference is detected only 36% of the time; you would most likely conclude "no difference" even though one exists.
- The quick rule is close. 21 / 0.75² = 37.3, near the normal approximation; the exact answer adds about one unit.
- Total cost is 2n. If 78 tests are too many, you can accept 80% power (29 per group by the same method, power 0.801) or a larger δ, but write down that choice.
Common mistakes
- Planning with the standard deviation of the difference of two means. σ here is the spread of individual units within one group.
- Ignoring between-lot variation. If each mill's bars come from several heats, sample across heats and plan with a σ that includes heat-to-heat variation.
- Testing whatever is on the shelf. Ten bars from one heat per mill compare two heats, not two mills.
- Assuming equal variances when one group is much more variable. Use the Welch version of the test, and plan with the larger σ or by simulation.
Frequently asked questions
Is n the total or per group?
Per group. A 2-sample study with n = 39 needs 78 units.
What if I only know the difference as a percentage?
Convert both the difference and σ to the same units, or work directly with the ratio δ/σ. Only that ratio enters the calculation.
Does the Welch test need a different sample size?
With equal group sizes and equal variances, the Welch and pooled tests have almost the same power. With unequal variances, put more units in the more variable group.
Why is a paired design so much cheaper?
Pairing removes the unit-to-unit variation from the comparison. See sample size for a paired t test for a worked comparison.