Accepts reference labels and predicted probabilities, matching lists of those
inputs, or a long table with recall, precision, and optional ap,
prevalence, class, split, fold, and omitted columns. Named input
lists are matched by name.
Usage
draw_pr(
true_labels,
predicted_prob = NULL,
positive = NULL,
...,
legend_position = "top",
legend_placement = "outside",
legend_title = NULL,
theme = NULL,
width = NULL,
height = NULL,
element_id = NULL,
filename = NULL
)Arguments
- true_labels
Factor, vector, list, or data frame: Reference labels or precision-recall records.
- predicted_prob
Optional Numeric vector, matrix, or list: Class probabilities.
- positive
Optional Character: Positive class for binary input.
- ...
Additional named settings for
setup_PRConfig().- 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.
- legend_title
Optional Character: Title drawn with the legend or colorbar: above left/right legends and vertical colorbars, before the first row of top/bottom legends and horizontal colorbars.
NULLdraws no title. A title does not add 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.
Details
Binary input uses the second factor level (second level after factor
conversion for nonfactors), unless positive names the desired class.
Precision and recall are defined on the positive class, so that choice
changes the curve. An unnamed probability vector/column describes that class.
Named columns identify their classes; multiclass matrices use names, or
factor-level order when unnamed. Multiclass curves are one-versus-rest.
Missing labels/scores are excluded separately for each curve and disclosed.
Scores must be probabilities in [0, 1]; direction is fixed, and tied scores
enter together. No observations are deduplicated, curves smoothed, or vertices
downsampled.
Legend placement
The shared top/outside layout reserves a horizontal band above the plot. Choose an inside corner to overlay the legend on the data.
Statistical semantics
Vertices are ordered by recall, then by decreasing precision, which is threshold order. Curves must include recall 0 and recall 1. Consecutive vertices are joined by steps: precision holds its value at each vertex back to the previous recall, so the area under the drawn curve is the average precision, \(\sum_k (R_k - R_{k-1}) P_k\). Precision is not linear in recall between two points of the curve, so a straight segment misstates the attainable values (Davis and Goadrich, 2006).
Supplied average precision is authoritative and may describe a
higher-resolution curve. Without an ap binding, the supplied vertices
define it. An undefined curve is represented by missing recall, precision,
and average precision and is reported in the console when omitted.
Per-resample legends report the unweighted mean and sample SD of average
precision over defined folds. SD is NA for one defined fold. Pooled average
precision is never inferred from per-fold values.
The chance level of a curve is the prevalence of its positive class, the expected precision of a classifier that scores independently of the label (Saito and Rehmsmeier, 2015). Prevalence differs by class and sample, so each curve group draws its own dotted baseline, in the group color, at the mean prevalence of its defined folds. The baseline toggles with its curves in the legend.
The legend uses the shared position and placement controls. Hover describes
the selected curve, including its resample identifier. Numeric tooltip labels
use digits; coordinates and summaries retain their full precision in the
compiled data.