mrPerformancePlot: Plot Model Performance Comparison

View source: R/mrPerformancePlot.R

mrPerformancePlotR Documentation

Plot Model Performance Comparison

Description

Create visualizations to compare the performance of two models based on their performance metrics generated by mrIMLperformance.

Usage

mrPerformancePlot(
  ModelPerf1 = NULL,
  ModelPerf2 = NULL,
  mode = "classification"
)

Arguments

ModelPerf1, ModelPerf2

Two data frames of model performance metrics to compare. The data frames are created by mrIMLperformance, see Examples.

mode

A character string describing the mode of the models. Should be either "regression" or "classification". The default is "classification".

Value

A list containing:

  • ⁠$performance_plot⁠: A box plot of model performance metrics.

  • ⁠$performance_diff_plot⁠: A bar plot of the differences in performance metrics.

  • ⁠$performance_diff_df⁠: A data frame in wide format containing model performance metrics and their differences.

Examples

library(tidymodels)

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

# Specify a random forest tidy model
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")
model_lm <- logistic_reg()

MR_perf_rf <- mrIMLpredicts(
  X = X,
  Y = Y,
  Model = model_rf,
  prop = 0.7,
  k = 2,
  racing = FALSE
) %>%
  mrIMLperformance()
MR_perf_lm <- mrIMLpredicts(
  X = X,
  Y = Y,
  Model = model_lm,
  prop = 0.7,
  k = 2,
  racing = FALSE
) %>%
  mrIMLperformance()

perf_comp <- mrPerformancePlot(
  ModelPerf1 = MR_perf_rf,
  ModelPerf2 = MR_perf_lm
)

perf_comp[[1]]
perf_comp[[2]]
perf_comp[[3]]


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