Xleaners: X-Learners

X-LearnerR Documentation

X-Learners

Description

X_RF is an implementation of the X-learner with Random Forests (Breiman 2001) in the first and second stage.

X_BART is an implementation of the X-learner with Bayesian Additive Regression Trees (Chipman et al. 2010) at the first and second stage

Usage

X_RF(
  feat,
  tr,
  yobs,
  predmode = "propmean",
  nthread = 0,
  verbose = FALSE,
  correction = NULL,
  mu.forestry = list(relevant.Variable = 1:ncol(feat), ntree = 1000, replace = TRUE,
    sample.fraction = 0.8, mtry = round(ncol(feat) * 13/20), nodesizeSpl = 2, nodesizeAvg
    = 1, nodesizeStrictSpl = 2, nodesizeStrictAvg = 1, splitratio = 1, middleSplit =
    TRUE, OOBhonest = TRUE),
  tau.forestry = list(relevant.Variable = 1:ncol(feat), ntree = 1000, replace = TRUE,
    sample.fraction = 0.7, mtry = round(ncol(feat) * 17/20), nodesizeSpl = 5, nodesizeAvg
    = 6, nodesizeStrictSpl = 3, nodesizeStrictAvg = 1, splitratio = 1, middleSplit =
    TRUE, OOBhonest = TRUE),
  e.forestry = list(relevant.Variable = 1:ncol(feat), ntree = 500, replace = TRUE,
    sample.fraction = 0.5, mtry = ncol(feat), nodesizeSpl = 11, nodesizeAvg = 33,
    nodesizeStrictSpl = 2, nodesizeStrictAvg = 1, splitratio = 1, middleSplit = FALSE,
    OOBhonest = TRUE)
)

X_BART(
  feat,
  tr,
  yobs,
  predmode = "pscore",
  nthread = 1,
  ndpost = 1200,
  ntree = 200,
  mu.BART = list(sparse = FALSE, theta = 0, omega = 1, a = 0.5, b = 1, augment = FALSE,
    rho = NULL, usequants = FALSE, cont = FALSE, sigest = NA, sigdf = 3, sigquant = 0.9,
    k = 2, power = 2, base = 0.95, sigmaf = NA, lambda = NA, numcut = 100L, nskip = 100L),
  tau.BART = list(sparse = FALSE, theta = 0, omega = 1, a = 0.5, b = 1, augment = FALSE,
    rho = NULL, usequants = FALSE, cont = FALSE, sigest = NA, sigdf = 3, sigquant = 0.9,
    k = 2, power = 2, base = 0.95, sigmaf = NA, lambda = NA, numcut = 100L, nskip = 100L),
  e.BART = list(sparse = FALSE, theta = 0, omega = 1, a = 0.5, b = 1, augment = FALSE,
    rho = NULL, usequants = FALSE, cont = FALSE, sigest = NA, sigdf = 3, sigquant = 0.9,
    k = 2, power = 2, base = 0.95, sigmaf = NA, lambda = NA, numcut = 100L, nskip = 100L)
)

Arguments

feat

A data frame containing the features.

tr

A numeric vector with 0 for control and 1 for treated variables.

yobs

A numeric vector containing the observed outcomes.

predmode

Specifies how the two estimators of the second stage should be aggregated. Possible types are "propmean," "control," and "treated." The default is "propmean," which refers to propensity score weighting.

nthread

Number of threads which should be used to work in parallel.

verbose

TRUE for detailed output, FALSE for no output.

correction

The parameters to use for the bias corrected predictions when creating the outcome and treatment effect regressions. Should be a list of parameters that can be passed to Rforestry::correctedPredict.

mu.forestry, tau.forestry, e.forestry

A list containing the hyperparameters for the Rforestry package that are used for estimating the response functions, the CATE, and the propensity score. These hyperparameters are passed to the Rforestry package. (Please refer to the Rforestry package for a more detailed documentation of the hyperparamters.)

  • relevant.Variable Variables that are only used in the first stage.

  • ntree Numbers of trees used in the first stage.

  • replace Sample with or without replacement in the first stage.

  • sample.fraction The size of total samples to draw for the training data in the first stage.

  • mtry The number of variables randomly selected in each splitting point.

  • nodesizeSpl Minimum nodesize in the first stage for the observations in the splitting set. (See the details of the forestry package)

  • nodesizeAvg Minimum nodesize in the first stage for the observations in the averaging set.

  • nodesizeStrictSpl Minimum nodesize in the first stage for the observations in the splitting set. (See the details of the forestry package)

  • nodesizeStrictAvg Minimum nodesize in the first stage for the observations in the averaging set.

  • splitratio Proportion of the training data used as the splitting dataset in the first stage.

  • middleSplit If true, the split value will be exactly in the middle of two observations. Otherwise, it will take a point based on a uniform distribution between the two observations.

  • OOBhonest If true, forestry object will use the Out of Bag honesty implemented in the Rforestry package.

ndpost

Number of posterior draws.

ntree

Number of trees.

mu.BART, tau.BART, e.BART

hyperparameters of the BART functions for the estimates of the first and second stage and the propensity score. Use ?BART::mc.wbart for a detailed explanation of their effects.

Details

The X-Learner estimates the CATE in three steps:

  1. Estimate the response functions

    μ_0(x) = E[Y(0) | X = x]

    μ_1(x) = E[Y(1) | X = x]

    using the base learner and denote the estimates as \hat μ_0 and \hat μ_1.

  2. Impute the treatment effects for the individuals in the treated group, based on the control outcome estimator, and the treatment effects for the individuals in the control group, based on the treatment outcome estimator, that is,

    D^1_i = Y_i(1) - \hat μ_0(X_i)

    D^0_i = \hat μ_1(X_i) - Y_i(0).

    Now employ the base learner in two ways: using D^1_i as the dependent variable to obtain \hat τ_1(x), and using D^0_i as the dependent variable to obtain \hat τ_0(x).

  3. Define the CATE estimate by a weighted average of the two estimates at Stage 2:

    τ(x) = g(x) \hat τ_0(x) + (1 - g(x)) \hat τ_1(x).

    If predmode = "propmean", then g(x) = e(x), where e(x) is an estimate of the propensity score using the Rforestry Random Forests version with the hyperparameters specified in e.forestry. If predmode = "control", then g(x) = 1, and if predmode = "treated", then g(x) = 0.

Value

An object from a class that contains the CATEestimator class. It should be used with one of the following functions: EstimateCATE, CateCI, and CateBIAS. The object has at least the following slots:

feature_train

A copy of feat.

tr_train

A copy of tr.

yobs_train

A copy of yobs.

creator

Function call that creates the CATE estimator. This is used for different bootstrap procedures.

Author(s)

Soeren R. Kuenzel

References

  • Sören Künzel, Jasjeet Sekhon, Peter Bickel, and Bin Yu (2017). MetaLearners for Estimating Heterogeneous Treatment Effects using Machine Learning. https://www.pnas.org/content/116/10/4156

  • Sören Künzel, Simon Walter, and Jasjeet Sekhon (2018). Causaltoolbox—Estimator Stability for Heterogeneous Treatment Effects. https://arxiv.org/pdf/1811.02833.pdf

  • Sören Künzel, Bradly Stadie, Nikita Vemuri, Varsha Ramakrishnan, Jasjeet Sekhon, and Pieter Abbeel (2018). Transfer Learning for Estimating Causal Effects using Neural Networks. https://arxiv.org/pdf/1808.07804.pdf

See Also

Other metalearners: DR-Learner, M-Learner, S-Learner, T-Learner

Examples

require(causalToolbox)

# create example data set
simulated_experiment <- simulate_causal_experiment(
  ntrain = 1000,
  ntest = 1000,
  dim = 10
)
feat <- simulated_experiment$feat_tr
tr <- simulated_experiment$W_tr
yobs <- simulated_experiment$Yobs_tr
feature_test <- simulated_experiment$feat_te

# create the CATE estimator using Random Forests (RF)
xl_rf <- X_RF(feat = feat, tr = tr, yobs = yobs)
tl_rf <- T_RF(feat = feat, tr = tr, yobs = yobs)
sl_rf <- S_RF(feat = feat, tr = tr, yobs = yobs)
ml_rf <- M_RF(feat = feat, tr = tr, yobs = yobs)
xl_bt <- X_BART(feat = feat, tr = tr, yobs = yobs)
tl_bt <- T_BART(feat = feat, tr = tr, yobs = yobs)
sl_bt <- S_BART(feat = feat, tr = tr, yobs = yobs)
ml_bt <- M_BART(feat = feat, tr = tr, yobs = yobs)
  
cate_esti_xrf <- EstimateCate(xl_rf, feature_test)

# evaluate the performance.
cate_true <- simulated_experiment$tau_te
mean((cate_esti_xrf - cate_true) ^ 2)
## Not run: 
# create confidence intervals via bootstrapping. 
xl_ci_rf <- CateCI(xl_rf, feature_test, B = 500)

## End(Not run)

forestry-labs/causalToolbox documentation built on Feb. 6, 2023, 11:27 p.m.