ROC Curves for Diagnostic Tests

The trade-off between sensitivity and specificity as the cut-off of a continuous test moves. The empirical ROC curve; the area under it as the probability that a person with the condition scores higher than one without, computed as the Mann-Whitney statistic; its standard error by Hanley and McNeil, by DeLong's method and by the bootstrap; comparing two tests on the same patients; and choosing the cut-off by Youden's index or by expected cost. Worked on HbA1c, BMI and age as screens for a diabetic fasting glucose in NHANES adults.

The ROC curve plots sensitivity against the false positive rate over every cut-off of a continuous test, and its area is proved here to be $P(X > Y) + \tfrac12 P(X = Y)$ for a random case $X$ and non-case $Y$, the Mann–Whitney statistic over $n_1 n_0$. For HbA1c against a fasting glucose of 126 mg/dL or more, in 1,975 undiagnosed NHANES 2017 to 2018 adults, the area is 0.889 (DeLong 95% interval 0.855 to 0.924), against 0.657 for BMI and 0.676 for age on the 1,942 with a BMI. Its precision is set by the 115 cases, and tests on the same people need the paired comparison. Youden's index picks a cut-off of 6.0%; minimum expected cost at this prevalence picks 6.8% for equal costs and 5.5% when a miss costs fifty times as much.

At the American Diabetes Association's threshold of 6.5% (ADA, 2025), HbA1c catches 47.0% of the adults whose fasting plasma glucose (FPG) is in the diabetic range and clears 98.7% of the others. But 6.5% is one choice among many. Lowering the threshold catches more cases and flags more people without the condition. How good is HbA1c as a measurement, apart from any one threshold, and where should the threshold go? The first question has a single answer, an area of 0.889 under a curve. The second does not: the best threshold depends on how common the condition is and on what each kind of error costs.

Sensitivity and Specificity found those two numbers at 6.5%. Likelihood Ratios for Diagnostic Tests found evidence for the condition in HbA1c values well below the threshold. The receiver operating characteristic (ROC) curve displays the trade-off for every possible threshold at once. The area under it summarizes how well the measurement separates the two groups, regardless of where the threshold is put.

ROC graphs come from signal detection theory, where they plotted the rate of hits against the rate of false alarms (Fawcett, 2006, §1). The library's Binary Classification Metrics introduces the ROC curve for a machine-learning classifier and works a small example by hand. This article develops the statistics a diagnostic study needs.

First we build the curve, including tied results. Then we prove that its area is a probability about pairs of people, the statistic of the Wilcoxon rank-sum test of a later unit. Next we compute its standard error three ways and compare HbA1c with two weaker screens. Finally we choose a cut-off, by Youden's index and by expected cost.

The data are the unit's 1,975 adults from the National Health and Nutrition Examination Survey (NHANES) 2017 to 2018. Of them, 115 have an FPG of 126 mg/dL or more, the reference definition used throughout.

From cut-offs to a curve

Call a result positive when the HbA1c is at or above a cut-off $c$. Each cut-off gives a sensitivity, the true positive rate $\mathrm{TPR}(c)$, and a false positive rate $\mathrm{FPR}(c) = 1 - \mathrm{Sp}(c)$:

Cut-off TP (of 115) Sensitivity FP (of 1,860) False positive rate $\mathrm{Se} + \mathrm{Sp} - 1$
5.5% 109 0.948 944 0.508 0.440
5.7% 98 0.852 595 0.320 0.532
5.9% 91 0.791 303 0.163 0.628
6.0% 86 0.748 217 0.117 0.631
6.2% 72 0.626 90 0.048 0.578
6.5% 54 0.470 25 0.013 0.456
6.8% 39 0.339 7 0.004 0.335
7.0% 28 0.243 4 0.002 0.241

As the cut-off falls, both rates can only rise, because every person positive at a higher cut-off is still positive at a lower one. Plotting $\mathrm{TPR}$ against $\mathrm{FPR}$ for every cut-off gives the ROC curve.

  • It runs from $(0, 0)$, where the cut-off is above every value and nobody is positive, to $(1, 1)$, where everybody is.
  • A test that carries no information about the condition has the same distribution in both groups. Each cut-off flags the same fraction of each, and its curve is the diagonal.
  • A perfect test reaches $(0, 1)$: all cases found, with no false positives.
ROC curves of three measurements as screens for an FPG of 126 mg/dL or more, on the 1,942 adults with all three recorded; the two marked points on the HbA1c curve are the ADA cut-off of 6.5% and the cut-off of 6.0% that maximizes Youden's index. Notice how far HbA1c bows toward the top left (area 0.887), while age and BMI, risk factors rather than measurements of glucose, stay much closer to the dotted diagonal of an uninformative test.
ROC curves of three measurements as screens for an FPG of 126 mg/dL or more, on the 1,942 adults with all three recorded; the two marked points on the HbA1c curve are the ADA cut-off of 6.5% and the cut-off of 6.0% that maximizes Youden's index. Notice how far HbA1c bows toward the top left (area 0.887), while age and BMI, risk factors rather than measurements of glucose, stay much closer to the dotted diagonal of an uninformative test.

Tied results

HbA1c is reported to one decimal place, so the 1,975 adults have only 48 distinct values, and the empirical curve has 49 points. At each value, cases and non-cases with that exact HbA1c switch from negative to positive together. The curve then moves diagonally: up by the share of cases at that value, and right by the share of non-cases. Joining the points with straight lines is the standard convention. Fawcett (2006, §5) explains the diagonal segment as the expected performance: the average of the curves from the most and the least favorable orderings of the tied results. The proof below shows that the area under it counts each tied pair as one half.

The area under the curve

A whole curve is hard to compare across tests. One number that summarizes it is the area under the ROC curve (AUC), which is 0.5 for an uninformative test and 1 for a perfect one. Its value has a direct interpretation, in terms of pairs of people.

Let $X$ be the result of a randomly chosen person with the condition, and $Y$ that of a randomly chosen person without it, independently. Here is the idea. Each step of the curve to the right is one non-case passing the cut-off. The height at that moment counts the cases already above it. So the area counts the pairs in which the case outranks the non-case.

Proposition. For the empirical ROC curve of $n_1$ cases and $n_0$ non-cases, with tied points joined by straight segments,

$$\mathrm{AUC} = \frac{1}{n_1 n_0}\sum_{i=1}^{n_1}\sum_{j=1}^{n_0}\left[\mathbf{1}(x_i > y_j) + \tfrac12\,\mathbf{1}(x_i = y_j)\right],$$

the proportion of case and non-case pairs in which the case has the higher result, counting ties as one half. It is the sample estimate of $P(X > Y) + \tfrac12 P(X = Y)$. As an effect size the same quantity is the probability of superiority of Effect Sizes and Standardized Differences.

Proof. List the distinct values from the highest down, $v_1 > v_2 > \cdots$. At $v_k$, let $a_k$ cases and $b_k$ non-cases have that value, and let $A_{k}$ be the number of cases with values above $v_k$. Lowering the cut-off past $v_k$ moves the curve right by $b_k/n_0$, from height $A_k/n_1$ to height $(A_k + a_k)/n_1$. The area under that segment is a trapezoid, its width times its average height:

$$\frac{b_k}{n_0}\cdot\frac{1}{n_1}\left(A_k + \frac{a_k}{2}\right) = \frac{1}{n_1 n_0}\left(b_k A_k + \tfrac12\,a_k b_k\right).$$

Each of the $b_k$ non-cases at $v_k$ is exceeded by exactly the $A_k$ cases above $v_k$, and tied with the $a_k$ cases at $v_k$. So $b_k A_k$ counts the pairs in which one of these non-cases is below a case, and $a_k b_k$ the pairs in which it is tied with one. Summing over $k$ counts every non-case once. The total area is therefore the number of pairs with the case higher, plus half the number tied, divided by $n_1 n_0$. $\square$

Back to the 1,975 adults. For HbA1c there are $115 \times 1{,}860 = 213{,}900$ case and non-case pairs. In 187,328 the case has the higher HbA1c, in 5,817 the two are tied, and in 20,755 the non-case is higher, so

$$\mathrm{AUC} = \frac{187{,}328 + 5{,}817/2}{213{,}900} = \frac{190{,}236.5}{213{,}900} = 0.8894.$$

The trapezoid area under the 49-point curve gives the same 0.8894. A randomly chosen adult with a diabetic fasting glucose has the higher HbA1c than a randomly chosen adult without one about 89% of the time, counting ties as half. Hanley and McNeil (1982) give this interpretation. The underlying result is that the area under the ROC curve equals the probability of correctly ranking a randomly chosen abnormal and normal case. They attribute it to Green and Swets's Signal Detection Theory and Psychophysics (1966).

The connection to the rank-sum test

The double sum is the Mann–Whitney statistic $U$ of The Wilcoxon Rank-Sum Test, computed for the cases. The AUC is $U/(n_1 n_0)$, the estimate of the probability that article calls $\theta$. Equivalently, rank all 1,975 HbA1c values together, with tied values sharing the mean of their ranks. The cases' ranks sum to $W = 196{,}906.5$, and $U = W - n_1(n_1 + 1)/2 = 196{,}906.5 - 6{,}670 = 190{,}236.5$. The script computes the AUC this way, which takes one sort instead of a quarter of a million comparisons.

Two consequences follow.

  • Testing for any discrimination is the rank-sum test. The null hypothesis $H_0\colon \mathrm{AUC} = 0.5$ says the measurement has no discriminating power. Here $W$ is 14.07 standard deviations above its null mean of 113,620 (with the correction for ties). The evidence is overwhelming, as it would be for any measurement this closely tied to the reference definition.
  • Only the order matters. The AUC depends on the results only through their order. Fawcett (2006, §7) states the equivalence with the Wilcoxon statistic for classifier scores.

Example (a change of units, and a change of prevalence). The AUC would not change if HbA1c were reported in mmol/mol instead of percent, or if its logarithm were used. Nor would it change in a population where the condition was twice as common, with the same two distributions. Any increasing transformation of the scale keeps every pair in the same order. And the AUC is a comparison between one case and one non-case, so the prevalence does not enter.

A single cut-off as a curve

A test reported only as positive or negative has a curve with one interior point, $(1 - \mathrm{Sp}, \mathrm{Se})$, joined to the corners.

Example (the area of a single cut-off). HbA1c dichotomized at 6.5% uses the same measurement as the full curve, but its area is much lower, 0.728 against 0.889. The curve has two straight segments, from $(0, 0)$ to $(f, \mathrm{Se})$ and from there to $(1, 1)$, where $f = 1 - \mathrm{Sp}$. The area under the first is a triangle, $\tfrac12 f\,\mathrm{Se}$, and under the second a trapezoid of width $1 - f$ and average height $\tfrac12(\mathrm{Se} + 1)$:

$$\tfrac12 f\,\mathrm{Se} + \tfrac12 (1 - f)(\mathrm{Se} + 1) = \tfrac12\big(f\,\mathrm{Se} + \mathrm{Se} + 1 - f\,\mathrm{Se} - f\big) = \tfrac12(\mathrm{Se} + 1 - f) = \frac{\mathrm{Se} + \mathrm{Sp}}{2}.$$

For HbA1c at 6.5% this is $(0.470 + 0.987)/2 = 0.728$, against 0.889 for the full measurement. Reporting only "positive" or "negative" discards a large part of the discriminating power. The quantity $2\,\mathrm{AUC} - 1 = \mathrm{Se} + \mathrm{Sp} - 1$ for one cut-off is Youden's index, which reappears below.

The precision of an AUC

The 0.889 comes from 115 cases and 1,860 non-cases, so it is an estimate. Its standard error is needed to report an interval or to compare tests, and there are three standard ways to get it.

Hanley and McNeil (1982) took the variance of $U/(n_1 n_0)$ from the theory of the Wilcoxon statistic:

$$\mathrm{SE}(\widehat{\mathrm{AUC}}) = \sqrt{\frac{A(1 - A) + (n_1 - 1)(Q_1 - A^2) + (n_0 - 1)(Q_2 - A^2)}{n_1 n_0}}.$$

Here $A$ is the AUC. $Q_1$ is the probability that two randomly chosen cases both rank above one randomly chosen non-case. $Q_2$ is the probability that one randomly chosen case ranks above two randomly chosen non-cases. $Q_1$ and $Q_2$ depend on the shapes of the two distributions.

Here is the idea of the formula in one sentence: the estimate is an average over all pairs of a case and a non-case, two pairs are related only when they share a person, and the three terms count the pairs that are identical, that share a non-case and that share a case.

The formal version. The derivation uses the covariance of two random variables and the variance of a sum, which Random Variables, Expectation and Variance develops in the next unit. Let $X_1, \ldots, X_{n_1}$ be the results of the cases and $Y_1, \ldots, Y_{n_0}$ those of the non-cases, all independent, the $X_i$ with one distribution and the $Y_j$ with another. Suppose first that ties have probability 0, and write $\psi_{ij} = 1$ if $X_i > Y_j$ and $\psi_{ij} = 0$ otherwise. Then $\widehat{\mathrm{AUC}} = \frac{1}{n_1 n_0}\sum_{i,j} \psi_{ij}$, each $\psi_{ij}$ has mean $A = P(X > Y)$, and the variance of the sum is the sum of the covariances of all ordered pairs of terms:

$$\operatorname{Var}(\widehat{\mathrm{AUC}}) = \frac{1}{(n_1 n_0)^2} \sum_{i,j} \sum_{k,l} \operatorname{Cov}(\psi_{ij}, \psi_{kl}).$$

The covariance of two terms depends only on which people they share.

  • No person in common ($i \ne k$ and $j \ne l$). The two terms are functions of different independent results, so they are independent and their covariance is 0.
  • The same pair ($i = k$, $j = l$). There are $n_1 n_0$ such terms. Each is the variance of a variable that is 1 with probability $A$ and 0 otherwise, $A(1 - A)$.
  • The same non-case, two cases ($j = l$, $i \ne k$). There are $n_1 n_0 (n_1 - 1)$ such ordered pairs of terms. The product $\psi_{ij}\psi_{kj}$ is 1 exactly when both cases exceed the non-case, so its mean is $Q_1$ and the covariance is $Q_1 - A^2$.
  • The same case, two non-cases ($i = k$, $j \ne l$). There are $n_1 n_0 (n_0 - 1)$ such ordered pairs. The product $\psi_{ij}\psi_{il}$ is 1 exactly when the case exceeds both non-cases, so its mean is $Q_2$ and the covariance is $Q_2 - A^2$.

Adding the three kinds of terms and dividing by $(n_1 n_0)^2$,

$$\operatorname{Var}(\widehat{\mathrm{AUC}}) = \frac{A(1 - A) + (n_1 - 1)(Q_1 - A^2) + (n_0 - 1)(Q_2 - A^2)}{n_1 n_0},$$

which is the square of the standard error above. The formula is exact for results without ties, whatever the two distributions. With ties, $\psi_{ij}$ takes the value $\tfrac12$ for a tied pair, and the same count goes through with $\operatorname{Var}(\psi)$ in place of $A(1 - A)$ and with $Q_1$ and $Q_2$ read as the means of the products $\psi_{ij}\psi_{kj}$ and $\psi_{ij}\psi_{il}$. The script confirms this general form against the exact variance, by listing every possible sample, in three small examples, two of them with ties.

The formula needs $Q_1$ and $Q_2$, which are not known. Hanley and McNeil used the approximations

$$Q_1 = \frac{A}{2 - A}, \qquad Q_2 = \frac{2A^2}{1 + A},$$

which hold exactly when the results follow exponential distributions.

Why the exponential model gives these. Suppose the non-cases' results have the exponential density $\lambda_0 e^{-\lambda_0 y}$ and the cases' results the density $\lambda_1 e^{-\lambda_1 x}$, for positive values, so that $P(Y > t) = e^{-\lambda_0 t}$ and $P(X > t) = e^{-\lambda_1 t}$. Averaging $P(X > y)$ over the non-cases' density,

$$A = \int_0^\infty \lambda_0 e^{-\lambda_0 y}\,e^{-\lambda_1 y}\,dy = \frac{\lambda_0}{\lambda_0 + \lambda_1}.$$

Two independent cases both exceed $y$ with probability $e^{-2\lambda_1 y}$, so

$$Q_1 = \int_0^\infty \lambda_0 e^{-\lambda_0 y}\,e^{-2\lambda_1 y}\,dy = \frac{\lambda_0}{\lambda_0 + 2\lambda_1}.$$

Dividing numerator and denominator by $\lambda_0 + \lambda_1$, and using $\lambda_1/(\lambda_0 + \lambda_1) = 1 - A$, gives $Q_1 = A/[A + 2(1 - A)] = A/(2 - A)$. Two independent non-cases both fall below $x$ with probability $(1 - e^{-\lambda_0 x})^2 = 1 - 2e^{-\lambda_0 x} + e^{-2\lambda_0 x}$, so

$$Q_2 = \int_0^\infty \lambda_1 e^{-\lambda_1 x}\,\big(1 - 2e^{-\lambda_0 x} + e^{-2\lambda_0 x}\big)\,dx = 1 - \frac{2\lambda_1}{\lambda_0 + \lambda_1} + \frac{\lambda_1}{2\lambda_0 + \lambda_1}.$$

The middle term is $2(1 - A)$. In the last, dividing by $\lambda_0 + \lambda_1$ gives $(1 - A)/(2A + 1 - A) = (1 - A)/(1 + A)$. So

$$Q_2 = 2A - 1 + \frac{1 - A}{1 + A} = \frac{(2A - 1)(1 + A) + 1 - A}{1 + A} = \frac{2A^2}{1 + A}.$$

Hanley and McNeil found that these approximations give standard errors close to those of other models, and slightly conservative in the range of areas of interest. With $A = 0.8894$, $Q_1 = 0.8008$ and $Q_2 = 0.8373$, and the standard error is 0.0202.

HbA1c does not follow the exponential model, and the data show the size of the approximation. Estimating the two probabilities directly from the 115 cases and 1,860 non-cases, with ties counted as one half, gives $Q_1 = 0.8067$ and $Q_2 = 0.8256$. The variance of $\psi$ is 0.0916, a little below $A(1 - A) = 0.0984$ because of the ties. With these in the variance formula the standard error is 0.0176. The difference from 0.0202 comes almost entirely from $Q_2$, which is multiplied by the number of non-cases.

DeLong, DeLong and Clarke-Pearson (1988) replaced the approximations with an estimate from the data. Each case $i$ gets a placement value $V_{10}(x_i)$, the fraction of non-cases it exceeds (ties counted as one half). Each non-case $j$ gets a value $V_{01}(y_j)$, the fraction of cases that exceed it. Both sets average to the AUC, and

$$\widehat{\mathrm{Var}}(\widehat{\mathrm{AUC}}) = \frac{s_{10}^2}{n_1} + \frac{s_{01}^2}{n_0},$$

with $s_{10}^2$ and $s_{01}^2$ the sample variances of the two sets of placement values. For HbA1c the standard error is 0.0177. The estimator is cited from DeLong, DeLong and Clarke-Pearson (1988), not derived here. Its connection with the formula above can be stated exactly. The placement value of a case is the probability that a non-case falls below it, and the variance of that probability over the cases is $Q_2 - A^2$. In the same way the variance of the non-cases' placement values is $Q_1 - A^2$. So $s_{10}^2/n_1$ and $s_{01}^2/n_0$ estimate the two large terms of the variance formula, $(n_0 - 1)(Q_2 - A^2)/(n_1 n_0)$ and $(n_1 - 1)(Q_1 - A^2)/(n_1 n_0)$, from the data and without a model. That is why DeLong's 0.0177 agrees with the 0.0176 found above from the estimated $Q_1$ and $Q_2$.

The bootstrap resamples the 115 cases and the 1,860 non-cases separately, with replacement, and recomputes the AUC each time (Bootstrap Confidence Intervals builds intervals for an AUC this way). With 2,000 resamples and 30 seeds, the median bootstrap standard error was 0.0176 (interquartile range 0.0173 to 0.0178).

DeLong's method and the bootstrap agree closely. The Hanley–McNeil formula is about 0.0025 larger; its authors found the exponential approximation slightly conservative for areas of 0.8 or more. The 95% interval from DeLong's standard error is $0.889 \pm 1.96 \times 0.0177 = (0.855, 0.924)$.

Example (doubling the non-cases). Suppose a study kept the same 115 cases but doubled the non-cases to 3,720. The standard error of the AUC would hardly shrink at all: from 0.0177 to 0.0176, if the new non-cases resemble the old. In DeLong's formula the cases' term is 0.00030 and the non-cases' term 0.000009, so the cases supply 97% of the variance. Even with infinitely many non-cases, which removes the second term, the standard error would still be 0.0174. The standard error is driven by the 115 cases far more than by the 1,860 non-cases. A study with few cases has an imprecise AUC however many non-cases it includes.

Comparing two tests

HbA1c is a far better screen than BMI or age. On the 1,942 adults whose BMI was recorded (113 cases), the AUCs and their DeLong standard errors are:

  • HbA1c, 0.887 (0.0180);
  • BMI, 0.657 (0.0244);
  • age, 0.676 (0.0216).

Example (a common misstatement: comparing two AUCs as if they were independent). Two AUCs are often compared with

$$z = \frac{\mathrm{AUC}_1 - \mathrm{AUC}_2}{\sqrt{\mathrm{SE}_1^2 + \mathrm{SE}_2^2}},$$

which is right when the two AUCs come from independent samples of patients. When both tests are measured on the same patients, as here and in most diagnostic studies, the two estimates are correlated. The variance of their difference is then $\mathrm{SE}_1^2 + \mathrm{SE}_2^2 - 2\,\mathrm{Cov}$. DeLong's method estimates the covariance from the same placement values, computed for each test on the same people. Hanley and McNeil (1983) gave an earlier correction based on the correlation between the tests.

Example (HbA1c against BMI). For HbA1c against BMI, the estimated correlation between the two AUCs is positive, 0.115, so the paired standard error of the difference is smaller than the unpaired one: a positive covariance is subtracted. The difference is $0.887 - 0.657 = 0.2307$. Its paired standard error is 0.0286, giving $z = 8.06$, against 0.0303 and $z = 7.61$ from the unpaired formula. The conclusion does not change here, because the difference is large.

For BMI against age the correlation is negative, $-0.254$. The difference, $-0.019$, has a paired standard error of 0.0365 ($z = -0.53$, $p = 0.599$): the two risk factors are about equally weak screens. A positive correlation, the usual case for two tests of the same condition, makes the unpaired formula too conservative. A negative one makes it too liberal.

Choosing the cut-off

The ROC curve shows the options. Choosing among them needs a criterion, and the two common ones give different answers.

Youden's index

Youden (1950) proposed rating a test by $J = \mathrm{Se} + \mathrm{Sp} - 1$, the vertical distance from the diagonal to the point on the curve. Choosing the cut-off that maximizes $J$ treats a point of sensitivity and a point of specificity as equally valuable. For HbA1c the maximum, $J = 0.6312$, is at 6.0% (sensitivity 0.748, false positive rate 0.117), with 5.9% close behind at 0.6284. The point closest to the corner $(0, 1)$, another common criterion, is 5.9% here. The ADA's 6.5% gives $J = 0.456$.

A cut-off chosen to maximize $J$ on a dataset gives an optimistic estimate of $J$ on that dataset. The reason is the same as for a model that looks better on its training data. At each fixed cut-off $c$ the sample value $\hat{J}(c)$ is an unbiased estimate of the true $J(c)$, being a difference of two sample proportions. The largest of the sample values is at least as large as the sample value at the truly best cut-off, so on average it is at least as large as the true maximum: the mean of $\max_c \hat{J}(c)$ is at least $\max_c J(c)$. The honest estimate comes from new data or cross-validation, as the library's Binary Classification Metrics illustrates. More basically, Youden's criterion ignores both the prevalence and the consequences of the two errors.

Expected cost

Here is the idea. Give each kind of error a cost, weight each by how often it happens in the population screened, and choose the cut-off with the smallest total.

The formal version. Suppose a missed case costs $C_{\mathrm{FN}}$ and a false positive costs $C_{\mathrm{FP}}$, in any common unit, and correct results cost nothing. Among adults screened, a fraction $\pi$ have the condition, and each is missed with probability $1 - \mathrm{TPR}(c)$. A fraction $1 - \pi$ do not, and each is flagged with probability $\mathrm{FPR}(c)$. The expected cost per adult screened is

$$\mathrm{Cost}(c) = \pi\,C_{\mathrm{FN}}\,[1 - \mathrm{TPR}(c)] + (1 - \pi)\,C_{\mathrm{FP}}\,\mathrm{FPR}(c).$$

Example (a common misstatement: a cost criterion without the prevalence). The cost of a cut-off is sometimes written as $c_1(1 - \mathrm{Se}) + c_2(1 - \mathrm{Sp})$, with a cost for each error rate and no prevalence. The two rates apply to groups of different sizes, so the expected cost per person weights them by $\pi$ and $1 - \pi$, as above. The difference is large here. Without the weights, equal costs make the criterion $(1 - \mathrm{Se}) + (1 - \mathrm{Sp}) = 1 - J$, whose minimum is at Youden's cut-off, 6.0%. With them, the equal-cost optimum in this population is 6.8%, as the table below shows.

The cost is linear in the two rates, so all points of ROC space with the same expected cost lie on a straight line. Setting the cost equal to a constant $K$ and solving for $\mathrm{TPR}$,

$$\mathrm{TPR} = 1 - \frac{K}{\pi\,C_{\mathrm{FN}}} + \frac{(1 - \pi)\,C_{\mathrm{FP}}}{\pi\,C_{\mathrm{FN}}}\,\mathrm{FPR},$$

a line of slope

$$m = \frac{(1 - \pi)\,C_{\mathrm{FP}}}{\pi\,C_{\mathrm{FN}}}.$$

A smaller cost $K$ gives a larger intercept, so lines further to the upper left have lower cost, and the best cut-off is where the highest such line touches the curve. Fawcett (2006, §6) calls these iso-performance lines and gives the same slope. When the condition is rare, $(1 - \pi)/\pi$ is large and the lines are steep. They then favor a strict cut-off with few false positives, unless missed cases are judged much more costly.

The slope of the ROC curve between two cut-offs is (change in TPR)/(change in FPR). Lowering the cut-off from $c_2$ to $c_1$ adds to the positives the results from $c_1$ up to $c_2$. So the change in TPR is the probability of such a result among the cases, the change in FPR is its probability among the non-cases, and their quotient is the likelihood ratio of that band of results, as defined in Likelihood Ratios for Diagnostic Tests. Problem 1 below checks this on the five bands of that article. The tangency condition therefore has a direct reading: call a result positive exactly when its likelihood ratio exceeds $m$. By the odds form of Bayes' theorem its post-test odds are its likelihood ratio times $\pi/(1 - \pi)$, so the condition says that the post-test odds exceed $m\,\pi/(1 - \pi) = C_{\mathrm{FP}}/C_{\mathrm{FN}}$. On a curve whose slope decreases steadily (a concave curve), this is the same as choosing the cut-off.

Example (equal costs). With the NHANES prevalence, $\pi = 0.0582$, and equal costs for the two errors, the best cut-off is stricter than the ADA's 6.5%. The slope is 16.17, so steep that the line touches the curve at 6.8%:

$C_{\mathrm{FN}} / C_{\mathrm{FP}}$ Slope $m$ Best cut-off Sensitivity False positive rate False positives per 1,000 Missed cases per 1,000
1 16.17 6.8% 0.339 0.004 3.5 38.5
5 3.23 6.2% 0.626 0.048 45.6 21.8
10 1.62 6.1% 0.687 0.073 68.4 18.2
50 0.32 5.5% 0.948 0.508 478.0 3.0
The HbA1c ROC curve (the left part, false positive rates up to 0.62) with the lowest-cost iso-cost line for three cost ratios. Watch the point of contact slide down the curve as a miss becomes more costly: at equal costs the steep line touches at a strict cut-off, 6.8%; at 10 times it touches at 6.1%; and at 50 times at 5.5%, where half of the adults without the condition are flagged.
The HbA1c ROC curve (the left part, false positive rates up to 0.62) with the lowest-cost iso-cost line for three cost ratios. Watch the point of contact slide down the curve as a miss becomes more costly: at equal costs the steep line touches at a strict cut-off, 6.8%; at 10 times it touches at 6.1%; and at 50 times at 5.5%, where half of the adults without the condition are flagged.

The table makes the role of prevalence concrete. With equal costs, the best rule flags almost nobody, because at 5.8% prevalence nearly every flagged person would otherwise be a false positive. It misses two thirds of the cases. Only when a missed case is judged several times as costly as an unnecessary confirmatory test does the best cut-off move into the range that a screening program would use.

Neither 6.0% (Youden) nor 6.5% (the ADA) is optimal for any of these cost ratios in this population. That is not a defect of either. A diagnostic threshold in a guideline must serve many populations and purposes at once, while the cost calculation answers one question for one population. What the calculation does show is that a cut-off is a decision. It depends on the prevalence, and on judgments of cost that statistics cannot supply.

A different criterion fixes one error rate and optimizes the other. Allowing at most 5% false positives, the most sensitive HbA1c cut-off is 6.2%, with sensitivity 0.626. The area under the part of the curve over a range of false positive rates is the partial AUC. It summarizes a test over that range when only strict cut-offs are of practical interest.

What the ROC curve does not show

The ROC curve inherits the properties of sensitivity and specificity, including their limits.

  • It does not depend on the prevalence. So it describes the test, but not what a positive result means for a patient. For that, the predictive values of Predictive Values and Bayes' Theorem are needed at the chosen cut-off.
  • It does depend on the spectrum of cases and non-cases. A curve from a study of severe cases and healthy controls lies above the curve the test will achieve in screening, for the reasons given in Sensitivity and Specificity.
  • Its area averages over all cut-offs, including those no one would use. Two tests with the same AUC can differ greatly in the region that matters.

Summary

Quantity Formula HbA1c
ROC point at cut-off $c$ $(\mathrm{FPR}(c), \mathrm{TPR}(c))$ 6.5%: (0.013, 0.470)
AUC $U/(n_1 n_0)$, $P(X > Y) + \tfrac12 P(X = Y)$ 0.889 (0.855, 0.924)
One cut-off as a curve $(\mathrm{Se} + \mathrm{Sp})/2$ 0.728 at 6.5%
Youden's index $\max_c [\mathrm{Se}(c) + \mathrm{Sp}(c) - 1]$ 0.631 at 6.0%
Iso-cost slope $(1 - \pi)\,C_{\mathrm{FP}}/(\pi\,C_{\mathrm{FN}})$ 16.2 for equal costs
Variance of the AUC $[A(1 - A) + (n_1 - 1)(Q_1 - A^2) + (n_0 - 1)(Q_2 - A^2)]/(n_1 n_0)$ SE 0.0176 to 0.0202

Worked problems

These problems are posed on the unit's own data, the 1,975 NHANES adults, and each is solved from the results above; none is taken from the course text. The script recomputes every number.

Problem 1. Report HbA1c only in the five bands of Likelihood Ratios for Diagnostic Tests, so that the test has five ordered results. The numbers of cases and non-cases in each band are:

Band Cases (of 115) Non-cases (of 1,860)
7.0% and over 28 4
6.5–6.9% 26 21
6.0–6.4% 32 192
5.7–5.9% 12 378
below 5.7% 17 1,265

Draw up the points of the ROC curve, find the slope of each segment, and compute the area under the curve in two ways.

The points. Lower the cut-off one band at a time, from "nobody positive" to "everybody positive." Each step adds the band's cases to the true positives and its non-cases to the false positives:

Positive if in or above TP TPR FP FPR Slope of the segment
(nobody) 0 0 0 0
7.0% and over 28 0.2435 4 0.0022 113.2
6.5–6.9% 54 0.4696 25 0.0134 20.0
6.0–6.4% 86 0.7478 217 0.1167 2.70
5.7–5.9% 98 0.8522 595 0.3199 0.513
below 5.7% 115 1 1,860 1 0.217

The slopes. The segment that ends at a row rises by the band's share of the cases and runs by its share of the non-cases. For the first band the slope is $(28/115)/(4/1{,}860) = 113.2$, and for the third it is $(32/115)/(192/1{,}860) = 2.70$. These are the likelihood ratios of the bands, as the section on expected cost stated. They decrease from one segment to the next, so this curve is concave.

The area by pairs. By the proposition, the area is the share of case and non-case pairs in which the case is in the higher band, plus half the share in which the two are in the same band. For each band, multiply its non-cases by the number of cases in higher bands, and by the number of cases in the same band:

Band Non-cases Cases above Pairs with the case higher Pairs tied
7.0% and over 4 0 0 $4 \times 28 = 112$
6.5–6.9% 21 28 588 $21 \times 26 = 546$
6.0–6.4% 192 54 10,368 $192 \times 32 = 6{,}144$
5.7–5.9% 378 86 32,508 $378 \times 12 = 4{,}536$
below 5.7% 1,265 98 123,970 $1{,}265 \times 17 = 21{,}505$
Sum 1,860 167,434 32,843

$$\mathrm{AUC} = \frac{167{,}434 + 32{,}843/2}{115 \times 1{,}860} = \frac{183{,}855.5}{213{,}900} = 0.8595.$$

The area by trapezoids. The script adds the five trapezoids under the segments and gets the same 0.8595, as the proposition requires.

Five bands keep most of the discrimination of the full measurement: 0.8595 against 0.8894 for the 48 distinct values, and against 0.728 for the single cut-off at 6.5%. The two areas can differ only through the 32,843 pairs that fall in the same band. The band version counts each of them as one half, and the full measurement puts most of them in order, more often with the case higher.

Problem 2. On the 1,942 adults with a BMI on record (113 cases and 1,829 non-cases), the AUC of BMI is 0.6567. Compute its Hanley–McNeil standard error and a 95% interval, and compare the standard error with DeLong's 0.0244.

Carrying one more digit, $A = 0.65673$, so $A^2 = 0.4313$ and

$$Q_1 = \frac{A}{2 - A} = \frac{0.65673}{1.34327} = 0.4889, \qquad Q_2 = \frac{2A^2}{1 + A} = \frac{0.86259}{1.65673} = 0.5207.$$

The three terms of the numerator are

$$A(1 - A) = 0.2254, \qquad 112 \times (0.4889 - 0.4313) = 6.4523, \qquad 1{,}828 \times (0.5207 - 0.4313) = 163.3556,$$

computed from the unrounded values. Their sum is 170.0333, and $n_1 n_0 = 113 \times 1{,}829 = 206{,}677$, so

$$\mathrm{SE} = \sqrt{\frac{170.0333}{206{,}677}} = \sqrt{0.0008227} = 0.0287.$$

The 95% interval is $0.6567 \pm 1.96 \times 0.0287 = (0.601,\ 0.713)$. It excludes 0.5, so BMI does discriminate, but weakly.

The Hanley–McNeil standard error is larger than DeLong's 0.0244 by 0.0043, a wider gap than for HbA1c (0.0202 against 0.0177). The term with $Q_2$ supplies 96% of the numerator, so the result is only as good as the exponential approximation to $Q_2$. DeLong's method estimates that term from the cases' placement values and needs no model.

Problem 3. On the same 1,942 adults the AUCs of HbA1c and age are 0.8874 and 0.6759, with DeLong standard errors 0.0180 and 0.0216, and the estimated covariance between the two AUCs is $-0.000004$. Test whether the two AUCs differ, with the paired and with the unpaired standard error.

The difference is $0.8874 - 0.6759 = 0.2115$. The two variances are $0.0180^2 = 0.000323$ and $0.0216^2 = 0.000467$ (from the unrounded standard errors).

Paired. The variance of the difference is $0.000323 + 0.000467 - 2 \times (-0.000004) = 0.000798$, so the standard error is $\sqrt{0.000798} = 0.02825$ and

$$z = \frac{0.2115}{0.02825} = 7.49.$$

A 95% interval for the difference is $0.2115 \pm 1.96 \times 0.02825 = (0.156,\ 0.267)$.

Unpaired. Leaving out the covariance gives a standard error of 0.0281 and $z = 7.53$ (from the unrounded variances; the rounded ones shown give 7.52).

Both statistics are far beyond any conventional critical value, so HbA1c discriminates better than age. Here the two standard errors nearly coincide, because the correlation between the two AUCs is only $-0.011$. That is unlike HbA1c against BMI, where the correlation was 0.115 and the paired standard error the smaller, and unlike BMI against age, where it was $-0.254$ and the paired standard error the larger. The sign and size of the covariance cannot be known without estimating it, which is the reason to use the paired method whenever the tests are measured on the same people.

Problem 4. Suppose a missed case is judged 20 times as costly as a false positive, at the NHANES prevalence of 0.0582. Find the slope of the iso-cost lines and the cut-off with the lowest expected cost among those of the article's first table.

The slope is

$$m = \frac{(1 - \pi)\,C_{\mathrm{FP}}}{\pi\,C_{\mathrm{FN}}} = \frac{1{,}860/1{,}975}{20 \times 115/1{,}975} = \frac{1{,}860}{2{,}300} = 0.8087.$$

In units of one false positive, the expected cost per adult is $(1 - \pi)\,\mathrm{FPR} + 20\,\pi\,(1 - \mathrm{TPR})$:

Cut-off False positive term Missed case term Expected cost
5.5% 0.4780 0.0608 0.5387
5.7% 0.3013 0.1722 0.4734
5.9% 0.1534 0.2430 0.3965
6.0% 0.1099 0.2937 0.4035
6.2% 0.0456 0.4354 0.4810
6.5% 0.0127 0.6177 0.6304
6.8% 0.0035 0.7696 0.7732
7.0% 0.0020 0.8810 0.8830

For 5.9%, for example, the terms are $0.9418 \times 0.1629 = 0.1534$ and $20 \times 0.0582 \times (1 - 0.7913) = 0.2430$. The lowest cost is at 5.9%. The script searches all 48 cut-offs and finds the same one, with 6.0% next at 0.4035 and 5.8% third at 0.4177. At 5.9%, of every 1,000 adults screened, the rule flags 153.4 who do not have the condition and misses 12.2 who do. These are the 303 false positives and the 24 missed cases among the 1,975 adults, on the same basis as the per-1,000 columns of the article's table.

The answer falls between those of the article's table for cost ratios of 10 (6.1%) and 50 (5.5%), as it should: the costlier a miss, the flatter the iso-cost line and the further down the curve it touches. At a ratio of 20 the cost-based cut-off is close to Youden's 6.0%, and the reason is exact. Dividing the expected cost by $\pi\,C_{\mathrm{FN}}$ gives $(1 - \mathrm{TPR}) + m\,\mathrm{FPR}$, which for $m = 1$ is $1 - J$. So maximizing Youden's index is minimizing the expected cost when the iso-cost slope is 1, that is, when $C_{\mathrm{FN}}/C_{\mathrm{FP}} = (1 - \pi)/\pi$, which is 16.17 in this population. Youden's criterion does not avoid a judgment about costs. It makes the one under which a miss is exactly as many times worse than a false alarm as the condition is rarer than its absence. The script confirms that the cost ratio 16.17 selects 6.0%.

What we have learned

The ROC curve shows every trade-off between sensitivity and false positives that a measurement offers. Its area, 0.889 for HbA1c, is the chance that a random case outranks a random non-case, which makes it the Mann–Whitney statistic. It ignores the scale and the prevalence, and its precision is set by the number of cases. Comparing tests on the same adults needs the covariance between their AUCs. The curve cannot by itself pick a cut-off. Youden's index picks 6.0%. A cut-off that minimizes expected cost depends on the prevalence and on what each error costs: 6.8% at equal costs in this population, and 5.5% when a miss costs fifty times as much.

This unit has worked with events: positive or negative, case or non-case. The next unit, Theoretical Probability Distributions, turns to random variables, numbers whose values depend on chance, such as the count of positives among the people screened. It begins with Random Variables, Expectation and Variance, which defines them, and goes on to The Binomial Distribution, the distribution of the number of successes in a fixed number of independent trials.

In Python

import numpy as np
from scipy.stats import mannwhitneyu
from sklearn.metrics import roc_auc_score, roc_curve

def auc_ci(score, disease, z=1.96):
    """AUC with DeLong's standard error (ties counted as 1/2)."""
    s, d = np.asarray(score, float), np.asarray(disease, bool)
    x, y = s[d], s[~d]
    v10 = np.array([(np.sum(xi > y) + 0.5 * np.sum(xi == y)) / len(y) for xi in x])
    v01 = np.array([(np.sum(x > yj) + 0.5 * np.sum(x == yj)) / len(x) for yj in y])
    auc = v10.mean()
    se = np.sqrt(v10.var(ddof=1) / len(x) + v01.var(ddof=1) / len(y))
    return auc, auc - z * se, auc + z * se

# a1c: HbA1c values; fpg_high: FPG >= 126 (both arrays from NHANES 2017-2018)
# roc_auc_score(fpg_high, a1c)                        -> 0.8894
# mannwhitneyu(a1c[fpg_high], a1c[~fpg_high]).statistic / (115 * 1860)  -> 0.8894
# auc_ci(a1c, fpg_high)                               -> (0.8894, 0.855, 0.924)
# fpr, tpr, thresholds = roc_curve(fpg_high, a1c)     # the points of the curve

roc_curve returns a point for each distinct value at which the curve changes direction (all 49 with drop_intermediate=False); tied values produce the diagonal segments described above, and roc_auc_score counts ties as one half. Every number in this article is computed by tools/experiments/applied-statistics/roc-curves-for-diagnostic-tests.py in the site's repository, from the NHANES files loaded by screendata.py, which implements the Hanley–McNeil and DeLong standard errors directly.

References

  • American Diabetes Association Professional Practice Committee (2025). 2. Diagnosis and classification of diabetes: Standards of Care in Diabetes–2025. Diabetes Care, 48(Suppl. 1), S27–S49. https://doi.org/10.2337/dc25-S002 record · 7 pages
  • DeLong, E. R., DeLong, D. M., and Clarke-Pearson, D. L. (1988). Comparing the areas under two or more correlated receiver operating characteristic curves: A nonparametric approach. Biometrics, 44(3), 837–845. record · 4 pages
  • Fawcett, T. (2006). An introduction to ROC analysis. Pattern Recognition Letters, 27(8), 861–874. record · 2 pages
  • Green, D. M., and Swets, J. A. (1966). Signal Detection Theory and Psychophysics. Wiley. Cited through Hanley and McNeil (1982). record
  • Hanley, J. A., and McNeil, B. J. (1982). The meaning and use of the area under a receiver operating characteristic (ROC) curve. Radiology, 143(1), 29–36. record · 3 pages
  • Hanley, J. A., and McNeil, B. J. (1983). A method of comparing the areas under receiver operating characteristic curves derived from the same cases. Radiology, 148(3), 839–843. record
  • National Center for Health Statistics (2020). National Health and Nutrition Examination Survey 2017–2018: DEMO_J, DIQ_J, BMX_J, GLU_J and GHB_J data files. Centers for Disease Control and Prevention. https://wwwn.cdc.gov/nchs/nhanes/continuousnhanes/default.aspx?BeginYear=2017 record · 109 pages
  • Pagano, M., Gauvreau, K., and Mattie, H. (2022). Principles of Biostatistics (3rd ed.). CRC Press. The course text. record · 48 pages
  • Youden, W. J. (1950). Index for rating diagnostic tests. Cancer, 3(1), 32–35. record · 2 pages

Reviewed: verified, 16 Nov 2026 · checked against sources, 23 Nov 2026 · citations checked, 16 Nov 2026 · editorial review, 23 Nov 2026 · 11 revisions