| gg_partial | R Documentation |
Takes the list returned by rfsrc::plot.variable(partial = TRUE) and
separates the variables into two data frames: one for continuous predictors
and one for categorical (factor-like) predictors. The split is controlled
by cat_limit: variables with more unique x-values than this threshold
are treated as continuous; all others are categorical.
gg_partial(part_dta, nvars = NULL, cat_limit = 10, model = NULL)
part_dta |
partial plot data from |
nvars |
how many of the partial plot variables to calculate |
cat_limit |
Categorical features are built when there are fewer than
|
model |
a label name applied to all features. Useful when combining multiple partial plot objects in figures. |
A named list with two elements:
data.frame with columns x, yhat,
name (and optionally model) for continuous variables
data.frame with the same columns but with x
as a factor, for low-cardinality / categorical variables
gg_partial_rfsrc gg_partialpro
## Build a small regression forest on the airquality dataset
set.seed(42)
airq <- na.omit(airquality)
rf <- rfsrc(Ozone ~ ., data = airq, ntree = 50)
## Compute partial dependence via plot.variable (show.plots = FALSE to
## suppress the base-graphics output — we only want the data)
pv <- randomForestSRC::plot.variable(rf, partial = TRUE,
show.plots = FALSE)
## Split into continuous and categorical data frames
result <- gg_partial(pv)
head(result$continuous)
## Label this model for later comparison with a second forest
result_labelled <- gg_partial(pv, model = "airq_model")
unique(result_labelled$continuous$model)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.