Covariate Adjustment in Experiments

Python · NumPy · statsmodels  ·  R · estimatr

Precision, Not Bias

Randomization already delivers an unbiased effect from a plain difference in means, so adjusting for covariates cannot be about removing bias — there is none to remove. It is about precision. A pre-treatment variable that predicts the outcome absorbs variation that has nothing to do with the treatment, shrinking the standard error without changing what the estimate targets. That is the everyday workhorse of modern experimentation, and it carries different names in different fields: ANCOVA (analysis of covariance) in clinical trials, CUPED (Controlled-experiment Using Pre-Existing Data, Deng et al. 2013) in online A/B testing. They are the same estimator, and it is worth knowing that, because the two literatures rediscovered it independently and still largely cite each other's results as novel.

Two real experiments bracket the phenomenon deliberately. The Electric Company (1971) randomized 192 classrooms across grades 1–4, 96 treated and 96 control, to watch an educational television programme or not, with reading measured before and after. Its pre-test correlates with the post-test at 0.883 — close to the best case adjustment can hope for. Social Pressure GOTV (Gerber, Green & Larimer 2008) mailed get-out-the-vote messages to 305,866 voters, and its only baseline covariate — whether the person voted in the 2004 primary — correlates with 2006 turnout at just 0.163. One near-ideal, one nearly useless, on purpose.

ANCOVA on a Strong Baseline

Yi=α+τTi+βXi+εiY_i = \alpha + \tau\,T_i + \beta\,X_i + \varepsilon_i

On the Electric Company the unadjusted difference is +5.66 points with a standard error of 2.537. Adding the pre-test moves the point estimate to +4.73 and the standard error to 1.169 — the estimate barely moves, as randomization guarantees, while the standard error is cut by 54% and the sampling variance by 79%. A bootstrap agrees independently: 2.47 unadjusted against 1.15 adjusted, about 2.1× more precise for the same target. The confidence interval narrows from a width of 9.94 to 4.58.

The small movement in the point estimate is worth naming rather than waving past, because it is the second thing adjustment does. Randomization balances covariates in expectation, not in any particular sample, and this sample has a slight pre-test imbalance across grades. Adjustment removes that chance imbalance too. So the shift from +5.66 to +4.73 is not evidence of bias being introduced; it is evidence of a lucky draw being corrected.

The Electric Company, 192 classroomseffectSECI width
unadjusted difference in means+5.662.5379.94
ANCOVA (adjust for pre-test)+4.731.1694.58
Lin (centred, interacted)+4.731.157
standard error cut 54% · sampling variance cut 79% · bootstrap SD 2.47 → 1.15

CUPED and the ρ² Law

CUPED is the same thing arrived at from a different direction. Rather than regressing the outcome on treatment and covariate, replace the outcome with an adjusted version and take a plain difference in means. Because θ\theta is exactly the regression slope, the two estimators coincide — and the variance reduction has a closed form that makes the whole subject predictable in advance.

Yicuped=Yiθ(XiXˉ),θ=Cov(Y,X)Var(X),1Var(τ^cuped)Var(τ^)ρ2Y_i^{\text{cuped}} = Y_i - \theta\,(X_i - \bar X), \qquad \theta = \frac{\operatorname{Cov}(Y,X)}{\operatorname{Var}(X)}, \qquad 1 - \frac{\operatorname{Var}(\hat\tau_{\text{cuped}})}{\operatorname{Var}(\hat\tau)} \approx \rho^2

That law is what the two experiments were chosen to test, and it holds at both ends. The Electric Company, with ρ=0.883\rho = 0.883 and ρ2=0.780\rho^2 = 0.780, gives a 79% variance reduction. Social Pressure, with ρ=0.163\rho = 0.163 and ρ2=0.026\rho^2 = 0.026, gives 3% — and its effect moves only from +0.081 to +0.080. The practical consequence is that the value of adjustment is knowable before running it: square the correlation between the covariate and the outcome. A weak covariate is not harmful, it is simply not worth much, and no amount of methodological sophistication will change that.

experimentρρ²variance reductioneffect, unadjusted → adjusted
Electric Company (192 classrooms)0.8830.78079%+5.66 → +4.73
Social Pressure GOTV (305,866 voters)0.1630.0263%+0.081 → +0.080

Freedman’s Objection and Lin’s Fix

There is a real objection to plain ANCOVA, and it is not a technicality. Freedman (2008) showed it can be slightly biased in finite samples, and can even hurt precision, because a single common slope is imposed on both arms — if the covariate relates to the outcome differently under treatment and control, that constraint is wrong. Lin (2013) fixed it with a small change: centre the covariates and fully interact them with treatment, fitting a separate slope per arm. The result is guaranteed asymptotically no worse than the unadjusted difference, and it removes Freedman's bias, at the cost of a few parameters.

Yi=α+τTi+β(XiXˉ)+γTi(XiXˉ)+εiY_i = \alpha + \tau\,T_i + \beta\,(X_i - \bar X) + \gamma\,T_i(X_i - \bar X) + \varepsilon_i

In practice the interaction rarely changes much at scale — on Social Pressure, Lin and ANCOVA agree to the fourth decimal — which is precisely why it is the right default: it costs almost nothing when it is unnecessary and protects you when it is not. The Electric Company is adjusted within grade, respecting its blocked design, and the per-grade view shows why the interacted form matters: adjustment tightens every grade, but it moves the estimates in different directions and by very different amounts, from +8.36 down to +4.27 in grade 2 while grade 3 rises from +0.33 to +1.91. Those are genuinely different slopes, not noise around a common one.

Electric Company, within gradeunadjustedSEANCOVASE
grade 18.304.628.792.61
grade 28.362.704.271.36
grade 30.332.351.910.77
grade 43.711.841.700.71

Where this sits

This is the precision layer sitting on top of the RCT foundations, where identification was settled and nothing was said about how sharp the answer would be. The same pre-period-covariate logic returns as the baseline period in difference-in-differences and as the residualization idea behind double machine learning, later in the arc. The blocked design here connects to stratified and matched-pair randomization — the Electric Company was randomized in matched pairs within grade, which is the same structure Darwin's pots have in the previous notebook. And CUPED is where this subject meets online experimentation, which the A/B-testing notebooks in this group take up in earnest.

Notebooks

Downloads

References