Draw calibration plot
Usage
draw_calibration(
true_labels,
predicted_prob,
n_bins = 10L,
bin_method = c("quantile", "equidistant"),
binclasspos = 2L,
main = NULL,
subtitle = NULL,
xlab = "Mean predicted probability",
ylab = "Empirical risk",
show_marginal_x = TRUE,
marginal_x_y = -0.02,
marginal_col = NULL,
marginal_size = 10,
mode = "markers+lines",
show_brier = TRUE,
theme = choose_theme(getOption("rtemis_theme")),
filename = NULL,
...
)Arguments
- true_labels
Factor or list of factors with true class labels
- predicted_prob
Numeric vector or list of numeric vectors with predicted probabilities
- n_bins
Integer: Number of windows to split the data into
- bin_method
Character: "quantile" or "equidistant": Method to bin the estimated probabilities.
- binclasspos
Integer: Index of the positive class. The convention used in the package is the second level is the positive class.
- main
Character: Main title
- subtitle
Character: Subtitle, placed bottom right of plot
- xlab
Character: x-axis label
- ylab
Character: y-axis label
- show_marginal_x
Logical: Add marginal plot of distribution of estimated probabilities
- marginal_x_y
Numeric: y position of marginal plot
- marginal_col
Character: Color of marginal plot
- marginal_size
Numeric: Size of marginal plot
- mode
Character: "lines", "markers", "lines+markers": How to plot.
- show_brier
Logical: If TRUE, add Brier scores to trace names.
- theme
Themeobject.- filename
Character: Path to save output.
- ...
Additional arguments passed to draw_scatter
Examples
if (FALSE) { # interactive()
# Synthetic data with n cases
n <- 500L
true_labels <- factor(sample(c("A", "B"), n, replace = TRUE))
# Synthetic probabilities where A has mean 0.25 and B has mean 0.75
predicted_prob <- ifelse(true_labels == "A",
rbeta(n, 2, 6),
rbeta(n, 6, 2)
)
draw_calibration(true_labels, predicted_prob)
}