2 proportions test: compare two defect rates, with example
The 2 proportions test checks whether two groups have different rates of some pass/fail outcome: defective or good, failed or passed, returned or kept. It compares the two sample proportions p̂₁ = x₁/n₁ and p̂₂ = x₂/n₂ and gives a p-value and a confidence interval for the difference. With large counts it uses a normal (z) approximation; with small counts, Fisher's exact test is the safer choice.
When to use it
- Comparing the defect rate before and after a process change, such as a new fixture, tool or supplier.
- Comparing first-pass yield on two lines, two shifts or two product versions.
- Comparing the share of units that fail a reliability test under two designs.
- For counts of defects per unit (several defects can occur on one unit) instead of defective units, use the 2-sample Poisson rate test. For more than two groups, use cross tabulation and chi-square.
How it works
Hypotheses, with p₁ and p₂ the true proportions:
- H₀: p₁ = p₂ (no difference).
- H₁: p₁ ≠ p₂, or p₁ > p₂, or p₁ < p₂.
The z test uses the pooled proportion p̂ = (x₁ + x₂)/(n₁ + n₂), because under H₀ both groups share one rate:
z = (p̂₁ − p̂₂) / √( p̂(1 − p̂)(1/n₁ + 1/n₂) )The p-value comes from the standard normal distribution. The confidence interval for the difference uses each group's own proportion, since it does not assume H₀ is true:
(p̂₁ − p̂₂) ± z(1 − α/2) · √( p̂₁(1 − p̂₁)/n₁ + p̂₂(1 − p̂₂)/n₂ )Fisher's exact test takes the 2×2 table of defective and good units with its row and column totals fixed, and computes the probability of every possible table from the hypergeometric distribution. The two-sided p-value used here adds the probabilities of all tables no more likely than the observed one. It is valid for any sample size, and it is the test to use when any expected count (row total × column total / grand total) is below about 5.
Assumptions: units are independent, and each group's units share one underlying rate.
Example
An electronics plant tests every assembled controller board at a functional test station. Many failures turn out to be false calls caused by worn spring contacts in the test fixture. The test engineer rebuilds the fixture with new contacts and compares a week before with a week after:
| Period | Boards tested | Failed | Fail rate |
|---|---|---|---|
| Before the rebuild | 860 | 41 | 4.77% |
| After the rebuild | 815 | 20 | 2.45% |
Test H₀: p_before = p_after, two-sided, α = 0.05:
- Difference: 0.0477 − 0.0245 = 0.0231 (2.31 percentage points).
- Pooled proportion: 61/1675 = 0.0364.
- Standard error under H₀: √(0.0364 × 0.9636 × (1/860 + 1/815)) = 0.00916.
- z = 0.0231/0.00916 = 2.53, p-value = 0.012.
- 95% CI for the difference: 0.0231 ± 1.960 × 0.00906 = 0.0054 to 0.0409, that is 0.5 to 4.1 percentage points.
- Fisher's exact test, two-sided: p = 0.013.
The expected counts of failures are about 31 and 30, so the normal approximation is reliable here, and the two tests agree.
How to read the results
- The p-value of 0.012 says the drop in the fail rate is unlikely to be chance. The fixture rebuild worked.
- The interval says the rebuild cut the fail rate by somewhere between 0.5 and 4.1 percentage points. At about 850 boards a week, that is roughly 5 to 35 fewer boards a week sent to troubleshooting.
- Look at what remains. A 2.45% fail rate is still high if many of those are false calls too. Retest the failed boards to split real defects from fixture problems, and track the rate on a P chart to see whether it holds.
- Check the comparison is fair. A before/after study assumes nothing else changed that week, such as the product mix or a component lot. If something did, the difference may not belong to the fixture.
Common mistakes
- Using the z test with small counts. With only a handful of failures in a group, use Fisher's exact test.
- Comparing percentages without the sample sizes. 2 of 20 and 200 of 2,000 are both 10%, but they carry very different amounts of evidence.
- Counting defects instead of defective units. If one board can have several defects, the counts are not binomial; use a Poisson rate test.
- Ignoring time. If the rate was drifting down before the change, a before/after test credits the change for the drift. Plot the rate over time first.
Frequently asked questions
Why does the test use a pooled proportion but the interval does not?
The test asks what the data would look like if H₀ were true, and under H₀ both groups share one rate, best estimated by pooling. The interval estimates the actual difference, so it uses each group's own rate.
When should I use Fisher's exact test?
When any expected count in the 2×2 table is below about 5, which happens with small samples or very low defect rates. It is valid for large samples too, but there it gives nearly the same answer as the z test.
Is the 2 proportions test the same as a chi-square test?
For a 2×2 table, the Pearson chi-square statistic equals z², and the two-sided p-values match. The chi-square test extends to more groups and more categories.
How many units do I need?
Detecting a change from 4.8% to 2.5% takes several hundred units per group; detecting smaller changes takes thousands. See sample size for 2 proportions.