View source: R/rpart-functions.R
avg_characteristics_rpart | R Documentation |
Computes the average characteristics of units in each leaf of an rpart
object.
avg_characteristics_rpart(tree, X)
tree |
An |
X |
Covariate matrix (no intercept). |
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.
A list storing each regression as an lm_robust
object.
Riccardo Di Francesco
Di Francesco, R. (2022). Aggregation Trees. CEIS Research Paper, 546. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.2139/ssrn.4304256")}.
causal_ols_rpart
, estimate_rpart
## 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.