A/B Test Planning: Power, CUPED, Peeking, SRM and Causal Checks
Statistics & ExperimentsModel answerLast updated
Plan an online experiment end to end: sample size, runtime, variance reduction, sequential monitoring, cluster randomization, an SRM diagnosis, and a causal design for observational data.
You are the data scientist responsible for a conversion experiment. Answer each part with formulas, numeric results and explicit assumptions.
A. Sample size. The baseline conversion rate is p0 = 0.045. You want to detect a 7% relative lift, so p1 = 0.045 × 1.07. Use a two-sided test with alpha = 0.05 and power = 0.90. Compute the per-variant sample size for a two-proportion z-test. State the z-values and explain how you treat the variance (pooled vs. unpooled). Then say how the answer changes if traffic is split 60/40.
B. Runtime. There are 1.2M daily visitors, 80% are eligible, and traffic is split 60/40 between A and B. How many calendar days are needed to reach the sample size from A? Discuss adjustments for repeat visitors and for other experiments competing for the same traffic.
C. Variance reduction. A pre-experiment covariate has R² = 0.20 with the outcome. Quantify the gain from CUPED, as a sample-size reduction and as an MDE reduction. When can CUPED introduce bias or stop helping?
D. Sequential monitoring. Stakeholders want to look at the results every day for 21 days. Propose an alpha-spending or group-sequential design, name the spending function, and give the approximate final critical z. Compare it with always-valid methods such as mSPRT or e-values.
E. Interference. User-level randomization is contaminated by spillovers between users. Propose a cluster-randomized design. Compute the design effect for ICC = 0.02 with average cluster sizes m = 5 and m = 50, and explain how the required sample size changes.
F. Sample ratio mismatch. The plan was a 60/40 split of 200,000 eligible users. On day 3 you see 110,000 users in A and 90,000 in B. Run a chi-square goodness-of-fit test, report the p-value, and describe what you do if the SRM is real.
G. Observational causal inference. A team analysed observational data with a strong pre-period trend. Sketch a DAG, pick an identification strategy (DID, IV or RDD), list its required assumptions, and propose concrete robustness checks.
Hints
Hint 1
For A, use pooled variance 2·p̄·q̄ under H0 and p0q0 + p1q1 under H1, with z = 1.96 and 1.2816. For an unequal split, hold Var(diff) fixed, so 1/nA + 1/nB must equal 2/n.
Hint 2
For B, the raw arithmetic gives a fraction of a day, so think about what actually limits enrollment: unique users rather than visits, the traffic slice your experiment owns, and weekly seasonality.
Hint 3
For F, the expected counts are 120,000 and 80,000, and the test has one degree of freedom. The statistic is huge, so the p-value is effectively zero. Focus on what you do next, not on the exact digits.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
A. Sample size
Inputs: p0 = 0.045, p1 = 0.04815, Δ = 0.00315, z(1−α/2) = 1.960, z(1−β) = 1.2816.
Use the pooled variance under H0 (both arms share p̄ = 0.046575) and the unpooled variance under H1:
n = [1.960·√(2p̄q̄) + 1.2816·√(p0q0 + p1q1)]² / Δ²
Here √(2p̄q̄) ≈ 0.2980 and √(p0q0 + p1q1) ≈ 0.2980, so
n = (0.5841 + 0.3819)² / 9.92×10⁻⁶ ≈ 94,050 per arm (about 188,100 total).
The two variance forms nearly coincide because p0 and p1 are close.
For a 60/40 split, require 1/nA + 1/nB = 2/n. This gives N_total ≈ 2.083 × 94,046 ≈ 195,900, with nA ≈ 117,560 and nB ≈ 78,370. The unbalanced split costs about 4% more total traffic.
B. Runtime
Eligible traffic is 1.2M × 0.8 = 960k/day, and B receives 384k/day. Naively, 78,370 / 384k ≈ 0.2 days, which is misleading.
- Repeat visitors. Randomization is by user, so what counts is cumulative unique users U(d), not visits. Solve for the smallest d with 0.32·U(d) ≥ 78,370 using historical data. Also fix a per-user outcome window (for example 7 days after first exposure) so late joiners are measured like early ones.
- Other experiments. If this test owns only a slice of traffic, scale accordingly. With a 5% slice, B gets 19.2k/day and needs about 4.1 days. Orthogonal layers do not shrink the slice, but they assume no interaction effects.
- Recommendation. Run at least 14 days, two full weekly cycles, to cover day-of-week effects and novelty or primacy effects, even if the numeric threshold is reached sooner.
C. CUPED
With Y_cv = Y − θ(X − X̄) and θ = Cov(X,Y)/Var(X), the variance becomes Var(Y)(1 − R²) = 0.8·Var(Y).
- Required sample size falls 20%: about 75,240 per arm (roughly 156,700 total at 60/40).
- At fixed n, the MDE shrinks by √0.8 ≈ 0.894, from 7% to about 6.26% relative.
CUPED stays unbiased under proper randomization, but it can fail or mislead when:
- X is measured after exposure, so it absorbs part of the treatment effect. Only strictly pre-period covariates are valid.
- Arms are imbalanced on X (for example from SRM, differential bot filtering or behavior-dependent triggering).
- θ is fitted separately per arm or tuned on the same small sample. Estimate it on pooled data.
- Users have no history. Impute consistently in both arms, for example X = 0 plus an indicator.
- The pre/post relationship drifts, so the realized R² is lower than 0.20. A 0.20 figure is optimistic for a binary outcome, so check it against A/A data.
D. Sequential testing
Use a Lan–DeMets O'Brien–Fleming-type spending function, α(t) = 2 − 2Φ(z₀.₉₇₅/√t), where t is the information fraction, with 21 equally spaced looks.
- Early boundaries are extreme (around 9 at day 1), so almost no alpha is spent early.
- The final critical z is only slightly above 1.96, about 2.0–2.06. Compute exact values with
gsDesignorrpact. - The maximum sample size inflates only a few percent.
Pocock uses a constant boundary near 2.7 for 21 looks. It stops early more readily on big effects but needs a much larger maximum sample (often 30% or more) and makes the final analysis stricter. It is a poor fit when effects are small.
Group-sequential pros: exact alpha control, near fixed-horizon power, simple to explain. Cons: the schedule and N_max must be pre-registered, unplanned peeks break the guarantee, and estimates at early stops are biased upward.
Always-valid methods (mSPRT, e-values, confidence sequences) allow continuous monitoring and optional stopping with no fixed horizon. The cost is lower power at a given horizon, dependence on the mixing prior, and harder communication. Use them for live dashboards, and use group-sequential designs for the formal decision.
E. Cluster randomization
Randomize at a level that contains the spillover: social or graph components, geo regions, or traffic buckets. Design effect: DE = 1 + (m − 1)·ICC.
| m | DE | Users per arm | Clusters per arm |
|---|---|---|---|
| 5 | 1.08 | ≈ 101,570 | ≈ 20,300 |
| 50 | 1.98 | ≈ 186,210 | ≈ 3,720 |
Apply the 60/40 inflation of about 4% on top. For unequal cluster sizes, use DE ≈ 1 + [(1 + CV²)m − 1]·ICC. Analyze with cluster-robust standard errors, or randomization inference when clusters are few. Larger clusters reduce bias from interference but cost power. Comparing user-level and cluster-level estimates helps diagnose interference.
F. SRM
Expected counts are A = 120,000 and B = 80,000. Then
χ² = (−10,000)²/120,000 + (10,000)²/80,000 = 833.3 + 1,250 = 2,083.3 (df = 1).
Since z = √χ² ≈ 45.6, the p-value is on the order of 10⁻⁴⁵³, effectively zero. The observed split is 55/45, not 60/40.
Actions:
- Treat the results as invalid and do not report the metric lift.
- Locate the cause: assignment code or hashing, ramp configuration, logging or exposure-event loss, redirects, bot filtering, caching, or triggering that depends on treatment.
- Break the counts down by platform, browser, country and day to find where the mismatch concentrates.
- Fix the cause and restart, or re-run with a corrected pipeline. Do not "reweight" the data away.
G. Causal inference with a pre-trend
Sketch of the DAG: unobserved confounders U affect both treatment adoption T and outcome Y. Pre-period outcome Y_pre and covariates X affect T and Y, and time affects Y in both groups.
With panel data and a pre-period trend, choose difference-in-differences (preferably an event-study version).
Assumptions:
- Parallel trends in the absence of treatment (after conditioning on covariates).
- No anticipation effects.
- No spillover to the control group (SUTVA).
- Stable group composition.
Robustness checks:
- Event-study plots with leads near zero.
- Placebo treatment dates and placebo outcomes.
- Group-specific linear trends, or synthetic control or matching on pre-trends, if the trend differs.
- Alternative control groups.
- Sensitivity analyses for unobserved confounding (for example Rosenbaum bounds or the E-value, or bounding departures from parallel trends).
Choose IV only if there is a credible instrument satisfying relevance and the exclusion restriction. Choose RDD only if there is a sharp assignment cutoff with continuity of potential outcomes and no manipulation of the running variable (check with a density test).
Common mistakes
- Using a single arm's n for an unbalanced split.
- Counting visits instead of unique users.
- Peeking daily with a fixed-horizon test.
- Using a post-exposure covariate in CUPED.
- Reading results despite a significant SRM.
- Assuming parallel trends without testing them.