Learn R Programming

OutcomeWeights (version 0.1.1)

get_outcome_weights.instrumental_forest: Outcome weights for the instrumental_forest function

Description

Post-estimation command to extract outcome weights for instrumental forest implemented via the instrumental_forest function from the grf package.

Usage

# S3 method for instrumental_forest
get_outcome_weights(object, ..., S, newdata = NULL, checks = TRUE)

Value

get_outcome_weights object with omega containing weights and treat the treatment

Arguments

object

An object of class instrumental_forest, i.e. the result of running instrumental_forest.

...

Pass potentially generic get_outcome_weights options.

S

A smoother matrix reproducing the outcome predictions used in building the instrumental_forest. Obtained by calling get_forest_weights() for the regression_forest object producing the outcome predictions.

newdata

Corresponds to newdata option in predict.instrumental_forest. If NULL, out-of-bag outcome weights, otherwise for those for the provided test data returned.

checks

Default TRUE checks whether weights numerically replicate original estimates. Only set FALSE if you know what you are doing and want to save computation time.

References

Athey, S., Tibshirani, J., & Wager, S. (2019). Generalized random forest. The Annals of Statistics, 47(2), 1148-1178.

Knaus, M. C. (2024). Treatment effect estimators as weighted outcomes, https://arxiv.org/abs/2411.11559.

Examples

Run this code
# \donttest{
# Sample from DGP borrowed from grf documentation
n = 2000
p = 5
X = matrix(rbinom(n * p, 1, 0.5), n, p)
Z = rbinom(n, 1, 0.5)
Q = rbinom(n, 1, 0.5)
W = Q * Z
tau =  X[, 1] / 2
Y = rowSums(X[, 1:3]) + tau * W + Q + rnorm(n)

# Run outcome regression and extract smoother matrix
forest.Y = grf::regression_forest(X, Y)
Y.hat = predict(forest.Y)$predictions
outcome_smoother = grf::get_forest_weights(forest.Y)

# Run instrumental forest with external Y.hats
iv.forest = grf::instrumental_forest(X, Y, W, Z, Y.hat = Y.hat)

# Predict on out-of-bag training samples.
iv.pred = predict(iv.forest)$predictions

omega_if = get_outcome_weights(iv.forest, S = outcome_smoother)

# Observe that they perfectly replicate the original CLATEs
all.equal(as.numeric(omega_if$omega %*% Y), 
          as.numeric(iv.pred))

# }

Run the code above in your browser using DataLab