EnsemTree | R Documentation |
Build and/or predict on an ensemble regression tree.
EnsemTree(
coord_id,
aug_df,
site,
covars,
honest = FALSE,
is_pred = FALSE,
myfit = NULL,
leaves_tab = NULL,
...
)
coord_id |
Site index for coordinating site. |
aug_df |
The augmented data frame used to fit an ensemble tree ('data.table'). |
site |
Variable name for site indicator. |
covars |
A vector of covariate names used. |
honest |
Whether to use honest splitting (i.e., subsample splitting). Default is FALSE. |
is_pred |
Whether to build an ensemble tree or make prediction. Default is FALSE. |
myfit |
A fitted ensemble tree (for prediction purpose). Default is NULL. |
leaves_tab |
A table indicates leaf assignments in a fitted ensemble tree (for prediction purpose). Default is NULL. |
\dots |
Additional arguments for building the tree. |
Training: return a fitted ensemble tree and estimation of the input data; Prediction: return predictions of the input data.
data(SimDataLst)
K <- length(SimDataLst)
covars <- grep("^X", names(SimDataLst[[1]]), value=TRUE)
fit_lst <- list()
for (k in 1:K) {
tmpdf <- SimDataLst[[k]]
# use your estimator of interest
fit_lst[[k]] <- grf::causal_forest(X=as.matrix(tmpdf[, covars, with=FALSE]),
Y=tmpdf$Y, W=tmpdf$Z)
}
coord_id <- 1
coord_test <- GenSimData(coord_id)
coord_df <- SimDataLst[[coord_id]]
aug_df <- GenAugData(coord_id, coord_df, fit_lst, covars)
res_et <- EnsemTree(coord_id, aug_df, "site", covars)
et_hat <- EnsemTree(coord_id, coord_test, "site", covars, is_pred=TRUE,
myfit=res_et$myfit, leaves_tab=res_et$leaves_tab)
res_et <- EnsemTree(coord_id, aug_df, "site", covars, honest=TRUE)
et_hat <- EnsemTree(coord_id, coord_test, "site", covars, honest=TRUE, is_pred=TRUE,
myfit=res_et$myfit, leaves_tab=res_et$leaves_tab)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.