Compare Two Proportions with Unequal, Clustered Samples
Statistics & ExperimentsModel answerLast updated
Construct and interpret a confidence interval for the difference in conversion rates when observations are clustered within groups, not independently drawn.
Setting
A product team runs a study across 40 retail stores. Half the stores (20) receive a redesigned checkout flow; the other half keep the original. Every customer who visits a store during the two-week window is tracked.
Summary data:
| Group | Stores | Total customers | Conversions |
|---|---|---|---|
| Treatment | 20 | 8 400 | 1 092 |
| Control | 20 | 6 000 | 660 |
A junior analyst computes a standard two-proportion z-interval for the difference in conversion rates and reports:
"The 95% CI for the lift is [+0.6 pp, +3.4 pp], p < 0.05. We should ship."
You are asked to review this analysis in a technical interview setting.
What is expected
- Identify the flaw in the analyst's approach and explain precisely why it matters here.
- Describe the correct method for constructing a confidence interval that accounts for the data structure. Be specific about the estimator and the variance formula you would use.
- Walk through the calculation using the cluster-level data below, and produce a corrected 95% CI. Show every step.
- Interpret the result and make a shipping recommendation with appropriate caveats.
Cluster-level conversion rates (store means)
Use these per-store rates to do your calculation. Assume the analyst computed them correctly.
Treatment stores (n = 20):
Mean store rate p̄_T = 0.1310, sample variance of store rates s²_T = 0.000784
Control stores (n = 20):
Mean store rate p̄_C = 0.1105, sample variance of store rates s²_C = 0.000625
(You do not need to recompute these from raw data.)
Hints
Hint 1
The standard two-proportion z-test assumes every observation is independent. Ask yourself: are two customers in the same store really independent? What does this violation do to the standard error?
Hint 2
The correct approach treats each store as one unit of observation. With 20 stores per arm, you have 20 independent data points per group, not 8,400 vs. 6,000. Build your CI around the distribution of store-level means.
Hint 3
For two independent groups with small, equal n, use the two-sample t-interval. The SE of the difference is sqrt(s²_T/n_T + s²_C/n_C). Degrees of freedom: n_T + n_C - 2 = 38, or use Welch if variances differ substantially.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Step 1 — Identify the Flaw
The analyst treats all 14,400 customers as independent Bernoulli trials. They are not. Customers within the same store share the same physical environment, staff, local promotions, and customer demographics. This intra-cluster correlation (ICC) means each additional customer from an already-observed store carries less new information than an independent draw would.
Ignoring clustering underestimates the true standard error. The effective sample size is much smaller than 14,400. The standard two-proportion z-interval is therefore too narrow, the z-statistic is inflated, and the reported p-value is anti-conservative. In the worst cases, studies like this produce false positives purely from this mistake.
The design unit is the store, not the customer. Randomization happened at the store level; inference must happen at the store level too.
Step 2 — The Correct Method: Cluster-Robust / Store-Level t-Interval
Because randomization is at the store level and we have 20 stores per arm, we treat each store's conversion rate as one observation. We then apply a standard two-sample t-interval on those 20 + 20 store-level proportions.
Estimator for the difference:
$$\hat{\delta} = \bar{p}_T - \bar{p}_C$$
Standard error of the difference (unpooled / Welch form):
$$SE = \sqrt{\frac{s^2_T}{n_T} + \frac{s^2_C}{n_C}}$$
Degrees of freedom (Welch–Satterthwaite):
$$\nu = \frac{\left(\frac{s^2_T}{n_T} + \frac{s^2_C}{n_C}\right)^2}{\frac{(s^2_T/n_T)^2}{n_T - 1} + \frac{(s^2_C/n_C)^2}{n_C - 1}}$$
We use the Welch form rather than pooled because there is no strong reason to assume the two arms have the same variance of store rates, and Welch is robust when they do differ.
Step 3 — Numerical Calculation
Given:
- p̄_T = 0.1310, s²_T = 0.000784, n_T = 20
- p̄_C = 0.1105, s²_C = 0.000625, n_C = 20
Point estimate:
$$\hat{\delta} = 0.1310 - 0.1105 = 0.0205 \quad (+2.05 \text{ pp})$$
Variance components:
$$\frac{s^2_T}{n_T} = \frac{0.000784}{20} = 0.0000392$$
$$\frac{s^2_C}{n_C} = \frac{0.000625}{20} = 0.00003125$$
Standard error:
$$SE = \sqrt{0.0000392 + 0.00003125} = \sqrt{0.00007045} \approx 0.008393$$
Welch degrees of freedom:
Numerator: $(0.0000392 + 0.00003125)^2 = (0.00007045)^2 = 4.963 \times 10^{-9}$
Denominator: $$\frac{(0.0000392)^2}{19} + \frac{(0.00003125)^2}{19} = \frac{1.537 \times 10^{-9}}{19} + \frac{9.766 \times 10^{-10}}{19}$$ $$= 8.089 \times 10^{-11} + 5.140 \times 10^{-11} = 1.323 \times 10^{-10}$$
$$\nu = \frac{4.963 \times 10^{-9}}{1.323 \times 10^{-10}} \approx 37.5 \rightarrow \text{use } \nu = 37$$
Critical value: t*(0.025, 37) ≈ 2.026
95% CI:
$$0.0205 \pm 2.026 \times 0.008393 = 0.0205 \pm 0.01701$$
$$\boxed{[+0.33 \text{ pp},\ +3.75 \text{ pp}]}$$
Step 4 — Interpretation and Recommendation
The corrected CI is [+0.33 pp, +3.75 pp], compared to the analyst's [+0.6 pp, +3.4 pp].
Key observations:
- The point estimate is the same (+2.05 pp). The means are unaffected by the correction.
- The interval is wider because the true SE (~0.84 pp) is larger than the naive SE the analyst used.
- The lower bound (+0.33 pp) is still above zero, so the result remains nominally significant — but only barely, and with a much weaker margin.
- With only 20 clusters per arm, the t-test has limited power. The result is directionally positive but the precision is low.
Recommendation: The result is encouraging but not conclusive enough to ship globally on its own. I would:
- Not over-index on statistical significance given the wide CI and small cluster count.
- Ask whether +0.33 pp is the minimum detectable effect worth shipping — if the business requires at least +1 pp to justify implementation costs, the CI does not rule out effects below that threshold.
- Recommend a follow-up experiment with more stores or a longer window to tighten the CI.
- Investigate store-level heterogeneity (the ICC and variance components) — if a few outlier stores drive the effect, the result may not generalize.
Common Mistakes to Avoid
- Ignoring clustering entirely — the most common error; inflates sample size by 100–500x in typical retail studies.
- Switching to a mixed model but forgetting to report a marginal CI — random-effects models are valid but the CI must still be interpreted at the population level.
- Using a pooled t-test when variances clearly differ — check the ratio s²_T / s²_C = 0.000784 / 0.000625 ≈ 1.25; mild here, but Welch is still the safer default.
- Confusing statistical significance with practical significance — the lower bound of +0.33 pp may be economically trivial depending on margin and traffic.