mrVip: Calculates and helps interpret variable importance for...

View source: R/mrVip.R

mrVipR Documentation

Calculates and helps interpret variable importance for mrIML models.

Description

Summarizes variable importance in a mrIML model at both a global (across all the response models) and local (for individual response models) level. This can be done for a plain mrIML model or bootstrap results obtained from mrBootstrap().

Usage

mrVip(
  mrIMLobj,
  mrBootstrap_obj = NULL,
  threshold = 0.1,
  global_top_var = 10,
  local_top_var = 5,
  taxa = NULL,
  model_perf = NULL
)

Arguments

mrIMLobj

A list object output by mrIMLpredicts().

mrBootstrap_obj

A list of bootstrap results output by mrBootstrap().

threshold

The performance threshold for response models (AUC for classification and R2 for regression). Only response models that meet this performance criterion are plotted.

global_top_var

The number of top global variables to display (default: 10).

local_top_var

The number of top local variables for each response to display (default: 5).

taxa

A character string identifying which response model should be plotted.

model_perf

A list object containing model performance metrics output by mrIMLperformance(). If not supplied, then mrIMLperformance() is run inside mrvip() to get performance metrics.

Value

A list containing:

  • ⁠$vi_data⁠: Variable importance data in its raw form (including bootstrap samples if mrBootstrap_obj was supplied).

  • ⁠$vi_tbl⁠: Variable importance data point estimates.

  • ⁠$vi_plot⁠: A grouped plot of the most important variables both globally and for the individual response models.

Examples

library(tidymodels)

# Without bootstrap
data <- MRFcov::Bird.parasites
Y <- data %>%
  select(-scale.prop.zos) %>%
  select(order(everything()))
X <- data %>%
  select(scale.prop.zos)

model_rf <- rand_forest(
  trees = 50, # 50 trees are set for brevity. Aim to start with 1000
  mode = "classification",
  mtry = tune(),
  min_n = tune()
) %>%
  set_engine("randomForest")

mrIML_rf <- mrIMLpredicts(
  X = X,
  Y = Y,
  X1 = Y,
  Model = model_rf,
  prop = 0.7,
  k = 2,
  racing = FALSE
)

mrVip(mrIML_rf, taxa = "Plas")

# With bootstrap

mrIML_rf_boot <- mrIML_rf %>%
  mrBootstrap(num_bootstrap = 5)
  
mrIML_rf_vip <- mrVip(
  mrIML_rf,
  mrBootstrap_obj = mrIML_rf_boot
)

mrIML_rf_vip


nfj1380/mrIML documentation built on June 2, 2025, 1:03 a.m.