ENFR

ROC and AUC, explained for clinicians

What the curve is, how it is built cell by cell, and the one sentence that makes AUC stick.

In a hurry

A diagnostic test gives each patient a number: a marker level, an antibody titre, a risk score. AUC measures how well that number separates the sick from the healthy, before you commit to any cutoff. It has a plain reading: pick one sick patient and one healthy patient at random, and AUC is the probability the test gives the sick one the higher score. 0.5 is a coin toss, 1.0 never gets a pair wrong, and most useful clinical tests land between 0.75 and 0.95. The ROC curve is the picture behind that single number, and every point on it is one cutoff you could choose.

Want to move it yourself? The companion playground lets you drag the cutoff and watch all of this happen.

Open the ROC playground

It starts with a ranking

Forget positive and negative for a moment. A test that outputs a score does one thing: it ranks patients. Line them up from the highest score to the lowest, and a good test pushes the sick toward the top and the healthy toward the bottom. Everything about ROC and AUC follows from that order, and nothing follows from the exact scores. Here are six patients, three sick and three healthy, sorted by their score.

Six patients sorted by score, with the ROC staircase built on a 3 by 3 grid: step up for a diseased patient, right for a healthy one.

Six patients, sorted so the one with the highest score is at the top and the lowest at the bottom. D is a patient who has the disease, H a healthy one. Read the list from the top down: step up for each D, step right for each H. The staircase you trace is the ROC curve.

To turn that ranking into the curve, take a grid three cells tall, one row for each patient who has the disease, and three cells wide, one column for each healthy one. Start in the bottom-left corner and read the sorted list from the top, one step per patient: up for a diseased patient, right for a healthy one. Our list opens with the diseased patient scoring 0.91, so the first move is up. Next is a healthy one at 0.78, a step right. Then two diseased patients in a row, 0.66 and 0.55, two steps up that carry you to the top edge. The last two are healthy, 0.40 and 0.22, two steps right into the top-right corner. Six patients, six moves; and because there are exactly three of each, three ups and three rights, you land in the top-right corner whatever their order. What the order changes is the path between the two corners, and that path is the ROC curve.

The six clean steps assume every patient has a different score. Real tests produce ties, and the honest move is not to invent an order the test never gave. When several patients share the same score, you make one diagonal move instead of separate steps: up by the number of diseased patients in the tied group, right by the number of healthy ones. A batch the test cannot separate becomes a straight diagonal on the curve rather than a staircase, which is why real ROC curves are part staircase and part slope. Take it to the limit, where the test gives everyone the identical score, and the whole curve falls onto the diagonal with an area of 0.5, exactly the verdict such a test has earned.

What the area actually counts

Now the payoff. The grid holds three times three, nine cells, and each cell is one pairing of a sick patient with a healthy one. A cell sits below the staircase exactly when that sick patient was ranked above that healthy one, which is the test getting that pair right. Count them: seven of the nine are below the line.

××AUC = 7 / 9 ≈ 0.78

Each cell is one (sick, healthy) pair. Blue cells are pairs the test ordered correctly; the two crossed cells are the errors, where a healthy patient outscored a sick one.

So the area under the curve is not an abstract integral. It is the fraction of sick-and-healthy pairs the test ordered correctly, which is the same thing as the probability that a random sick patient outscores a random healthy one.

$$\text{AUC} = P\big(\text{score}_{\text{sick}} > \text{score}_{\text{healthy}}\big)$$

For these six patients AUC is 7/9, about 0.78. Two pairs went the wrong way, a healthy patient scoring above a sick one, twice. This is also the Mann-Whitney statistic, and in machine learning it is the standard score for a binary classifier, but the medical reading is the one to keep: how often the test ranks disease above health.

Try it: drag the patients

Here are seven new patients, four sick and three healthy, ranked from the highest score at the top. Drag a patient to change the ranking, or press a preset, and watch the staircase redraw. Four sick against three healthy makes twelve pairs, and a grid three cells wide by four tall.

highest score
lowest score
Shaded cells are pairs the current ranking orders correctly; crossed cells are the inversions, a healthy patient ranked above a sick one. AUC is the shaded share of the square.

Notice the grid is no longer square, though the outer square still is: both axes run from 0 to 1 whatever the mix. Each up-step is now 1/4 and each right-step 1/3, because four sick patients share the vertical axis and three healthy ones the horizontal. Change the mix and the cells change shape, but the area keeps the same reading: the fraction of correctly ordered pairs. And with thousands of patients instead of seven, the steps shrink until the staircase becomes the smooth curve you saw in the playground.

Three curves to keep in your head

AUC 10.5AUC 0FPRTPR

A perfect test hugs the top-left corner (area 1). A useless one follows the diagonal (about 0.5). A perfectly wrong test runs along the bottom (area 0); it is a real test with its labels flipped.

A perfect test ranks every sick patient above every healthy one, so its curve shoots up the left edge and along the top. A test that ranks at random wanders along the diagonal at about 0.5. Below 0.5 is not noise; it is a test that works, with its output pointing the wrong way.

A cutoff is a single point on the curve

The score ranks patients, but eventually you have to act: above this cutoff, call it positive; below, negative. Choosing that cutoff is choosing one point on the ROC curve. Its height is the sensitivity you get, the true positive rate; its distance from the left edge is the false positive rate, one minus the specificity. Slide the cutoff and the point slides along the curve, trading sensitivity for specificity. Where to sit on that trade is a clinical decision, not a statistical one, and it is exactly what the playground is built to let you feel.

One number ties the two views together. Fix a cutoff, turn the score into a plain positive or negative, and the ROC shrinks to three points. The area under that shrunken curve is (sensitivity + specificity) / 2, the balanced accuracy at that operating point, and it is never larger than the AUC of the full ranking.

What surprises people about AUC

AUC ignores the actual numbers. Square every score, take their logs, add 100: the order is unchanged, so the AUC is unchanged. It measures ranking, not calibration.
AUC can sit far above the best accuracy. A test can rank patients well overall and still, at any single cutoff, get only a modest share of individual calls right. Ranking and deciding are different jobs.
AUC does not depend on how common the disease is. It is a property of the test and stays put as prevalence changes. Whether a positive result is trustworthy is a separate question that does move with prevalence.
Gini is just AUC rescaled. Gini = 2 × AUC − 1 places a coin-toss test at 0 and a perfect one at 1. Credit scoring quotes Gini, medicine usually quotes AUC; the information is the same.
AUC from a small study is shakier than it looks. It is estimated from every sick-and-healthy pair, so a handful of patients means few pairs and a lot of luck. An AUC of 0.85 from forty patients and one from four thousand are not the same claim, and a small gap between two small-sample AUCs is mostly noise.

Want to see this go wrong in the real world? A sepsis model running in hundreds of hospitals was sold at an AUC of 0.83, measured at 0.63, and missed two thirds of the cases it was built to catch.

Read the full story

Common questions

How is the ROC curve actually built?

Rank every patient by their test score, then walk down the list: step up for each diseased patient and right for each healthy one. The staircase you trace is the ROC curve, and each corner is one possible cutoff.

Why does AUC equal the probability a sick patient outscores a healthy one?

The area under the staircase counts, out of all sick-and-healthy pairs, the fraction the test ordered correctly, sick above healthy. That fraction is exactly the probability that a random sick patient has the higher score, which is what AUC means.

Does the ROC grid have to be square?

No. The outer box is always a unit square, but the inner grid cells are only square when there are equal numbers of sick and healthy patients. With a different mix the steps have different heights and widths, yet the area keeps the same reading: the fraction of correctly ordered pairs.

Stat Exam Pro turns ROC, AUC and the rest of medical statistics into exam-style questions with worked answers, in English and French.

Get it on iPhone