avg_characteristics_rpart {aggTrees}R Documentation

Leaves Average Characteristics

Description

Computes the average characteristics of units in each leaf of an rpart object.

Usage

avg_characteristics_rpart(tree, X)

Arguments

tree

An rpart object.

X

Covariate matrix (no intercept).

Details

avg_characteristics_rpart regresses each covariate on a set of dummies denoting leaf membership. This way, we get the average characteristics of units in each leaf, together with a standard error.

Leaves are ordered in increasing order of their predictions (from most negative to most positive).

Standard errors are estimated via the Eicker-Huber-White estimator.

Value

A list storing each regression as an lm_robust object.

Author(s)

Riccardo Di Francesco

References

See Also

causal_ols_rpart, estimate_rpart

Examples

## Generate data.
set.seed(1986)

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)

## Construct a tree.
library(rpart)
tree <- rpart(y ~ ., data = data.frame("y" = y, X), maxdepth = 2)

## Compute average characteristics in each leaf.
results <- avg_characteristics_rpart(tree, X)
results


[Package aggTrees version 2.0.2 Index]