01 / 20

ROC Curves &
AUC

Learn how to evaluate diagnostic and classification models using Receiver Operating Characteristic curves and the Area Under the Curve.

Biostatistics

What Problem Are We Solving?

Imagine a blood test that predicts whether a patient has a disease. It returns a probability score between 0 and 1. But how do you decide the cutoff: at what score do you say "positive"?

Choose too low a cutoff and you flag healthy people as sick (false positives). Choose too high and you miss truly sick patients (false negatives). The ROC curve shows you every possible cutoff at once.

Key Vocabulary

Sensitivity (TPR)
Proportion of actual positives correctly identified: \(\text{TPR} = \frac{TP}{TP + FN}\)
1 − Specificity (FPR)
Proportion of actual negatives wrongly flagged: \(\text{FPR} = \frac{FP}{FP + TN}\)
Threshold
The cutoff probability above which the model predicts "positive."
AUC
Area Under the ROC Curve: a single number summarizing overall performance.

The Confusion Matrix

Every threshold produces a \(2 \times 2\) table of outcomes. The ROC curve is built by computing TPR and FPR from this table at each possible threshold.

Predicted
Positive
Negative
Actual
Positive
Negative
TP FN FP TN
\(\text{TPR} = \frac{TP}{TP + FN}\)
\(\text{FPR} = \frac{FP}{FP + TN}\)

How an ROC Curve Is Built

1
Rank all subjects by their predicted probability from high to low.
2
Sweep the threshold from 1.0 down to 0.0. At each threshold, compute \(\text{TPR}\) and \(\text{FPR}\).
3
Plot each pair as a point on the graph: \(x = \text{FPR}\), \(y = \text{TPR}\).
4
Connect the dots to form the ROC curve from (0, 0) to (1, 1).

Anatomy of an ROC Curve

False Positive Rate (FPR)
True Positive Rate (TPR)
0 0.25 0.50 0.75 1.0 0 0.25 0.50 0.75 1.0
Random (\(\text{AUC} = 0.5\))
Perfect (0, 1)
AUC ≈ 0.92

What Is AUC?

The Area Under the Curve (AUC) compresses the entire ROC curve into a single number between 0 and 1:

Probabilistic interpretation: AUC equals the probability that a randomly chosen positive case is ranked higher than a randomly chosen negative case by the model.

AUC = 1.0
Perfect discrimination: the model always ranks positives above negatives.
AUC = 0.5
No discrimination: equivalent to flipping a coin.
\(\text{AUC} < 0.5\)
Worse than random: the model's predictions are inverted.

Sensitivity vs. Specificity

Moving along the ROC curve corresponds to changing the threshold. Every gain in sensitivity comes at a cost in specificity:

Low Threshold High Threshold
Sensitivity (TPR) High Low
Specificity (\(1 - \text{FPR}\)) Low High
False Positives Many Few
False Negatives Few Many
Clinical Example Cancer screening Confirmatory test

ROC vs. Precision-Recall

Both curves evaluate classifiers, but they shine in different scenarios.

ROC Curve Precision-Recall Curve
Y-axis TPR (Sensitivity) Precision (PPV)
X-axis FPR Recall (TPR)
Best for Balanced classes Imbalanced classes
Random baseline Diagonal line Horizontal at prevalence
Affected by prevalence? No Yes

How to Apply ROC Analysis

1
Collect predictions: obtain the predicted probability for each subject from your model.
2
Compute TPR and FPR at every distinct threshold (or use software to sweep automatically).
3
Plot the ROC curve and compute \(\text{AUC}\) using the trapezoidal rule or a statistical package.
4
Compare models: a higher AUC means better overall discrimination. Use a DeLong test for statistical comparison.
5
Choose the optimal threshold using the Youden index: \(J = \text{TPR} - \text{FPR}\), maximized.

Example 1: Small Dataset

A test assigns probabilities to 6 patients. Actual disease status is known. Let us compute two points on the ROC curve.

Patient Prob. Actual
A0.95+
B0.80+
C0.60−
D0.50+
E0.30−
F0.10−

Example 1: More Thresholds

Sweeping the threshold across all distinct probability values produces the full curve:

Threshold TPR FPR
1.0000
0.95\(\frac{1}{3}\)0
0.80\(\frac{2}{3}\)0
0.60\(\frac{2}{3}\)\(\frac{1}{3}\)
0.50\(\frac{3}{3}\)\(\frac{1}{3}\)
0.30\(\frac{3}{3}\)\(\frac{2}{3}\)
0.10\(\frac{3}{3}\)\(\frac{3}{3}\)

Example 2: Comparing Two Models

FPR
TPR
0 0.5 1.0 0 0.5 1.0
Model A: AUC ≈ 0.92
Model B: AUC ≈ 0.72

Choosing the Optimal Threshold

The Youden Index identifies the threshold that maximizes the vertical distance between the ROC curve and the diagonal:

This index identifies the threshold that gives the best performance when sensitivity and specificity are considered equally important. Geometrically, it's the point on the curve furthest vertically from the diagonal line. However, in clinical practice, the chosen threshold may differ from the Youden optimum because:

Cost asymmetry
Missing a cancer (FN) may be far worse than a false alarm (FP), pushing the threshold lower.
Prevalence
In rare diseases, even a small FPR causes many false positives in the population.

Common Mistakes

✕ Thinking AUC is Accuracy
AUC measures ranking ability, not the fraction of correct predictions (i.e., accuracy). A model can have high AUC but poor accuracy at a specific threshold.
✕ Ignoring Class Imbalance
With 99% negatives, ROC can look great while precision is terrible. Check the precision-recall curve too.
✕ Comparing AUCs Visually
Two curves can cross, meaning one model is better at high sensitivity and the other at high specificity. AUC alone may hide this.

Question 1 of 5

A diagnostic test has an AUC of 0.5. What does this mean?

Question 2 of 5

On an ROC curve, what does the y-axis represent?

Question 3 of 5

A model's ROC curve passes through the point (0.1, 0.85). At that threshold, what is the sensitivity?

Question 4 of 5

When would a Precision-Recall curve be preferred over an ROC curve?

Question 5 of 5

The Youden Index \(J\) is defined as: