Causal Inference with Machine Learning
Treatment effects, double machine learning and causal forests.
Machine learning predicts; decisions need to know what would happen under an intervention. This lesson builds the bridge: the potential-outcome assumptions that identify causal effects from observational data, propensity scores and doubly robust estimation, double machine learning, which lets flexible predictors estimate nuisance functions without biasing the effect, heterogeneous effects with meta-learners and causal forests, and the sensitivity analyses that ask how wrong the assumptions would have to be to overturn a conclusion.
What you’ll learn
- Define potential outcomes, the ATE and the CATE, and prove identification under consistency, unconfoundedness and overlap, together with its graphical form, the backdoor adjustment.
- Derive inverse propensity weighting and the AIPW estimator, and prove double robustness with its product-of-errors bias.
- Explain Neyman orthogonality and cross-fitting, and state when double machine learning is -consistent and asymptotically normal.
- Compare S-, T-, X- and R-learners and causal forests for heterogeneous effects, and quantify robustness to unmeasured confounding with E-values.
Potential outcomes and identification
Each unit has a binary treatment , covariates and two potential outcomes: if treated and if not (Neyman, 1923; Rubin, 1974). Only one is ever observed, : the fundamental problem of causal inference. The targets are the average treatment effect and the conditional one, . Write for the propensity score and for the outcome regressions.
Unconfoundedness lets you condition on the treatment, consistency replaces the potential outcome by the observed one, and overlap ensures the conditioning event has positive probability:
For the weighting form, , and given the treatment is independent of :
The same steps give the control arm. Average over . Rosenbaum & Rubin (1983) added that the propensity score is a balancing score, , so unconfoundedness given implies unconfoundedness given the scalar : matching or stratifying on one number suffices.
In Pearl's graphical language (Pearl, 2009), a set satisfies the backdoor criterion for if no node in is a descendant of and blocks every path between and that starts with an arrow into . Then
the graphical counterpart of unconfoundedness given . Descendants of the treatment must stay out: adjusting for a mediator removes part of the effect, and adjusting for a common effect of and (a collider) creates bias where there was none. In the sprinkler network, Cloudy is a confounder of Sprinkler and WetGrass, and satisfies the criterion.
Use the backdoor formula with and the numbers in the caption. What is , in percent?
Show the answer
94.5 %
, against the observational 92.7%. With the sprinkler forced off, , so the causal effect of the sprinkler is 49.5 points while the naive contrast is points. The naive contrast weights the strata by instead of .
Estimating the average effect: weighting and double robustness
Each identification formula suggests an estimator. Outcome regression fits and averages ; any bias in the fits, such as shrinkage from regularization, passes straight into . Inverse propensity weighting (IPW), in the spirit of Horvitz & Thompson (1952), averages ; it is unbiased with the true propensities, but units with near 0 or 1 receive huge weights, and its variance explodes when overlap is weak. In high dimensions overlap is a strong assumption: D'Amour, Ding, Feller, Lei & Sekhon (2021) showed that strict overlap sharply limits how different the treated and control covariate distributions can be, increasingly so as the dimension grows.
Combine the two (Robins, Rotnitzky & Zhao, 1994): start from the regression estimate and correct it with the weighted residuals:
Take expectations of the treated part with estimated nuisances. Given , , so the error is a product:
Double robustness: the bias vanishes if either or , and the control arm behaves the same way. More usefully for machine learning, the bias is second order, bounded by the product of the two errors by Cauchy–Schwarz, when is bounded away from 0:
The AIPW score , centered at , is the efficient influence function of the ATE in the nonparametric model, so with good nuisance estimates the estimator attains the semiparametric efficiency bound; Bang & Robins (2005) discuss doubly robust estimation in missing-data and causal models. The product structure is the key that the next step generalizes: if each nuisance is estimated at rate , their product is , and the estimation error of the nuisances does not affect to first order.
Double machine learning
Take the partially linear model of Robinson (1988), with a scalar treatment that may be continuous:
Fitting with a lasso or a forest and regressing on fails: the regularization bias of enters the estimating equation to first order, and because flexible learners converge more slowly than , does not even stay bounded. Chernozhukov, Chetverikov, Demirer, Duflo, Hansen, Newey & Robins (2018) fixed this with two ingredients, which together make up double machine learning.
Partial out from both and . With , the score uses the nuisances :
Plug in estimates fitted on other data. Writing and , the first factor becomes and the second . All terms linear in the errors have mean zero because and have mean zero given ; only products of errors survive:
This is Neyman orthogonality: the derivative of the moment in the direction of the nuisances vanishes at the truth. By contrast, the naive score has bias , first order in the error. With the orthogonal score, nuisance errors of order each give a moment bias of , negligible against sampling noise:
Cross-fitting supplies the other data. Split the sample into folds, estimate on all folds but , evaluate the score on fold , and solve the averaged equation. This removes the bias that arises when a flexible learner's own overfitting correlates with the noise of the points it is evaluated on, without assumptions limiting the complexity of the learner. In the partially linear model the solution is a residual-on-residual regression:
import numpy as np
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import cross_val_predict
# Cross-fitted nuisances: each prediction comes from a model that never saw that row
l_hat = cross_val_predict(RandomForestRegressor(min_samples_leaf=5), X, Y, cv=5) # E[Y | X]
m_hat = cross_val_predict(RandomForestRegressor(min_samples_leaf=5), X, T, cv=5) # E[T | X]
y_res, t_res = Y - l_hat, T - m_hat # partial out X
theta = np.sum(t_res * y_res) / np.sum(t_res ** 2) # residual-on-residual slope
psi = (y_res - theta * t_res) * t_res
se = np.sqrt(np.mean(psi ** 2) / np.mean(t_res ** 2) ** 2 / len(Y))
print(f"theta = {theta:.3f} +/- {1.96 * se:.3f}") # 95% intervalThe forests may be heavily regularized and individually biased; the orthogonal score and cross-fitting keep that bias out of to first order. Validity still rests on unconfoundedness: no estimator can remove confounding by variables that are not in .
Heterogeneous effects
Targeting a treatment needs the conditional effect , a regression on outcomes nobody observes. Meta-learners reduce it to ordinary supervised learning (Künzel, Sekhon, Bickel & Yu, 2019).
| Learner | Recipe | Strength | Weakness |
|---|---|---|---|
| S-learner | one model with as a feature; | simple; shares information across arms | regularization can shrink the treatment effect toward zero, or ignore entirely |
| T-learner | separate ; | flexible | the difference of two noisy fits; poor when one arm is small |
| X-learner | impute effects for treated and for controls, regress each set on , and combine the two fits with weights such as | efficient with unbalanced arms; exploits structure in (under regularity conditions, a linear CATE can be learned at the parametric rate even when are only Lipschitz) | more steps; each a possible error source |
| R-learner (Nie & Wager, 2021) | with cross-fitted nuisances | orthogonalized; a quasi-oracle property (proved for penalized kernel regression): with moderately accurate nuisances it attains the error bound of an oracle that knows them | unstable where is near 0 or 1 |
Evaluating CATE estimators is itself hard: individual effects are never observed, so held-out error must be estimated with pseudo-outcomes (built from AIPW scores or from randomized data) whose noise can swamp differences between models. Honest reporting therefore shows calibration-style checks, such as whether units predicted to benefit most actually do in held-out data, rather than a single error number. The forests of Random Forest Theory supply the underlying asymptotics.
When identification fails: sensitivity analysis
Overlap can be checked (look at the estimated propensities and trim or redefine the population if they pile up near 0 or 1). Unconfoundedness cannot: the data never show the potential outcome a unit did not receive. Sensitivity analysis asks how strong an unmeasured confounder would have to be to change the conclusion. Rosenbaum's model bounds by a factor how much two units with the same covariates may differ in their odds of treatment, and reports the largest at which the finding survives (Rosenbaum, Observational Studies, 2002). The E-value of VanderWeele & Ding (2017) gives a single number for an observed risk ratio :
An observational study adjusted for measured confounders finds a risk ratio of 2.0 for disease among the exposed. What is its E-value?
Show the answer
3.41
. An unmeasured confounder associated with both exposure and disease by risk ratios of 3.41 each could explain the whole association; weaker confounding could not. Whether such a confounder is plausible is a scientific judgment the number informs but does not make.
Cinelli & Hazlett (2020) express the same question for regression estimates through partial values, which can be benchmarked against observed covariates ("a confounder as strong as income"). When unconfoundedness is implausible altogether, other designs identify effects under different assumptions: instrumental variables, regression discontinuity and difference-in-differences, each with its own untestable conditions.
Key takeaways
- Potential outcomes define and . Consistency, unconfoundedness and overlap identify them as or by inverse propensity weighting; the backdoor criterion is the graphical version.
- AIPW, , is doubly robust, and its bias is a product of nuisance errors, so two errors give an bias.
- Double machine learning combines a Neyman-orthogonal score with cross-fitting; with product-rate conditions on the nuisances, is -consistent and asymptotically normal, with the variance of the known-nuisance estimator.
- Heterogeneous effects: S-, T-, X- and R-learners turn CATE estimation into supervised learning, and honest causal forests are asymptotically Gaussian with infinitesimal-jackknife confidence intervals.
- Unconfoundedness is untestable: report sensitivity analyses such as Rosenbaum's or the E-value, .
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Which identification assumption cannot be checked from observational data on ?
- Overlap:
- Unconfoundedness:
- That the outcome model is well specified
- That the treatment is binary
Show the answer
B. Unconfoundedness:
Unconfoundedness is a statement about potential outcomes, one of which is never observed for each unit, so no data on can confirm or refute it. Overlap can be inspected through estimated propensities, and model fit through held-out error.
An analyst's propensity model is badly misspecified, but the outcome regressions are consistent. What happens to the AIPW estimate of the ATE?
- It is consistent: the bias is the product of the two errors, and one of them vanishes
- It is inconsistent, because the weights are wrong
- It is consistent only if the propensities are bounded by 0.5
- It equals the IPW estimate
Show the answer
A. It is consistent: the bias is the product of the two errors, and one of them vanishes
The bias of each arm is (with for the control arm); with it vanishes even if stays wrong, provided is bounded away from 0 and 1. That is double robustness.
In double machine learning, what does cross-fitting accomplish?
- It makes the nuisance estimators unbiased
- It replaces the orthogonal score
- It removes the bias from evaluating flexible nuisance fits on the same points they were trained on, without limiting the learners' complexity
- It guarantees unconfoundedness
Show the answer
C. It removes the bias from evaluating flexible nuisance fits on the same points they were trained on, without limiting the learners' complexity
If is fitted on the same observations at which the score is evaluated, its overfitting correlates with their noise and biases the estimate. Fitting on the other folds breaks that correlation; orthogonality then handles the remaining (independent) estimation error.
A study reports a risk ratio of 3.0 after adjustment. What is the E-value, and what does it mean?
- 3.0: a confounder with risk ratio 3 with the outcome alone could explain the effect
- About 5.45: a confounder would need risk ratios of about 5.45 with both treatment and outcome to explain the association away
- About 1.73: the effect is fragile
- It cannot be computed without knowing the confounder
Show the answer
B. About 5.45: a confounder would need risk ratios of about 5.45 with both treatment and outcome to explain the association away
. Only confounding at least that strong in both associations, beyond the measured covariates, could fully explain the observed risk ratio.
Further reading
- P. R. Rosenbaum & D. B. Rubin, "The central role of the propensity score in observational studies for causal effects," Biometrika 70(1), 41–55 (1983).
- J. M. Robins, A. Rotnitzky & L. P. Zhao, "Estimation of regression coefficients when some regressors are not always observed," Journal of the American Statistical Association 89(427), 846–866 (1994).
- V. Chernozhukov, D. Chetverikov, M. Demirer, E. Duflo, C. Hansen, W. Newey & J. Robins, "Double/debiased machine learning for treatment and structural parameters," The Econometrics Journal 21(1), C1–C68 (2018).
- S. Wager & S. Athey, "Estimation and inference of heterogeneous treatment effects using random forests," Journal of the American Statistical Association 113(523), 1228–1242 (2018).
- S. R. Künzel, J. S. Sekhon, P. J. Bickel & B. Yu, "Metalearners for estimating heterogeneous treatment effects using machine learning," Proceedings of the National Academy of Sciences 116(10), 4156–4165 (2019).
- G. W. Imbens & D. B. Rubin, Causal Inference for Statistics, Social, and Biomedical Sciences: An Introduction (Cambridge University Press, 2015).