Understanding the two-proportion z-test — concept and principle
A two-proportion z-test checks whether two groups have different success rates: conversion rates in an A/B test, defect rates on two machines, or response rates to two survey invitations. You enter the number of successes and the total for each group, and the calculator returns the z statistic, a two-tailed p-value and the difference between the rates.
How it is calculated
- Sample proportions: p̂₁ = x₁ ÷ n₁ and p̂₂ = x₂ ÷ n₂.
- Pooled proportion under H₀ (equal rates): p̂ = (x₁ + x₂) ÷ (n₁ + n₂).
- Standard error: SE = √[p̂(1 − p̂)(1/n₁ + 1/n₂)].
- z = (p̂₁ − p̂₂) ÷ SE.
- Two-tailed p = 2 × [1 − Φ(|z|)], where Φ is the standard normal cumulative distribution.
- Difference = (p̂₁ − p̂₂) × 100, in percentage points (A minus B).
Both z and the difference are A minus B, so they always share the same sign: a negative value means group B has the higher rate.
The principle
If both groups truly share one rate, the best estimate of that rate combines all the data, which is why the standard error uses the pooled p̂. With reasonably large samples the difference between two proportions is approximately normal, so z measures how many standard errors apart the two rates are. This test is mathematically equivalent to the chi-square test on the 2 × 2 table: z² equals the uncorrected chi-square statistic.
Worked example
- A: 120 successes of 1,000 (p̂₁ = 0.12). B: 150 of 1,000 (p̂₂ = 0.15).
- Pooled p̂ = 270 ÷ 2,000 = 0.135.
- SE = √(0.135 × 0.865 × 0.002) = √0.00023355 = 0.0152823.
- z = (0.12 − 0.15) ÷ 0.0152823 = −1.963049808.
- p = 2 × (1 − Φ(1.96305)) = 0.0496403869.
- Difference A − B = (0.12 − 0.15) × 100 = −3 percentage points, i.e. B is 3 points higher.
| Total B | z |
|---|---|
| 250 | -16.49572198 |
| 500 | -8.553989228 |
| 750 | -4.584868703 |
| 1,000 | -1.963049808 |
| 1,250 | 0 |
| 1,500 | 1.578379079 |
| 2,000 | 4.059989715 |
How to read the result
|z| = 1.96 is the 5% two-tailed threshold, and this result sits just beyond it: p ≈ 0.0496, barely below 0.05. B's rate is 3 points higher, a relative lift of 25% (0.03 ÷ 0.12). A result this close to the cut-off is fragile: a few more or fewer successes would flip the conclusion, so look at the confidence interval for the difference and at practical importance, not only at "significant".
Common mistakes
- Stopping an A/B test as soon as p drops below 0.05; repeated peeking inflates false positives.
- Confusing percentage points (3) with relative change (25%).
- Using the test with very small counts; expect at least about 5 to 10 successes and failures in each group.
Frequently asked questions
Should I use a one-tailed test because I expected B to win?
Only if that was decided before collecting data and a result in the other direction would be treated as "no effect"; otherwise use two tails.
Why use the pooled proportion?
Because the test assumes H₀ is true; confidence intervals for the difference use the unpooled standard error instead.
What about small samples?
Fisher's exact test is the usual alternative when expected counts are small.
Sources: Agresti, A. (2013). Categorical Data Analysis (3rd ed.). Wiley. · NIST/SEMATECH e-Handbook of Statistical Methods.