roc_curve: ROC curve coordinates

View source: R/roc_curve.R

roc_curveR Documentation

ROC curve coordinates

Description

Compute the points of one or more ROC curves from true labels and predicted probabilities, returning tidy ⁠(class, fpr, tpr, auc)⁠ rows. The rows serve any consumer of the curve data, such as a client that renders the curve.

Usage

roc_curve(true_labels, predicted_prob, max_points = NULL)

Arguments

true_labels

Factor: True outcome labels.

predicted_prob

Numeric vector or matrix [0, 1]: Predicted probabilities for the positive class (second level of true_labels), as a vector or a one-column matrix. For multiclass, a matrix with exactly one column per class, in factor-level order (rtemis's convention); the columns are labeled with the factor levels regardless of any names on the input.

max_points

Optional Integer [2, Inf): Cap on the number of vertices per curve. NULL keeps full resolution.

Details

Binary problems yield a single curve for the positive class (the second level of true_labels, rtemis convention); multiclass problems yield one one-vs-rest curve per class. Points are ordered along the curve; pass max_points to down-sample very long curves (one vertex per distinct score) to a compact, smooth line.

Value

data.frame with columns class, fpr, tpr, auc (the AUC is constant within a class group, repeated per vertex). Zero rows when no curve is defined.

Author(s)

EDG

Examples

true_labels <- factor(c("A", "B", "A", "A", "B", "A", "B", "B", "A", "B"))
predicted_prob <- c(0.1, 0.4, 0.35, 0.8, 0.65, 0.2, 0.9, 0.55, 0.3, 0.7)
roc_curve(true_labels, predicted_prob)

rtemis documentation built on Oct. 20, 2026, 1:06 a.m.