A/B Test Inference: Z-Test, Confidence Interval, and Power
Statistics & ExperimentsModel answerLast updated
Evaluate statistical significance, construct a confidence interval, calculate required sample size, and apply a multiple-comparison correction for an online experiment.
An e-commerce platform ran a one-week experiment comparing a control experience (A) against a redesigned variant (B). Group A recorded 520 purchases across 10,000 visits. Group B recorded 630 purchases across 11,500 visits. Treat each visit as an independent Bernoulli trial. You may use a calculator.
a) Test the null hypothesis that the true conversion rates are equal (pB − pA = 0) against the two-sided alternative. Compute the pooled-proportion z statistic and the corresponding two-sided p-value.
b) Construct a 95% confidence interval for the true difference pB − pA using the unpooled (Wald) standard error.
c) For planning a future study, set the baseline rate p0 equal to the observed control rate. What equal per-arm sample size n (visits per group) is needed to detect an absolute improvement of 0.7 percentage points (i.e., p1 = p0 and p2 = p0 + 0.007) with two-sided α = 0.05 and 80% power, using the normal approximation? Use z₀.₉₇₅ = 1.96 and z₀.₈₀ = 0.84. Show the formula and report n rounded up to the next whole number.
d) Suppose you are monitoring 12 independent metrics simultaneously. What per-metric significance threshold would you apply under a Bonferroni correction to keep the family-wise error rate at 0.05?
Hints
Hint 1
For the z-test, pool both groups to estimate the shared rate under H0—the standard error under the null uses this pooled estimate, not the individual group rates.
Hint 2
The confidence interval uses each group's own observed rate separately—no pooling, because the CI does not assume the null is true.
Hint 3
Sample size scales as 1/δ², so halving the detectable effect requires roughly four times the data per arm.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
What This Question Tests
Four core skills in experimental statistics:
- Running a two-proportion z-test and knowing when to pool versus not pool the standard error
- Building a confidence interval for a difference of proportions
- Computing the sample size needed to achieve a target power level
- Applying a Bonferroni correction when testing multiple metrics
Carry at least 4-5 significant digits through all intermediate steps; round only at the end.
Setup
| Purchases | Visits | Observed rate | |
|---|---|---|---|
| A (control) | 520 | 10,000 | p̂A = 0.052000 |
| B (variant) | 630 | 11,500 | p̂B = 0.054783 |
The observed difference is d̂ = p̂B − p̂A = 0.0027826, approximately +0.28 percentage points, or a 5.35% relative increase.
Part (a): Pooled Two-Proportion Z-Test
The null hypothesis states that both groups share one common conversion rate. Estimate that common rate by combining all observations:
p̂ = (520 + 630) / (10,000 + 11,500) = 1,150 / 21,500 = 0.053488
The pooled standard error under H0 is:
SE₀ = √[ p̂(1 − p̂) · (1/nA + 1/nB) ]
Computing each piece:
- p̂(1 − p̂) = 0.053488 × 0.946512 = 0.050627
- 1/10,000 + 1/11,500 = 0.00018696
- Variance = 0.050627 × 0.00018696 = 9.4651 × 10⁻⁶
- SE₀ = 0.0030766
z = 0.0027826 / 0.0030766 = 0.904
Two-sided p-value = 2 × (1 − Φ(0.904)) ≈ 2 × (1 − 0.8171) ≈ 0.366
We fail to reject H0 at α = 0.05. The observed lift is well within what random noise alone would produce.
Pooling is the correct choice here because the test statistic is evaluated under the null, and the null assumes both rates are identical. The combined estimate gives the best single estimate of that shared rate.
Part (b): 95% Confidence Interval (Unpooled SE)
A confidence interval does not impose the null hypothesis, so each group keeps its own variance:
SE = √[ p̂A(1 − p̂A)/nA + p̂B(1 − p̂B)/nB ]
- Group A variance: 0.052 × 0.948 / 10,000 = 4.9296 × 10⁻⁶
- Group B variance: 0.054783 × 0.945217 / 11,500 = 4.5027 × 10⁻⁶
- Total = 9.4323 × 10⁻⁶, SE = 0.0030712
Margin = 1.96 × 0.0030712 = 0.0060196
95% CI: 0.0027826 ± 0.0060196 = (−0.00324, +0.00880)
Roughly −0.32 pp to +0.88 pp. The interval includes 0, which agrees with part (a). It also shows the data cannot distinguish "B is slightly worse" from "B is almost 1 pp better"—a precision problem that part (c) quantifies.
Part (c): Sample Size Per Arm
Given p1 = 0.052, p2 = 0.059, and δ = 0.007. The normal-approximation formula with unpooled variances is:
n = (z₁₋α/₂ + z₁₋β)² · [p1(1 − p1) + p2(1 − p2)] / δ²
Computing:
- p1(1 − p1) = 0.052 × 0.948 = 0.049296
- p2(1 − p2) = 0.059 × 0.941 = 0.055519
- Sum = 0.104815
- (1.96 + 0.84)² = 2.8² = 7.84
- Numerator = 7.84 × 0.104815 = 0.821750
- δ² = 0.000049
n = 0.821750 / 0.000049 = 16,770.4 → n = 16,771 visits per arm (always round up).
An alternative formula uses the pooled variance under H0 for the α term:
n = [z₁₋α/₂·√(2p̄(1 − p̄)) + z₁₋β·√(p1q1 + p2q2)]² / δ², where p̄ = (p1 + p2)/2 = 0.0555
This yields n ≈ 16,774, only a few sessions different. Either approach is acceptable if the formula is stated.
The current experiment has 10,000 and 11,500 visits per arm—well below the ~16,771 needed to reliably detect a 0.7 pp difference. The non-significant result in (a) is therefore inconclusive, not proof of no effect. Because n scales as 1/δ², detecting the observed 0.28 pp difference would require roughly 6× more data.
Part (d): Bonferroni Correction
With m = 12 metrics, to maintain family-wise error rate at 0.05:
α_per-metric = 0.05 / 12 ≈ 0.00417
The two-sided critical z rises from 1.96 to about 2.86, meaning each metric requires more traffic to reach significance. Bonferroni is conservative—it controls FWER regardless of dependence among tests. Holm–Bonferroni offers the same guarantee with more power, and Benjamini–Hochberg is the standard choice when controlling false discovery rate rather than FWER.
Common Pitfalls
- Using the pooled SE for the CI or the unpooled SE for the test. Pooling belongs under H0; unpooled belongs to the CI.
- Rounding p̂B to 0.055 early, which inflates the difference and shifts z to about 0.97.
- Forgetting to double the one-sided tail for a two-sided p-value.
- Reporting total sample size instead of per-arm, or rounding n down.
- Confusing absolute lift (0.7 pp) with relative lift (~13.5% on a 5.2% baseline).
- Concluding "no effect" rather than "underpowered."
Python Verification
from math import sqrt, ceil
from scipy.stats import norm
xA, nA, xB, nB = 520, 10_000, 630, 11_500
pA, pB = xA / nA, xB / nB
d = pB - pA
# (a) pooled z-test
p_pool = (xA + xB) / (nA + nB)
se0 = sqrt(p_pool * (1 - p_pool) * (1 / nA + 1 / nB))
z = d / se0
pval = 2 * (1 - norm.cdf(abs(z)))
# (b) unpooled 95% CI
se = sqrt(pA * (1 - pA) / nA + pB * (1 - pB) / nB)
ci = (d - 1.96 * se, d + 1.96 * se)
# (c) per-arm sample size
p1, p2, delta = pA, pA + 0.007, 0.007
n = ceil((1.96 + 0.84) ** 2 * (p1 * (1 - p1) + p2 * (1 - p2)) / delta ** 2)
# (d) Bonferroni
alpha_bonf = 0.05 / 12
print(f"z={z:.4f}, p={pval:.4f}")
print(f"CI=({ci[0]:.5f}, {ci[1]:.5f})")
print(f"n per arm={n}")
print(f"alpha={alpha_bonf:.5f}")
Summary of Results
- (a) z ≈ 0.904, p ≈ 0.366
- (b) 95% CI ≈ (−0.00324, +0.00880), i.e. (−0.32 pp, +0.88 pp)
- (c) n = 16,771 per arm
- (d) α ≈ 0.00417