mc_calib_plot: Produce a calibration plot for a set of predicted...

View source: R/mc_calib_plot.R

mc_calib_plotR Documentation

Produce a calibration plot for a set of predicted probabilities for a single model across multiple classes.

Description

Produce a calibration plot for a set of predicted probabilities for a single model across multiple classes.

Usage

mc_calib_plot(
  form,
  data,
  cuts = 10,
  refline = TRUE,
  smooth = FALSE,
  rug = FALSE
)

Arguments

form

A formula where the left-hand side is the set variable representing the observed outcomes for each class, 0 or 1. The right-hand side represents the column names of the different class probabilities. The names of the columns don't matter to the model, but the order of the observed (on the left) and predicted (on the right) should align.

data

A data frame that contains one observed and one predicted column for each class.

cuts

The number of bins of probabilities. Default = 10.

refline

Whether or not to include a 45 degree reference line. Default = TRUE.

smooth

Whether or not to include a smoothed line for each class' probabilities. Default = FALSE.

rug

Whether or not to include a rug plot of the observed probabilities. Usually works best with only one model. Default = FALSE.

Examples

library(ranger)
library(palmerpenguins)
pp <- penguins[complete.cases(penguins),]
m1 <- ranger(species ~ island + bill_length_mm + sex,
      data = pp, probability = TRUE)
p_obj <- predict(m1, data = pp)
results <- data.frame(p_obj$predictions, ohe(pp$species, drop_ref = FALSE))
mc_calib_plot(pp.species_Adelie + pp.species_Chinstrap + pp.species_Gentoo ~
      Adelie + Chinstrap + Gentoo,
      data = results, cuts = 4)

gweissman/gmish documentation built on Feb. 21, 2025, 1:20 a.m.