PlotForestImp: Importance plot of an ensemble forest

View source: R/PlotForestImp.R

PlotForestImpR Documentation

Importance plot of an ensemble forest

Description

Importance plot of an ensemble forest

Usage

PlotForestImp(myfit)

Arguments

myfit

A fitted ensemble forest.

Value

A ggplot2 object and a table of relative importance of each covariate.

Examples

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_df <- SimDataLst[[coord_id]]
aug_df <- GenAugData(coord_id, coord_df, fit_lst, covars)

## Treat each site as a distinct factor
myfit <- EnsemForest(coord_id, aug_df, "site", covars, importance="impurity")$myfit
PlotForestImp(myfit)

## Mean encoding as surrogate for site index
myfit <- EnsemForest(coord_id, aug_df, "site", covars, is_encode=TRUE)$myfit
PlotForestImp(myfit)



ellenxtan/ifedtree documentation built on March 28, 2023, 9:09 a.m.