DEV Community

Cover image for Doubly Robust Estimation: When Two Imperfect Models Still Get Causality Right
Umesh Tharuka Malaviarachchi
Umesh Tharuka Malaviarachchi

Posted on

Doubly Robust Estimation: When Two Imperfect Models Still Get Causality Right

Most machine learning is optimised for prediction. Causal inference asks a harder question: what would have happened if we had acted differently? That difference — between predicting an outcome and estimating the effect of an intervention — is where doubly robust estimation earns its place.

Doubly robust methods do not promise magic. They promise something more useful: a second chance. If either of two models is right, the estimate can still be right. Understanding why that works, and where it breaks, changes how you should approach any observational study.

The estimand comes first

Suppose we have a binary treatment AA , covariates XX , and an observed outcome YY . Each person has two potential outcomes, Y(1)Y(1) under treatment and Y(0)Y(0) under control, but we observe only one:

Y=A⋅Y(1)+(1−A)⋅Y(0) Y = A \cdot Y(1) + (1 - A) \cdot Y(0)

The average treatment effect, or ATE, is:

τ=E[Y(1)−Y(0)] \tau = E[Y(1) - Y(0)]

We cannot compute this directly, because the counterfactual is missing by construction. Causal inference therefore rests on assumptions, not just on algorithms. The three that matter most here are:

  1. Consistency: the observed outcome under the treatment actually received equals the corresponding potential outcome.
  2. Unconfoundedness: conditional on XX , treatment assignment is as good as random, so Y(1),Y(0)Y(1), Y(0) are independent of AA given XX .
  3. Positivity, or overlap: every type of person has a non-zero chance of receiving either treatment, so 0<P(A=1∣X)<10 < P(A=1 \mid X) < 1 .

Unconfoundedness cannot be verified from the data alone. If an important confounder is unmeasured, no estimator in this family will rescue the analysis. Doubly robust estimation protects against model misspecification, not against a missing confounder. That distinction is essential, and it is the first thing to get wrong.

Two flawed answers

Answer 1: Model the outcome

Outcome regression models E[Y∣A,X]E[Y \mid A, X] . Write:

μa(X)=E[Y∣A=a,X] \mu_a(X) = E[Y \mid A=a, X]

If the model is correct, the ATE follows immediately:

τ=E[μ1(X)−μ0(X)] \tau = E[\mu_1(X) - \mu_0(X)]

In practice, we fit a flexible model, predict both potential outcomes for every observation, and average the difference. This is intuitive and often efficient when the outcome surface is smooth and well behaved.

Its weakness is obvious once stated: if μa(X)\mu_a(X) is misspecified — the wrong functional form, a missing interaction, a variable transformed incorrectly — the bias flows straight into τ\tau . A model that predicts well overall can still be badly wrong in exactly the region that matters for the treatment contrast.

Answer 2: Model the treatment assignment

Inverse probability weighting takes the opposite route. Estimate the propensity score:

e(X)=P(A=1∣X) e(X) = P(A=1 \mid X)

Then reweight the observed data so that the treated and control groups resemble the full population:

τ=E[AYe(X)−(1−A)Y1−e(X)] \tau = E\left[\frac{A Y}{e(X)} - \frac{(1-A) Y}{1-e(X)}\right]

This approach does not model the outcome at all. Its weakness is equally clear: it lives or dies by the propensity model, and it becomes unstable when e(X)e(X) is close to 0 or 1. A few observations with tiny denominators can dominate the estimate, and the variance can explode even when the bias looks small.

So we have two strategies, each vulnerable to a different kind of modelling error. Doubly robust estimation combines them in a way that is more than a compromise.

The augmented estimator

The augmented inverse probability weighting estimator, often called AIPW, uses both models at once. For each observation, form a pseudo-outcome:

ϕ=μ1(X)−μ0(X)+A(Y−μ1(X))e(X)−(1−A)(Y−μ0(X))1−e(X) \phi = \mu_1(X) - \mu_0(X) + \frac{A (Y - \mu_1(X))}{e(X)} - \frac{(1-A)(Y - \mu_0(X))}{1-e(X)}

Then average ϕ\phi over the sample to estimate τ\tau .

Read the formula term by term. The first part, μ1(X)−μ0(X)\mu_1(X) - \mu_0(X) , is the outcome-regression answer. The remaining terms are corrections. If the outcome model overpredicts for a treated person, Y−μ1(X)Y - \mu_1(X) is negative, and the correction pulls the estimate down, weighted by the inverse propensity. If the outcome model underpredicts, the correction pulls it up. The same logic applies to the control group.

The crucial property is this: τ\tau is estimated consistently if either the outcome model or the propensity model is correct. It does not require both.

Why two wrongs can make a right

The intuition can be made precise without heavy machinery. The bias of the AIPW estimator depends, roughly, on the product of the two modelling errors: the error in μa(X)\mu_a(X) multiplied by the error in e(X)e(X) .

If the outcome model is exactly right, the residual terms Y−μa(X)Y - \mu_a(X) have conditional mean zero, so the correction terms vanish in expectation, whatever the propensity model says. The outcome model carries the estimate.

If the propensity model is exactly right, the weighting corrects the outcome model's mistakes in expectation, because the inverse-probability weights restore the population distribution that the misspecified outcome model distorted. The propensity model carries the estimate.

If both models are slightly wrong, the damage is second-order: a small error times a small error, rather than a single error carried at full strength. That product structure is why doubly robust estimators often perform well even when neither model is perfect — provided both are reasonably close, and the positivity assumption holds.

This is also why the method is not a licence to be careless. If both models are badly wrong, the product of two large errors is still a large error. Double robustness is insurance, not immunity.

A practical example

The following Python sketch shows the structure. It is illustrative, not a production pipeline: in real work you would add cross-fitting, diagnostics, and uncertainty quantification, as discussed below.

import numpy as np
from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier

# X: covariates, A: binary treatment, Y: outcome
# Fit the nuisance models on training data (see cross-fitting below)
mu_model = RandomForestRegressor(random_state=0).fit(
    np.column_stack([A_train, X_train]), Y_train
)
e_model = RandomForestClassifier(random_state=0).fit(X_train, A_train)

# Predict both potential outcomes for each observation
mu1 = mu_model.predict(np.column_stack([np.ones(len(X)), X]))
mu0 = mu_model.predict(np.column_stack([np.zeros(len(X)), X]))
e = e_model.predict_proba(X)[:, 1]

# Clip propensities away from 0 and 1 to limit variance blow-up
# (clipping is a diagnostic signal, not a cure — see pitfalls below)
e = np.clip(e, 0.01, 0.99)

phi = (
    mu1 - mu0
    + A * (Y - mu1) / e
    - (1 - A) * (Y - mu0) / (1 - e)
)

ate_aipw = phi.mean()
Enter fullscreen mode Exit fullscreen mode

Note what the code does not do: it does not claim that a random forest is automatically correct. Flexible learners reduce functional-form risk, but they introduce their own risks — overfitting, poor extrapolation, and slow convergence in high dimensions. Doubly robust estimation works best when the nuisance models are good, not merely flexible.

Cross-fitting: the step most tutorials skip

There is a subtle trap in the sketch above. If you fit μa\mu_a and ee on the same data you use to average ϕ\phi , overfitting in the nuisance models can leak into the ATE estimate. A model that memorises its training data will produce residuals that look too small, and the correction terms will be understated.

Cross-fitting solves this cleanly. Split the data into folds. For each fold, fit the nuisance models on the other folds, then compute ϕ\phi for the held-out fold. Average across all folds. This is the core idea behind double machine learning, and it matters most precisely when you use powerful, flexible learners.

Cross-fitting does not fix a bad model. It stops a good model's overfitting from masquerading as causal evidence.

Limitations and common pitfalls

1. Extreme propensities destroy precision.
When e(X)e(X) is near 0 or 1, the inverse weights become enormous. The estimate may still be unbiased in theory, but its variance can make it useless in practice. Always inspect the propensity distribution and the overlap between treated and control groups before trusting an AIPW estimate. If there is almost no overlap, the honest conclusion may be that the ATE is not well identified for that population, and a different estimand — such as the effect on the treated — is more credible.

2. Clipping is not a fix.
Clipping propensities to a range such as [0.01, 0.99] limits variance, but it changes the estimand slightly and can hide an overlap problem. Treat heavy clipping as a warning to investigate, not as a routine preprocessing step.

3. Both models can be wrong in the same direction.
Double robustness requires at least one model to be right. If both models omit the same confounder, or both rely on the same flawed feature engineering, the product-of-errors argument offers no protection. This is why domain knowledge about what to include in XX matters more than the choice of learner.

4. The ATE hides heterogeneity.
A single average can conceal effects that differ sharply across subgroups. AIPW can be extended to conditional average treatment effects, but that requires more data, careful modelling of effect modification, and a clear statement of which subgroup effect is being estimated. Do not let a clean average number hide a messy reality.

5. Standard errors need care.
The pseudo-outcomes ϕ\phi can be used to form standard errors, but naive standard errors that ignore nuisance-model estimation can be misleading, especially without cross-fitting. Report uncertainty honestly, and be sceptical of estimates whose confidence intervals depend on ignoring the hardest part of the problem.

6. Prediction performance is not causal performance.
A nuisance model with excellent held-out predictive accuracy can still be a poor causal model if it is trained on the wrong variables, leaks post-treatment information, or conditions on a collider. Variable selection for causal estimation is a substantive decision, not a leaderboard exercise. In particular, never include variables affected by the treatment itself as if they were baseline confounders.

When to use it

Use doubly robust estimation when you have observational data, a plausible set of measured confounders, reasonable overlap, and two different modelling strategies that can plausibly capture different parts of the problem — for example, a well-understood outcome mechanism plus a treatment assignment process you can model separately.

Do not use it as a substitute for design. Randomisation, a natural experiment, or a better measurement strategy will usually beat a fancier estimator on confounded data. The best use of AIPW is to make a credible observational analysis more robust, not to make an incredible one look rigorous.

The takeaway

Causal inference from observational data is an exercise in managing assumptions you cannot fully test. Outcome regression bets everything on one model. Inverse probability weighting bets everything on another. Doubly robust estimation spreads that bet, and its bias depends on the product of the two errors rather than on either error alone.

That is a genuinely useful property — and a genuinely limited one. It protects you against one kind of modelling failure, not against unmeasured confounding, poor overlap, or bad design. Used with cross-fitting, overlap checks, and honest uncertainty reporting, it is one of the most practical tools in modern causal inference. Used as a black box, it is just another way to produce a precise-looking wrong answer.

The discipline is not in the formula. It is in everything around it: choosing the right covariates, checking overlap, fitting the nuisance models carefully, and knowing when to say that the data cannot answer the question as posed.


Connect with me on LinkedIn: linkedin.com/in/umeshtharukaofficial

Top comments (0)