The X-learner estimates the conditional average treatment effect (CATE) in four steps:
Arguments
- outcome_model
An unfitted
workflows::workflow()whose predictors don't include the treatment column. 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 models, such as
parsnip::linear_reg(), orNULL(default) to reuseoutcome_model's model, with a warning. The effect models useoutcome_model's formula or recipe, so give only the model, not a workflow; the predictors are encoded the way the effect model expects (seefit.x_learner()). Estimated 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 x_learner object, to be passed to
fit().
Details
Fit the outcome model separately on the treated and the control units, as in the T-learner.
Estimate each unit's own effect from its observed outcome and the other group's prediction for it: observed minus predicted for treated units, and predicted minus observed for control units.
Fit an effect model to those estimated effects, separately in each group.
Combine the two effect models' predictions, weighting the control group's effect model by the propensity (each unit's chance of being treated) and the treated group's by one minus the propensity.
The control group's effect model is built from the treated group's outcome model, so when few units are treated, that outcome model is the noisy one and the propensity gives it little weight. The effect models can also be simpler than the outcome model, which helps when the effect is simpler than the outcome itself.
References
Künzel, S. R., Sekhon, J. S., Bickel, P. J., & Yu, B. (2019). Metalearners for estimating heterogeneous treatment effects using machine learning. Proceedings of the National Academy of Sciences, 116(10), 4156-4165. doi:10.1073/pnas.1804597116
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 formula leaves out the treatment: fit() splits the data by it
wf <- workflows::workflow(spend ~ recency, parsnip::linear_reg())
# The email was a 50/50 coin flip, so the propensity is known
fitted <- x_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.43
#> 3 5.61
#> 4 9.24
#> 5 8.64
#> 6 5.61
# Or estimate the propensity with a classification workflow
propensity_wf <- workflows::workflow(emailed ~ recency, parsnip::logistic_reg())
estimated <- x_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.40
#> 2 7.43
#> 3 5.61
#> 4 9.24
#> 5 8.64
#> 6 5.61