mrFlashlight: Convert mrIML object into a 'flashlight' object

View source: R/MrFlashLight.R

mrFlashlightR Documentation

Convert mrIML object into a flashlight object

Description

A wrapper function around flashlight::flashlight() to run multi-response model-agnostic interpretable machine learning analyses. The output can be interrogated using the core functionality of flashlight: see vignette("flashlight", package = "flashlight").

Usage

mrFlashlight(mrIMLobj, response = "multi", index = 1, predict_function = NULL)

Arguments

mrIMLobj

A list object output by mrIMLpredicts().

response

A character string indicating the type of response: "single" selects one response (indicated by index) and "multi" selects all responses.

index

A numeric value used when response is "single" to select which response column in the data to create a flashlight object for.

predict_function

A function specifying a user-defined prediction function (optional).

Value

A flashlight or multi-flashlight object.

Examples

library(tidymodels)
library(flashlight)

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
)

fl <- mrFlashlight(
  mrIML_rf,
  response = "multi",
  index = 1
)

# Performance comparison
fl %>%
  light_performance(
    metrics = list(`ROC AUC` = MetricsWeighted::AUC)
  ) %>%
  plot() +
  ylim(0, 1)

# Partial dependence curves
fl %>%
  light_profile(data = cbind(X, Y), "scale.prop.zos") %>%
  plot()

# Two-way partial dependence
fl %>%
  light_profile2d(c("scale.prop.zos", "Plas")) %>%
  plot()


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