roc_plot: Produce a receiver operator characteristic plot for a set of...

View source: R/roc_plot.R

roc_plotR Documentation

Produce a receiver operator characteristic plot for a set of predicted probabilities for a binary classifier.

Description

Produce a receiver operator characteristic plot for a set of predicted probabilities for a binary classifier.

Usage

roc_plot(form, data, refline = TRUE, max_intervals = 1000)

Arguments

form

A formula where the left-hand side is the variable representing the observed outcome, 0 or 1, and the right-hand side represents the column names of the different model probabilities.

data

A data frame that contains at least two columns, one of which is the observed outcome and the others that are predicted probabilities.

refline

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

max_intervals

The maximum number of thresholds to evaluate. Default = 1000.

Examples

library(ranger)
library(palmerpenguins)
pp <- penguins[complete.cases(penguins),]
m1 <- ranger(species == 'Gentoo' ~ island + bill_length_mm + flipper_length_mm + body_mass_g + sex,
      data = pp, probability = TRUE)
p_obj <- predict(m1, data = pp)
results <- data.frame(preds_m1 = p_obj$predictions[,2],
                       obs = pp$species == 'Gentoo')
roc_plot(obs ~ preds_m1, data = results)

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