predict.instrumental_forest function

Predict with an instrumental forest

Predict with an instrumental forest

Gets estimates of tau(x) using a trained instrumental forest.

## S3 method for class 'instrumental_forest' predict( object, newdata = NULL, num.threads = NULL, estimate.variance = FALSE, ... )

Arguments

  • object: The trained forest.
  • newdata: Points at which predictions should be made. If NULL, makes out-of-bag predictions on the training set instead (i.e., provides predictions at Xi using only trees that did not use the i-th training example). Note that this matrix should have the number of columns as the training matrix, and that the columns must appear in the same order.
  • num.threads: Number of threads used in prediction. If set to NULL, the software automatically selects an appropriate amount.
  • estimate.variance: Whether variance estimates for τ^(x)\hat\tau(x) are desired (for confidence intervals).
  • ...: Additional arguments (currently ignored).

Returns

Vector of predictions, along with (optional) variance estimates.

Examples

# Train an instrumental forest. 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) iv.forest <- instrumental_forest(X, Y, W, Z) # Predict on out-of-bag training samples. iv.pred <- predict(iv.forest) # Estimate a (local) average treatment effect. average_treatment_effect(iv.forest)
  • Maintainer: Erik Sverdrup
  • License: GPL-3
  • Last published: 2024-11-15