Learn R Programming

vip (version 0.1.2)

vip: Variable Importance Plots

Description

Plot variable importance scores for the predictors in a model.

Usage

vip(object, ...)

# S3 method for default vip(object, num_features = 10L, bar = TRUE, width = 0.75, horizontal = TRUE, alpha = 1, color = "grey35", fill = "grey35", size = 1, shape = 19, ...)

Arguments

object

A fitted model object (e.g., a "randomForest" object) or an object that inherits from class "vi".

...

Additional optional arguments to be passed onto vi.

num_features

Integer specifying the number of variable importance scores to plot. Default is 10.

bar

Logical indicating whether or not to produce a barplot. Default is TRUE. If bar = FALSE, then a dotchart is displayed instead.

width

Numeric value specifying the width of the bars when bar = TRUE. Default is 0.75.

horizontal

Logical indicating whether or not to plot the importance scores on the x-axis (TRUE). Default is TRUE.

alpha

Numeric value between 0 and 1 giving the transparency of the bars (bar = TRUE) or points (bar = FALSE).

color

Character string specifying the color to use for the borders of the bars. Could also be a function, such as heat.colors. Default is "grey35".

fill

Character string specifying the color to use to fill the bars. Could also be a function, such as heat.colors. Default is "grey35".

size

Numeric value indicating the size to use for the points whenever bar = FALSE. Default is 1.

shape

Numeric value indicating the shape to use for the points whenever bar = FALSE. Default is 1.

Examples

Run this code
# NOT RUN {
#
# A projection pursuit regression example
#

# Load the sample data
data(mtcars)

# Fit a projection pursuit regression model
model <- ppr(mpg ~ ., data = mtcars, nterms = 1)

# Construct variable importance plot
vip(model, method = "ice")

# Better yet, store the variable importance scores and then plot
vi_scores <- vi(model, method = "ice")
vip(vi_scores, bar = FALSE, size = 3, horiz = FALSE)

# The \code{\link[magrittr]{\%T>\%}} operator is imported for convenience
vi_scores <- model %>%
  vi(method = "ice") %T>%
  {print(vip(.))}
vi_scores
# }

Run the code above in your browser using DataLab