estimate_rpart {aggTrees}R Documentation

GATE Estimation with rpart Objects


Replaces node predictions of an rpart object using external data to estimate the group average treatment effects (GATEs).


estimate_rpart(tree, y, D, X, method = "aipw", scores = NULL)



An rpart object.


Outcome vector.


Treatment assignment vector.


Covariate matrix (no intercept).


Either "raw" or "aipw", controls how node predictions are replaced.


Optional, vector of scores to be used in replacing node predictions. Useful to save computational time if scores have already been estimated. Ignored if method == "raw".


If method == "raw", estimate_rpart replaces node predictions with the differences between the sample average of the observed outcomes of treated units and the sample average of the observed outcomes of control units in each node, which is an unbiased estimator of the GATEs if the assignment to treatment is randomized.

If method == "aipw", estimate_rpart replaces node predictions with sample averages of doubly-robust scores in each node. This is a valid estimator of the GATEs in observational studies. Honest regression forests and 5-fold cross fitting are used to estimate the propensity score and the conditional mean function of the outcome (unless the user specifies the argument scores).

estimate_rpart allows the user to implement "honest" estimation. If observations in y, D and X have not been used to construct the tree, then the new predictions are honest in the sense of Athey and Imbens (2016). To get standard errors for the tree's estimates, please use causal_ols_rpart.


A tree with node predictions replaced, as an rpart object, and the scores (if method == "raw", this is NULL).


Riccardo Di Francesco


See Also

causal_ols_rpart avg_characteristics_rpart


## Generate data.

n <- 1000
k <- 3

X <- matrix(rnorm(n * k), ncol = k)
colnames(X) <- paste0("x", seq_len(k))
D <- rbinom(n, size = 1, prob = 0.5)
mu0 <- 0.5 * X[, 1]
mu1 <- 0.5 * X[, 1] + X[, 2]
y <- mu0 + D * (mu1 - mu0) + rnorm(n)

## Split the sample.
splits <- sample_split(length(y), training_frac = 0.5)
training_idx <- splits$training_idx
honest_idx <- splits$honest_idx

y_tr <- y[training_idx]
D_tr <- D[training_idx]
X_tr <- X[training_idx, ]

y_hon <- y[honest_idx]
D_hon <- D[honest_idx]
X_hon <- X[honest_idx, ]

## Construct a tree using training sample.
tree <- rpart(y ~ ., data = data.frame("y" = y_tr, X_tr), maxdepth = 2)

## Estimate GATEs in each node (internal and terminal) using honest sample.
new_tree <- estimate_rpart(tree, y_hon, D_hon, X_hon, method = "raw")

[Package aggTrees version 2.0.2 Index]