Skip to contents

Compare mean predicted probability with observed frequency. Accepts binary labels and probabilities, named lists of paired samples, or individual observation records with observed, probability, and optional group. Named lists are aligned by name. Binary class identity and probability columns follow draw_roc(): positive names the event, and otherwise the second factor level is selected. Named probability columns identify their classes. Samples must share the same positive class.

Usage

draw_calibration(
  true_labels,
  predicted_prob = NULL,
  positive = NULL,
  ...,
  group = NULL,
  legend_position = "top",
  legend_placement = "outside",
  theme = NULL,
  width = NULL,
  height = NULL,
  element_id = NULL,
  filename = NULL
)

Arguments

true_labels

Factor, vector, list, or data frame: Binary labels or observation records.

predicted_prob

Optional Numeric vector, matrix, or list: Predicted probabilities.

positive

Optional Character: Positive class label.

...

Additional named settings for setup_CalibrationConfig().

group

Optional Character: Group column for observation records. When omitted, a column named group is used if present; explicit NULL pools rows.

legend_position

Character {"top", "bottom", "left", "right", "top-left", "top-right", "bottom-left", "bottom-right"}: Legend anchor. Top/bottom anchors use horizontal rows; left/right anchors use a vertical column. Corner anchors align within the top or bottom row.

legend_placement

Character {"outside", "inside"}: Relation to the plotting area. Outside placement reserves space for the complete legend; inside placement overlays the data. Neither setting adds a missing legend.

theme

Optional Theme: Chart theme.

width, height

Optional Numeric or Character: Widget dimensions.

element_id

Optional Character: HTML element identifier.

filename

Optional Character: Static output path, currently SVG.

Value

An ECharts htmlwidget with vector SVG export.

Statistical semantics

Bins are computed independently within each group. Equidistant bins partition the unit interval. Quantile bins use linear interpolation at positions (n - 1) * p + 1 in the sorted probabilities (R quantile type 7). Repeated boundaries are collapsed without splitting tied scores. Intervals include their lower boundary and exclude their upper boundary, except that the final interval includes its upper boundary. Constant probabilities form one bin. Empty bins are omitted; lines join the remaining bin means. Each point is the mean predicted probability and mean observed outcome in its bin. The Brier score is the mean squared probability error across all complete observations, before binning. It is not an average of bin errors. Missing pairs are removed together when na_rm is true; invalid finite ranges and infinite values are always rejected. A group with no complete observations is rejected. The probability rug uses those same complete observations and sits just inside the lower plotting edge. Both axes span zero to one. Display precision does not round plotted values. A one-bin curve remains visible as a point even in lines-only mode.

Examples

labels <- factor(c("no", "yes", "no", "yes"), levels = c("no", "yes"))
draw_calibration(labels, c(.1, .8, .4, .9), n_bins = 2L)