Learn R Programming

grmtree (version 0.1.0)

plot.varimp: Plot Variable Importance

Description

Creates a bar plot of variable importance scores with options for both ggplot2 and base R graphics.

Usage

# S3 method for varimp
plot(x, top_n = NULL, use_ggplot = TRUE, ...)

Value

Invisibly returns the input object.

Arguments

x

A varimp object from varimp().

top_n

Number of top variables to display (NULL for all).

use_ggplot

Logical indicating whether to use ggplot2 (if available).

...

Additional arguments passed to plotting functions.

See Also

varimp calculates the variable importance for GRM Forest, grmforest for GRM Forests, grmforest.control creates a control object for grmforest, plot.grmtree creates plot for the grmtree object

Examples

Run this code
# \donttest{
 library(grmtree)
 library(hlt)
 data("asti", package = "hlt")
 asti$resp <- data.matrix(asti[, 1:4])

 # Fit forest with default parameters
 forest <- grmforest(resp ~ gender + group, data = asti)
 imp <- varimp(forest)
 plot(imp)
 plot(imp, top_n = 1) ## select top 1 importance variable
 plot(imp, use_ggplot = FALSE) # Use base R graphics
# }

Run the code above in your browser using DataLab