Skip to contents

The T-learner ("two" learners) estimates the conditional average treatment effect (CATE) by fitting the same outcome model twice: once on the treated units and once on the control units. Each unit's outcome is predicted by both models, and the difference is the estimated effect.

Usage

t_learner(outcome_model)

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).

Value

An unfitted t_learner object, to be passed to fit().

Details

Each model is fit within one treatment group, where the treatment is the same for every row, so the outcome model must not use the treatment as a predictor. Because the two models are separate, every part of the model can differ between the groups, and the estimated effects can vary across units without any interaction terms. The trade-off is that each model only sees part of the data, so the estimates can be noisy when one group is small.

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())

fitted <- t_learner(wf) |>
  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
predict(fitted, new_data = head(emails), type = "potential_outcomes")
#> # A tibble: 6 × 2
#>   .pred_control .pred_treated
#>           <dbl>         <dbl>
#> 1          11.0          15.4
#> 2          15.8          23.3
#> 3          12.9          18.5
#> 4          18.8          28.0
#> 5          17.8          26.4
#> 6          12.9          18.5