Remove predictable variation without adjusting away treatment
Derive CUPED control variates, their variance reduction, and the assumptions that keep the treatment contrast intact.
On this page
The question for today
What you’ll understand
- Calculate a CUPED coefficient from covariance and variance.
- Distinguish a population variance identity from a finite estimated adjustment.
- Exclude post-treatment leakage and preserve missing-history policy.
Randomized arms can differ by chance in how active their users were before the experiment. If past activity predicts the outcome, that predictable variation can obscure a small treatment effect. CUPED uses a pre-experiment covariate as a control variate: subtract the part of the outcome associated with the baseline, then compare adjusted means. It changes the estimator’s noise rather than making a weak randomization design valid. The important boundary is temporal and causal: the adjustment variable must not be a consequence of the treatment whose effect is being estimated.
Center a baseline and preserve the contrast
Let Y be the outcome and X a preperiod covariate observed before intervention. Subtract θ times the deviation of X from a common center c. Using the same coefficient and center in both arms makes the adjusted difference equal the raw outcome difference minus θ times the baseline imbalance. The center cancels from that contrast. For a fixed coefficient and a randomized baseline unaffected by treatment, the expected baseline difference is zero, preserving the assignment effect.
This does not mean every realized adjusted estimate equals the raw estimate, or that adjustment always moves a result toward zero. If treatment happened to receive unusually active users, adjustment may reduce an inflated observed difference; the opposite imbalance may increase it. Report the adjustment specification and uncertainty rather than choosing whichever version looks more favorable. Use the randomization unit’s covariate and outcome aggregation, avoiding a user/request mismatch hidden inside a regression table.
Covariance explains the potential gain
For a single population with finite second moments, the residual variance is a quadratic function of θ. Differentiating it gives covariance divided by baseline variance as the variance-minimizing coefficient. At that coefficient, the remaining variance is the original outcome variance times one minus squared correlation. This is a population identity, not a guarantee that an estimated coefficient on a small noisy sample improves every experiment or every arm.
Estimate adjustment parameters using a documented procedure, such as independent historical data, a prespecified pooled approach with appropriate asymptotic analysis, or cross-fitting when the method requires it. Fitting a flexible predictor and evaluating it on the same records can create overfitting and invalid uncertainty. Strong baseline predictiveness helps, but the analysis must still account for coefficient estimation, heterogeneous treatment effects where relevant, and any clustering induced by assignment.
Preperiod means genuinely before treatment
A feature computed from the experiment’s first day is not a preperiod covariate merely because it is available before the final analysis. If treatment affects it, adjusting for it can remove part of the causal pathway or create selection bias. Freeze source cutoffs and feature lineage, and verify that the baseline calculation cannot read outcome-window events through late joins, backfills, or a reused feature table whose contents changed during the run.
New users may lack history. Specify imputation and missingness indicators before inspecting treatment results, and preserve them symmetrically across arms. A complete-case analysis can change the target population, particularly if history availability is inferred from treatment-affected activity. Ratio metrics and repeated-event metrics also need a suitable unit-level or delta-method treatment; applying a simple scalar adjustment to arbitrary event ratios does not automatically inherit the elementary CUPED variance identity.
Work it through
Baseline imbalance accounts for part of an observed difference
Use fixed θ estimated from independent data with Var(X)=4, Cov(Y,X)=3, and Var(Y)=9. The experiment has treatment means YT=12, XT=6 and control means YC=10, XC=4. Use common center c=5.
The variance-minimizing population coefficient is θ=3/4=0.75. Correlation is 3/(√4√9)=0.5, so the control-variate residual variance is 9×(1−0.5²)=6.75, a 25% reduction in this population model.
Adjusted treatment mean is 12−0.75(6−5)=11.25. Adjusted control mean is 10−0.75(4−5)=10.75. Their observed difference is 0.5 outcome units.
Check the contrast directly: raw outcome difference is 2 and baseline difference is 2, so Δadj=2−0.75×2=0.5. This calculation adjusts a realized baseline imbalance; it does not prove the true causal effect equals exactly 0.5 or that every empirical variance will fall by 25%.
A fixed baseline adjustment changes the point estimate from 2 to 0.5 here. The population variance identity and the experiment’s uncertainty calculation remain distinct pieces of evidence.
The living notebook
Explore the model
Interactive lab · matrix
A linear shear can represent residualization
Reset, set Diagonal scale a to 1 and Shear b to 0. Predict identity and determinant 1 before Step. Reset, set a to 1 and b to −0.75; predict A=[[1,−0.75],[0,1]], whose first coordinate maps centered (Y,X) to Y−0.75X, with determinant 1. Readouts describe the selected final matrix during interpolation. This linear map does not estimate covariance, fit CUPED, or measure variance reduction.
- Area scale · det A
- 1.4
- Singular values · σmax, σmin
- 1.597, 0.876
- Condition number · κ₂(A)
- 1.823
The selected matrix is A = [[a,b],[0,1]]. Playback interpolates geometry between the identity and A; readouts always describe A. Its determinant is a and its singular values come from AᵀA. Positive a makes every supported matrix invertible. This two-dimensional family is not a general eigensolver or a learned network. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forThe adjustment is a defined linear transformation; its statistical benefit requires separate covariance and design assumptions.
Pause & reason
Check your understanding
Your turn
Try it yourself
Use fixed population quantities Var(X)=9, Cov(Y,X)=6, Var(Y)=16. Find θ*, residual variance, and the adjusted difference if raw ΔY=3 and preperiod ΔX=1.5.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Compute covariance divided by baseline variance, then apply the same coefficient to the observed contrast.
Compare with the solution
θ*=6/9=2/3. Residual variance is 16−6²/9=12, a 25% reduction from 16 under the population identity. The adjusted contrast is 3−(2/3)×1.5=2. This fixed-coefficient calculation does not by itself supply an experiment standard error or justify using a treatment-affected covariate.
Keep the idea
Take it with you
- CUPED subtracts predictable baseline variation using pre-treatment data.
- Population covariance identities do not eliminate estimation or design assumptions.
- Freeze feature lineage and prevent post-treatment leakage.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.