View source: R/rank_average_treatment.R
rank_average_treatment_effect.fit | R Documentation |
Provides an optional interface to rank_average_treatment_effect
which allows for user-supplied
evaluation scores.
rank_average_treatment_effect.fit(
DR.scores,
priorities,
target = c("AUTOC", "QINI"),
q = seq(0.1, 1, by = 0.1),
R = 200,
sample.weights = NULL,
clusters = NULL
)
DR.scores |
A vector with the evaluation set scores. |
priorities |
Treatment prioritization scores S(Xi) for the units in the evaluation set. Two prioritization rules can be compared by supplying a two-column array or named list of priorities (yielding paired standard errors that account for the correlation between RATE metrics estimated on the same evaluation data). WARNING: for valid statistical performance, these scores should be constructed independently from the evaluation dataset used to construct DR.scores. |
target |
The type of RATE estimate, options are "AUTOC" (exhibits greater power when only a small subset of the population experience nontrivial heterogeneous treatment effects) or "QINI" (exhibits greater power when the entire population experience diffuse or substantial heterogeneous treatment effects). Default is "AUTOC". |
q |
The grid q to compute the TOC curve on. Default is (10%, 20%, ..., 100%). |
R |
Number of bootstrap replicates for SEs. Default is 200. |
sample.weights |
Weights given to an observation in estimation. If NULL, each observation is given the same weight. Default is NULL. |
clusters |
Vector of integers or factors specifying which cluster each observation corresponds to. Default is NULL (ignored). |
A list of class 'rank_average_treatment_effect' with elements
estimate: the RATE estimate.
std.err: bootstrapped standard error of RATE.
target: the type of estimate.
TOC: a data.frame with the Targeting Operator Characteristic curve estimated on grid q, along with bootstrapped SEs.
# Estimate CATEs with a causal forest.
n <- 2000
p <- 5
X <- matrix(rnorm(n * p), n, p)
W <- rbinom(n, 1, 0.5)
event.probability <- 1 / (1 + exp(2 * (pmax(2 * X[, 1], 0) * W - X[, 2])))
Y <- 1 - rbinom(n, 1, event.probability)
train <- sample(1:n, n / 2)
cf.cate <- causal_forest(X[train, ], Y[train], W[train])
# Predict treatment effects on a held-out test set.
test <- -train
cate.hat <- predict(cf.cate, X[test, ])$predictions
# Estimate AIPW nuisance components on the held-out test set.
Y.forest.eval <- regression_forest(X[test, ], Y[test], num.trees = 500)
Y.hat.eval <- predict(Y.forest.eval)$predictions
W.forest.eval <- regression_forest(X[test, ], W[test], num.trees = 500)
W.hat.eval <- predict(W.forest.eval)$predictions
cf.eval <- causal_forest(X[test, ], Y[test], W[test],
Y.hat = Y.hat.eval,
W.hat = W.hat.eval)
# Form doubly robust scores.
tau.hat.eval <- predict(cf.eval)$predictions
debiasing.weights.eval <- (W[test] - W.hat.eval) / (W.hat.eval * (1 - W.hat.eval))
Y.residual.eval <- Y[test] - (Y.hat.eval + tau.hat.eval * (W[test] - W.hat.eval))
DR.scores <- tau.hat.eval + debiasing.weights.eval * Y.residual.eval
# Could equivalently be obtained by
# DR.scores <- get_scores(cf.eval)
# Form a doubly robust RATE estimate on the held-out test set.
rate <- rank_average_treatment_effect.fit(DR.scores, cate.hat)
rate
# Same as
# rate <- rank_average_treatment_effect(cf.eval, cate.hat)
# In settings where the treatment randomization probabilities W.hat are known, an
# alternative to AIPW scores is to use inverse-propensity weighting (IPW):
# 1(W=1) * Y / W.hat - 1(W=0) * Y / (1 - W.hat).
# Here, W.hat = 0.5, and an IPW-based estimate of RATE is:
IPW.scores <- ifelse(W[test] == 1, Y[test] / 0.5, -Y[test] / 0.5)
rate.ipw <- rank_average_treatment_effect.fit(IPW.scores, cate.hat)
rate.ipw
# IPW-based estimators typically have higher variance. For details on
# score constructions for other causal estimands, please see the RATE paper.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.