plot_calibration: Probability Calibration Curve(s)

View source: R/plot_calibration.R

plot_calibrationR Documentation

Probability Calibration Curve(s)

Description

This functions plots probability calibration curves for one or several classifiers.

Usage

plot_calibration(
  obs,
  pred,
  pal_curves = "npg",
  title = ifelse(is.numeric(pred), "Calibration Curve", "Calibration Curves"),
  legend = "right",
  hover = FALSE
)

Arguments

obs

Vector of observed outcomes. Must be dichotomous. Can be numeric, logical, character, or factor. If numeric, obs must be coded 1 or 0. If character or factor, a warning will be issued clarifying that the first level is assumed to be the reference.

pred

Vector of predicted probabilities, or several such vectors organized into a data frame or list, optionally named. Must be numeric on [0, 1].

pal_curves

String specifying the color palette to use when plotting multiple vectors. Options include "ggplot", all qualitative color schemes available in RColorBrewer, and the complete collection of ggsci palettes. Alternatively, a character vector of colors with length equal to the number of vectors in dat.

title

Optional plot title.

legend

Legend position. Must be one of "bottom", "left", "top", "right", "bottomright", "bottomleft", "topleft", or "topright".

hover

Show predictor name by hovering mouse over ROC curve? If TRUE, the plot is rendered in HTML and will either open in your browser's graphic display or appear in the RStudio viewer.

Details

Calibration curves are a quick and easy way to evaluate a classifier's fit to the data. This function allows one or several models to be plotted in the same figure, with points sized by the number of observations that fall within the corresponding bin.

Examples

x1 <- runif(1000)
y <- rbinom(1000, size = 1, prob = x1)
plot_calibration(obs = y, pred = x1)

x2 <- rbeta(1000, shape1 = 5/2, shape2 = 3/2)
plot_calibration(obs = y, pred = list("Good" = x1, "Bad" = x2))


dswatson/bioplotr documentation built on March 3, 2023, 9:43 p.m.