Sample size for a 1-proportion test (exact binomial)
Sample size for a 1-proportion test is the number of units to inspect so that a 1-proportion test detects a given change in a proportion, such as a defective rate or a first-pass yield, with a chosen power. A normal approximation gives a quick answer. The exact binomial calculation is more honest for small proportions, and it shows a surprise: power does not always increase with n.
When to use it
- You want to show that a defective rate fell below a historical or contractual value after an improvement.
- You need to check whether a supplier's rate exceeds an agreed limit.
- You plan a pass/fail test, such as a leak test or a functional test, and want to know how many units give a fair chance of seeing the change.
How it works
Let p₀ be the proportion under the null hypothesis and p₁ the value you want to detect. For a one-sided test at level α, the normal approximation is
n = ( (z₁₋α √(p₀(1 − p₀)) + z₁₋β √(p₁(1 − p₁))) / (p₀ − p₁) )²For a two-sided test, use z₁₋α/₂. The approximation is poor when n·p is small, which is common with defect rates of a few percent.
Exact binomial method. The number of defectives X in n units is binomial. To show the rate dropped below p₀, reject when X ≤ c, where c is the largest count with P(X ≤ c | p₀) ≤ α. The power is P(X ≤ c | p₁). Because c can only take whole values, the actual α jumps around below the nominal value as n changes, and the power follows a sawtooth: it rises with n until c steps up, then it falls back a little. A larger n can have lower power than a smaller one.
Example
A stamping supplier has run at 5% nonconforming parts. After a die rework, the quality engineer wants to show the rate is now below 5%, with a one-sided test at α = 0.05, and wants 80% power if the true rate has dropped to 2%.
Normal approximation, with z₀.₉₅ = 1.645 and z₀.₈₀ = 0.842:
n = ( (1.645 × 0.2179 + 0.842 × 0.1400) / 0.03 )² = 252.1 → 253 partsThe exact binomial calculation tells a different story. With 253 parts the critical count is c = 6, the actual α is only 0.029, and the power is 0.755, short of the goal. The first sample size that reaches 80% is smaller: 234 parts, rejecting H₀ if 6 or fewer are nonconforming, with actual α = 0.0499 and power 0.809. Other good choices sit just after each step of c:
| n | Reject if X ≤ | Actual α | Power at p = 0.02 |
|---|---|---|---|
| 234 | 6 | 0.0499 | 0.809 |
| 253 | 6 | 0.0287 | 0.755 |
| 260 | 7 | 0.0498 | 0.847 |
| 286 | 8 | 0.0493 | 0.877 |
From 286 parts on, the power never drops below 0.80 again.
How to read the results
- Pick n just after a step. At 234 or 260 parts the exact test uses almost all of its 5% α and has more power than at 253.
- The smooth curve is an average, not a promise. The normal approximation runs through the middle of the sawtooth; at any particular n, the exact power can be several points above or below it.
- State the decision rule with the sample size. "Inspect 260 parts; conclude the rate is below 5% if 7 or fewer are nonconforming" is a complete plan anyone can audit.
- Expect large samples for small rates. Detecting a change from 5% to 2% takes hundreds of parts. Proportions carry far less information per unit than measurements, so measure a continuous characteristic when you can.
Common mistakes
- Trusting the normal formula at low rates. With n·p₀ around 12, as here, it can miss in either direction.
- Assuming more parts always mean more power. With an exact test, check the power at the n you actually choose.
- Sampling only one lot or one shift. If the rate varies between lots, the binomial model understates the variation. Spread the sample over time.
- Changing the inspection method between before and after. A new gauge or a stricter inspector changes the measured rate as much as the process does.
Frequently asked questions
Why does power go down when I add parts?
The critical count c is a whole number. Just after c steps up, the test uses nearly all of its α; as n grows with the same c, the actual α shrinks and so does the power, until c steps up again.
Should I use the exact test or the normal approximation?
For planning and for the test itself, prefer the exact binomial when n·p₀ or n·(1 − p₀) is below about 10 to 15. For large counts the two agree closely.
What if I expect zero defects?
Then you are demonstrating a maximum rate rather than testing a change. A sample with zero failures supports a rate below p with confidence C when n ≥ ln(1 − C)/ln(1 − p); for 95% confidence that the rate is under 5%, that is 59 units. See how many samples do I need.
Can I use this for yields instead of defect rates?
Yes. A yield of 95% is a defect rate of 5%; the calculation is the same with p replaced by 1 − p.