Plot a gg_vimp object, extracted variable importance of a rfsrc object
Source: R/plot.gg_vimp.R
plot.gg_vimp.RdDraws a horizontal bar chart of the VIMP scores extracted by
gg_vimp. Each bar represents one predictor; bar length is
proportional to its permutation VIMP, the average rise in OOB prediction
error when that predictor's OOB values are randomly shuffled. Predictors
are sorted in descending order of importance so the most influential
variables appear at the top.
Usage
# S3 method for class 'gg_vimp'
plot(x, relative = FALSE, lbls, labels = NULL, ...)Arguments
- x
- relative
If
TRUE, plot relative VIMP: each variable's VIMP divided by the largest VIMP in itsset, so the top variable reads 1 (for classification, the top variable within each class). A set with no positive VIMP is divided by its largest absolute VIMP instead, and an all-zero set stays at zero. Defaults toFALSE, raw VIMP.- lbls
Deprecated as of v4.0.0; use
labels. A named character vector of alternative variable labels.- labels
Optional variable labels for the variable axis. One of: a named character vector (
c(bpd_last = "BP Diastole")); a labelled data frame, whoseattr(col, "label")values are read; or a two-columnkey/labeldata frame. Variables with no label keep their raw name. Defaults toNULL(raw names).- ...
optional arguments passed to gg_vimp if necessary
Details
Bars are colored by the positive flag: a bar at or below zero
(non-positive VIMP) is color-coded differently to flag predictors that
hurt OOB accuracy when their signal is removed, usually a sign of
collinearity or a very noisy variable. In a well-behaved forest most bars
are positive; the color distinction matters when a handful are not.
References
Breiman L. (2001). Random forests, Machine Learning, 45:5-32.
Ishwaran H. and Kogalur U.B. (2007). Random survival forests for R, Rnews, 7(2):25-31.
Ishwaran H, Kogalur U (2026). Fast Unified Random Forests for Survival, Regression, and Classification (RF-SRC). R package version 3.6.2. https://cran.r-project.org/package=randomForestSRC
Examples
## ------------------------------------------------------------
## classification example
## ------------------------------------------------------------
## -------- iris data
rfsrc_iris <- randomForestSRC::rfsrc(Species ~ ., data = iris, ntree = 50)
gg_dta <- gg_vimp(rfsrc_iris)
#> Warning: rfsrc object does not contain VIMP information. Calculating...
plot(gg_dta)
## ------------------------------------------------------------
## regression example
## ------------------------------------------------------------
## -------- air quality data
rfsrc_airq <- randomForestSRC::rfsrc(Ozone ~ ., airquality, ntree = 50)
gg_dta <- gg_vimp(rfsrc_airq)
#> Warning: rfsrc object does not contain VIMP information. Calculating...
plot(gg_dta)