The DR-learner (Kennedy, 2023), or doubly robust learner, estimates the conditional average treatment effect (CATE) in three steps:
Arguments
- outcome_model
An unfitted
workflows::workflow()that predicts the outcome from the features, without the treatment column. It is fit separately on the treated and the control units. Its model can be a regression (numeric outcome) or a classification with two classes (binary outcome).- effect_model
A parsnip model specification for the effect model, such as
parsnip::linear_reg(), orNULL(default) to reuseoutcome_model's model, with a warning. The effect model usesoutcome_model's formula or recipe, so give only the model, not a workflow; the predictors are encoded the way the effect model expects (seefit.dr_learner()). Effects are numbers, so this must be a regression model; a specification with no mode set is set to regression, with a warning. Required when the outcome is binary.- propensity
Each unit's chance of being treated: a single number strictly between 0 and 1 when it is known (e.g.,
0.5in a 50/50 randomized experiment), or an unfitted classificationworkflows::workflow()that predicts the treatment column. There is no default.
Value
An unfitted dr_learner object, to be passed to
fit().
Details
Cross-fit the outcome model separately in each treatment group, so every unit gets two predicted outcomes, one if treated and one if control, and cross-fit the propensity, each unit's chance of being treated. Each unit's predictions come from models fit without it.
Compute each unit's pseudo-outcome: the difference between its two predicted outcomes, plus a correction from its observed outcome, its residual from its own group's model divided by its chance of being in that group.
Fit an effect model to the pseudo-outcomes.
The pseudo-outcome is doubly robust: averaged over units with the same features, it equals the true effect if either the outcome models or the propensity is correct. With a known propensity, as in a randomized experiment, the pseudo-outcomes are centered on the true effects however well the outcome models fit; better outcome models make them less noisy. They are still noisy, so a simpler effect model than the outcome model often works better.
References
Kennedy, E. H. (2023). Towards optimal doubly robust estimation of heterogeneous causal effects. Electronic Journal of Statistics, 17(2), 3008-3049. doi:10.1214/23-EJS2157
Examples
# A small randomized email campaign: the email raises spending more for
# customers who bought recently
set.seed(1)
n <- 200
recency <- sample(1:12, n, replace = TRUE)
emailed <- rbinom(n, size = 1, prob = 0.5)
spend <- 20 - recency + emailed * (10 - 0.75 * recency) + rnorm(n, sd = 5)
emails <- data.frame(recency, emailed, spend)
# The outcome model predicts spending without the treatment; it is fit
# separately on the emailed and the not-emailed customers
wf <- workflows::workflow(spend ~ recency, parsnip::linear_reg())
# The email was a 50/50 coin flip, so the propensity is known. fit() makes
# random cross-fitting folds, so set the seed for reproducible results.
set.seed(2)
fitted <- dr_learner(wf, effect_model = parsnip::linear_reg(), propensity = 0.5) |>
fit(data = emails, treatment = emailed)
predict(fitted, new_data = head(emails))
#> # A tibble: 6 × 1
#> .pred_cate
#> <dbl>
#> 1 4.40
#> 2 7.48
#> 3 5.63
#> 4 9.34
#> 5 8.72
#> 6 5.63
# Or estimate the propensity with a classification workflow
propensity_wf <- workflows::workflow(emailed ~ recency, parsnip::logistic_reg())
set.seed(2)
estimated <- dr_learner(
wf,
effect_model = parsnip::linear_reg(),
propensity = propensity_wf
) |>
fit(data = emails, treatment = emailed)
predict(estimated, new_data = head(emails))
#> # A tibble: 6 × 1
#> .pred_cate
#> <dbl>
#> 1 4.35
#> 2 7.57
#> 3 5.64
#> 4 9.50
#> 5 8.85
#> 6 5.64