Skip to content

Estimate the best linear projection of the Conditional Average Treatment Effect for approximately optimal targeting

Notifications You must be signed in to change notification settings

christophergandrud/blpopt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

blpopt

R-CMD-check Lifecycle: experimental

Estimate the best linear projection of the Conditional Average Treatment Effect (CATE) for approximately optimal targeting

Installation

You can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("christophergandrud/blpopt")

Note: the package is in a private GitHub repo. You need to add your auth token (if you have access) to download using devtools.

Example

## ----setup--------------------------------------------------------------------
library(blpopt)
library(grf)
library(ggplot2)

## ---- data-generation---------------------------------------------------------
n <- 2000
p <- 20
X <- matrix(rnorm(n * p), n, p)

# CATE varies along one dim only.
tau_ex <- function(x){1 / (1 + exp(-x))} 
TAU <- tau_ex(X[,3])

# Propensity  and Outcome vary along 2 and 5 dimensions only.
W <- rbinom(n, 1, 1 / (1 + exp(-X[, 1] - X[, 2]))) 
Y <- pmax(X[, 2] + X[, 3], 0) + rowMeans(X[, 4:6]) / 2 + W * TAU + rnorm(n)

## ---- estimate----------------------------------------------------------------
cf <- causal_forest(X, Y, W)
blp <- cate_blp(cf, X[,3])

## ---- summary-----------------------------------------------------------------
summary(blp)

## ---- predictions-------------------------------------------------------------
predicted <- predict(blp)

## ---- visually-compare--------------------------------------------------------
ggplot(predicted, aes(x = A, y = predicted)) +
  xlim(c(min(predicted$A), max(predicted$A))) +
  geom_function(fun = tau_ex,col="red")  + 
  geom_point(size = 1, alpha = 0.4) +
  theme_minimal()
  
  
total_pred <- cate_blp_bootstrap(blp, iterations = 1000)

total_pred$difference_blp <- total_pred$predicted_optimal - total_pred$predicted_totals

median(total_pred$difference_blp)

See also

  • Semenova, V. and Chernozhukov, V., 2021. Debiased machine learning of conditional average treatment effects and other causal functions. The Econometrics Journal, 24(2), pp.264-289.

  • drlearner computes CATE estimates needed for best linaer projections in the format this package expects using the doubly robust learner method from Kennedy (2022)

  • grf::best_linear_projection gives best linear projections from causal forests. This function produces equivalent results for causal forests. blpopt aims to provide BLPs for a wider range of models, such as doubly robust learners.

About

Estimate the best linear projection of the Conditional Average Treatment Effect for approximately optimal targeting

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published