Predictive Values and Bayes' Theorem

What a test result means for the person tested. Positive and negative predictive values read from a 2 x 2 table and derived from sensitivity, specificity and prevalence by Bayes' theorem; natural frequencies; why a positive result for a rare condition is often a false alarm, shown at prevalences from 0.5% to 50%; how far the theorem's predictions hold across age groups when sensitivity and specificity themselves vary; why a case-control study cannot give predictive values; and estimating true prevalence from an imperfect test with the Rogan-Gladen correction. Worked on HbA1c and fasting glucose in NHANES adults.

An adult without a diabetes diagnosis has a routine blood test, and the HbA1c comes back at 6.6%, above the American Diabetes Association's threshold of 6.5%. How likely is it that this person's fasting glucose is also in the diabetic range?

Sensitivity and Specificity described the test from the other direction. Among the adults whose fasting glucose was 126 mg/dL or more, 47.0% had a positive HbA1c; among the rest, 98.7% had a negative one. Neither number answers the patient's question. The patient knows the test result, not the disease status, and needs a probability conditioned on the result. That probability is a predictive value. The two directions are the conditional probabilities $P(T^+ \mid D)$ and $P(D \mid T^+)$, which Conditional Probability and the Law of Total Probability showed can differ by a large factor. That article is also the home of Bayes' theorem, which this one applies to a test result.

First we read the predictive values off the 2 by 2 table. Then we rebuild them from sensitivity, specificity and prevalence by Bayes' theorem, and draw the same calculation as natural frequencies. Next we vary the prevalence and watch the meaning of a positive result change, and check the theorem's predictions on age groups of real adults. Finally we see what a case-control study cannot tell us, how to correct a prevalence estimated with an imperfect test, and why a diagnosis needs a second test.

The examples continue with the 1,975 adults of the National Health and Nutrition Examination Survey (NHANES) 2017 to 2018 who had no diabetes diagnosis. The test is HbA1c of 6.5% or more, and the reference standard is a fasting plasma glucose (FPG) of 126 mg/dL or more. The previous article explains that this "diabetes" is a definition based on one measurement.

Predictive values from the table

The 2 by 2 table of the previous article is repeated here:

HbA1c FPG $\ge$ 126 FPG $<$ 126 Total
$\ge 6.5\%$ 54 (TP) 25 (FP) 79
$< 6.5\%$ 61 (FN) 1,835 (TN) 1,896
Total 115 1,860 1,975

Sensitivity and specificity divide by column totals. The predictive values divide by row totals. The positive predictive value is the probability of the condition given a positive result,

$$\mathrm{PPV} = P(D \mid T^+) = \frac{\mathrm{TP}}{\mathrm{TP} + \mathrm{FP}} = \frac{54}{79} = 0.6835,$$

and the negative predictive value is the probability of no condition given a negative result,

$$\mathrm{NPV} = P(D^c \mid T^-) = \frac{\mathrm{TN}}{\mathrm{TN} + \mathrm{FN}} = \frac{1{,}835}{1{,}896} = 0.9678.$$

For the adult with an HbA1c of 6.6%, the answer is about two chances in three. A third of the positive results in this population belong to adults whose fasting glucose is below 126. (The 6.6% is treated here only as "positive"; Likelihood Ratios for Diagnostic Tests uses the value itself.)

Like sensitivity and specificity, these are proportions, and the Wilson intervals of Confidence Intervals for a Proportion apply. The PPV is 0.684 (0.575, 0.776) on 79 positives, and the NPV 0.9678 (0.9589, 0.9749) on 1,896 negatives.

There is a condition on reading predictive values straight from the table. The table must be a sample of the population in which the test is used, with cases and non-cases in their natural proportions, as in this cross-sectional sample. When it is not, the predictive values must be computed instead, by the theorem below.

Bayes' theorem for a test result

What if we know only how the test behaves, and how common the condition is? Here is the idea in one sentence. Out of the whole population, work out the share who are true positives and the share who are false positives; the PPV is the first share over their sum.

The formal version. Three quantities describe a test in a population:

  • the prevalence $\pi = P(D)$;
  • the sensitivity $\mathrm{Se} = P(T^+ \mid D)$;
  • the specificity $\mathrm{Sp} = P(T^- \mid D^c)$.

The events $D$ and $D^c$ partition the population, so the law of total probability gives the probability of a positive result:

$$P(T^+) = P(D)\,P(T^+ \mid D) + P(D^c)\,P(T^+ \mid D^c) = \pi\,\mathrm{Se} + (1 - \pi)(1 - \mathrm{Sp}).$$

The definition of conditional probability, with the multiplication rule in the numerator, then gives Bayes' theorem in the form used for diagnostic tests:

$$\mathrm{PPV} = P(D \mid T^+) = \frac{P(D)\,P(T^+ \mid D)}{P(T^+)} = \frac{\pi\,\mathrm{Se}}{\pi\,\mathrm{Se} + (1 - \pi)(1 - \mathrm{Sp})}.$$

The same argument with $T^-$ gives

$$\mathrm{NPV} = P(D^c \mid T^-) = \frac{(1 - \pi)\,\mathrm{Sp}}{(1 - \pi)\,\mathrm{Sp} + \pi\,(1 - \mathrm{Se})}.$$

The numerator of the PPV is the share of the whole population that is a true positive. The second term of the denominator is the share that is a false positive.

Back to the NHANES adults, with $\pi = 0.0582$, $\mathrm{Se} = 0.4696$ and $\mathrm{Sp} = 0.9866$. The true positives are $0.0582 \times 0.4696 = 0.02734$ of the population, and the false positives $0.9418 \times 0.0134 = 0.01266$. Together they are $P(T^+) = 0.04000$, which is $79/1{,}975$, and

$$\mathrm{PPV} = \frac{0.02734}{0.02734 + 0.01266} = 0.6835,$$

the value read from the table. On the population that produced the three inputs, the theorem simply reproduces the table. Its use is to transfer a test's sensitivity and specificity, measured in one study, to a population with a different prevalence.

Natural frequencies

The same calculation is easier to follow in counts. Imagine 10,000 adults like these. At a prevalence of 5.8%, 582 have the condition and 9,418 do not. The test is positive in 47.0% of the 582, about 273 people, and in 1.34% of the 9,418, about 127. Of the 400 positives, 273 have the condition, a proportion of 0.68.

Bayes' theorem as natural frequencies for 10,000 adults with the NHANES prevalence of 5.8%; the first branches split by the reference standard, the second by the test. Notice that the PPV uses only the two positive leaves, 273 true and 127 false: it is the share of all positives that are true, 273 of 400.
Bayes' theorem as natural frequencies for 10,000 adults with the NHANES prevalence of 5.8%; the first branches split by the reference standard, the second by the test. Notice that the PPV uses only the two positive leaves, 273 true and 127 false: it is the share of all positives that are true, 273 of 400.

The tree is the law of total probability drawn as in the previous unit, scaled by 10,000. Gigerenzer and Hoffrage (1995) showed that the Bayesian computation is simpler in such frequency formats than with probabilities. Participants with no training in statistics reached the Bayesian answer far more often when a problem was posed in frequencies, for up to half of all their inferences.

Prevalence and the false alarm

The tree used the NHANES prevalence. What happens to the same test in a population where the condition is rarer, or more common? Sensitivity and specificity do not involve the prevalence, but the predictive values depend on it strongly.

Check your understanding. Keep the test exactly as it is, and lower the prevalence from 5.8% to 0.5%. Will a positive result still mean the condition more often than not?

It will not. Holding the test fixed and changing only $\pi$:

Prevalence PPV NPV Per 10,000: TP FP FN TN
0.5% 0.149 0.9973 23 134 27 9,816
2% 0.416 0.9891 94 132 106 9,668
5.8% (NHANES) 0.684 0.9678 273 127 309 9,291
20% 0.897 0.8815 939 108 1,061 7,892
50% 0.972 0.6503 2,348 67 2,652 4,933

When the condition is rare, almost everyone tested is free of it. Even a small false positive rate, applied to that large group, yields more false alarms than the true cases can supply. At a prevalence of 0.5%, the 1.34% false positive rate produces 134 false positives against 23 true ones, and a positive result means the condition with probability 0.15. The PPV reaches one half at a prevalence of 2.8%, and 0.9 at 20.5%.

The negative result moves the other way. It becomes more reassuring as the condition becomes rarer, and less so as it becomes common. At 50% prevalence a negative HbA1c still leaves a probability of 0.35 that the fasting glucose is in the diabetic range.

PPV and NPV of HbA1c at 6.5% as functions of prevalence (log scale), from Bayes' theorem with the overall sensitivity 0.470 and specificity 0.987. Follow the PPV curve leftward: it falls below one half at 2.8%. The markers, observed PPVs with 95% Wilson intervals in three age groups whose prevalences are 1.6%, 6.5% and 10.3%, rise less steeply than the curve.
PPV and NPV of HbA1c at 6.5% as functions of prevalence (log scale), from Bayes' theorem with the overall sensitivity 0.470 and specificity 0.987. Follow the PPV curve leftward: it falls below one half at 2.8%. The markers, observed PPVs with 95% Wilson intervals in three age groups whose prevalences are 1.6%, 6.5% and 10.3%, rise less steeply than the curve.

The common misreading has a name. Ignoring the prevalence when interpreting a positive result is called base-rate neglect. It treats $P(D \mid T^+)$ as if it were the sensitivity, or as if it were the specificity: "the test is 98.7% specific, so a positive result is 98.7% certain." It is the $P(A \mid B)$ against $P(B \mid A)$ confusion of the previous unit, and the base rate is what connects the two.

What a negative result says

Check your understanding. Before testing, the probability of the condition is the prevalence, 0.0582. The NPV is 0.968, which sounds reassuring. By how much does a negative HbA1c lower the probability of the condition?

By a little under half. After a negative result it is $1 - \mathrm{NPV} = 61/1{,}896 = 0.0322$, a fall of 45%, to 0.55 times the prevalence. But most of the cases in the population (61 of 115) are among the negatives. A test with low sensitivity cannot rule a condition out, however high its NPV looks in a low-prevalence population.

Does the theorem hold within subgroups?

The usual way to apply Bayes' theorem in practice is to take sensitivity and specificity from a published study, and combine them with the prevalence of the patient's own group. The NHANES data allow a check. The prevalence of the condition rises with age, and each age group can be treated as a new population:

Age Prevalence Observed PPV (Wilson 95%) Bayes PPV Observed NPV Bayes NPV
18–39 12/743 = 0.0162 6/10 = 0.600 (0.313, 0.832) 0.364 727/733 = 0.9918 0.9913
40–59 41/628 = 0.0653 18/29 = 0.621 (0.440, 0.773) 0.709 576/599 = 0.9616 0.9638
60 and over 62/604 = 0.1026 30/40 = 0.750 (0.598, 0.858) 0.800 532/564 = 0.9433 0.9421

The negative predictive values agree closely. The positive ones move in the predicted direction, rising with prevalence, but by less than the theorem says. The young adults' PPV is higher than predicted, and the older adults' lower.

Part of the difference is sampling error, since the young group has only 10 positives and its interval is wide. Part is the lesson of the previous article: sensitivity and specificity are not constant across groups.

  • The young adults. Their specificity was 0.9945, so their false positive rate, 4 of 731 or 0.0055, was well under half the overall 0.0134. When the condition is rare the false positives come almost entirely from that rate, so the PPV is very sensitive to it. Their sensitivity, 0.500 against 0.470 overall, pushes the same way, but only slightly.
  • The two older groups. Their specificity was 0.981 to 0.982, below the overall value, and their PPVs fall short of the prediction.

Using the young adults' own sensitivity and specificity, the theorem gives their PPV exactly, 0.600, as it must. Their specificity rests on only 4 false positives, so the gap between 0.600 and 0.364 is a pattern to note rather than a precise measurement. Transferring accuracy from one population to another is only as good as the assumption that the test behaves the same way in both.

When predictive values cannot be read from a study

The previous article imitated a diagnostic case-control study. It took 264 diagnosed adults with high fasting glucose as cases and 444 young adults with normal glucose as controls.

Check your understanding. In that sample, 223 cases and 1 control were positive. Is the PPV of HbA1c in that setting $223/224 = 0.996$?

It is not a predictive value of anything. The proportion of cases in the sample, $264/708 = 0.373$, was fixed by the investigator's choice of how many of each to recruit. The PPV depends on that proportion, as the prevalence table above shows. A case-control design can estimate sensitivity and specificity, with the spectrum caveats of the previous article, but not predictive values. To obtain them, the sensitivity and specificity must be combined by Bayes' theorem with a prevalence from another source. This is the diagnostic counterpart of the result in Relative Risk and the Odds Ratio that a case-control study cannot estimate a risk.

Estimating prevalence with an imperfect test

Surveys often estimate how common a condition is by testing a sample. An imperfect test then gives the wrong answer, and Bayes' arithmetic can partly repair it.

The proportion testing positive, the apparent prevalence, is by total probability

$$\pi_a = P(T^+) = \pi\,\mathrm{Se} + (1 - \pi)(1 - \mathrm{Sp}).$$

The equation is linear in $\pi$, and solving it gives the estimator of Rogan and Gladen (1978):

$$\hat{\pi} = \frac{\pi_a + \mathrm{Sp} - 1}{\mathrm{Se} + \mathrm{Sp} - 1}.$$

Its denominator is Youden's index, which ROC Curves for Diagnostic Tests uses to choose a threshold. In the NHANES adults the apparent prevalence of the condition by HbA1c is $79/1{,}975 = 0.0400$. The correction gives back the true 0.0582, as it must on the data that supplied $\mathrm{Se}$ and $\mathrm{Sp}$. Applied to the age groups with the overall sensitivity and specificity:

Age Apparent Corrected True
18–39 10/743 = 0.0135 0.0000 0.0162
40–59 29/628 = 0.0462 0.0718 0.0653
60 and over 40/604 = 0.0662 0.1157 0.1026

The correction moves the estimates of the two older groups the right way but overshoots. In the youngest it gives a prevalence of zero (0.00004 before rounding), for a group in which 1.6% have the condition. Two features of the estimator explain this.

  • It amplifies error. Dividing by $\mathrm{Se} + \mathrm{Sp} - 1 = 0.4562$ multiplies any error in the apparent prevalence by 2.2, including sampling error.
  • It subtracts the false positive rate. The numerator removes $1 - \mathrm{Sp} = 0.0134$ from the apparent prevalence, so an apparent prevalence at or below that rate gives an estimate of zero or less. The young adults' apparent prevalence, 0.0135, is barely above it. Their specificity, 0.9945, was higher than the overall value, so fewer of their positives were false than the correction assumed.

A negative estimate is truncated to zero in practice. The formula is reliable only when sensitivity and specificity are known for the population being surveyed.

Sequential testing

The ADA requires a second abnormal result to confirm a diagnosis in the absence of unequivocal hyperglycemia (ADA, 2025). The arithmetic of this article explains why. After one positive HbA1c in this population, the probability of the condition is 0.684. That probability is the "prevalence" in which the second test is interpreted. A confirmatory test with the same sensitivity and specificity, applied to the positives, would by Bayes' theorem raise the probability to

$$\frac{0.684 \times 0.4696}{0.684 \times 0.4696 + 0.316 \times 0.0134} = 0.987,$$

if its errors were independent of the first test's within each disease group. That condition is strong, because repeating the same test on the same person tends to repeat its errors.

Corrections to the course notes

The unit's notes state Bayes' theorem as $P(A \mid B) = P(B \mid A)P(A)/P(B)$ and apply it to the probability of disease after a positive result, as here. The predictive values in terms of sensitivity, specificity and prevalence follow by expanding $P(B)$ with the law of total probability, which the notes' version leaves implicit. Their prevalence formula $(\mathrm{TP} + \mathrm{FN})/N$ is correct, as are their expression for the apparent prevalence and the corrected estimate $(\mathrm{AP} + \mathrm{Sp} - 1)/(\mathrm{Se} + \mathrm{Sp} - 1)$. Stated more precisely, the corrected estimate can fall below 0 or above 1. It also needs sensitivity and specificity that hold in the population surveyed, as the age groups above show. The notes' remark that predictive values depend on prevalence while sensitivity and specificity do not is the theme of this article. It carries the qualification of the previous one, that sensitivity and specificity can still vary between populations.

Summary

Quantity Formula
Positive predictive value $P(D \mid T^+) = \mathrm{TP}/(\mathrm{TP} + \mathrm{FP}) = \pi\,\mathrm{Se} / [\pi\,\mathrm{Se} + (1 - \pi)(1 - \mathrm{Sp})]$
Negative predictive value $P(D^c \mid T^-) = \mathrm{TN}/(\mathrm{TN} + \mathrm{FN}) = (1 - \pi)\,\mathrm{Sp} / [(1 - \pi)\,\mathrm{Sp} + \pi\,(1 - \mathrm{Se})]$
Probability of a positive result $P(T^+) = \pi\,\mathrm{Se} + (1 - \pi)(1 - \mathrm{Sp})$
Corrected prevalence (Rogan–Gladen) $\hat\pi = (\pi_a + \mathrm{Sp} - 1)/(\mathrm{Se} + \mathrm{Sp} - 1)$

What we have learned

The adult with an HbA1c of 6.6% has about a two-in-three chance of a diabetic fasting glucose in this population, 54 of 79 positives. Bayes' theorem rebuilds that number from sensitivity, specificity and prevalence. It also shows that at a prevalence of 0.5% the same test would mean the condition only 15% of the time. False alarms from the large healthy group swamp the few true cases. The theorem's predictions hold within age groups only as well as the test's accuracy is constant across them, and a case-control study cannot supply predictive values at all.

The probability form of the theorem mixes what describes the patient (the prevalence) with what describes the test. Likelihood Ratios for Diagnostic Tests separates the two and writes sequential testing as a chain of multiplications. It also measures how far the independence assumption behind the 0.987 above fails for two real measurements.

In Python

def ppv(prev, se, sp):
    return prev * se / (prev * se + (1 - prev) * (1 - sp))

def npv(prev, se, sp):
    return (1 - prev) * sp / ((1 - prev) * sp + prev * (1 - se))

se, sp = 54 / 115, 1835 / 1860                 # HbA1c >= 6.5% against FPG >= 126 mg/dL
for prev in (0.005, 0.02, 115 / 1975, 0.2, 0.5):
    print(f'{prev:.3f}  PPV {ppv(prev, se, sp):.3f}  NPV {npv(prev, se, sp):.4f}')

Every number in this article is computed by tools/experiments/applied-statistics/predictive-values-and-bayes-theorem.py in the site's repository, from the NHANES files loaded by screendata.py.

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 · 3 pages
  • Gigerenzer, G., and Hoffrage, U. (1995). How to improve Bayesian reasoning without instruction: Frequency formats. Psychological Review, 102(4), 684–704. record
  • National Center for Health Statistics (2020). National Health and Nutrition Examination Survey 2017–2018: DEMO_J, DIQ_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 · 45 pages
  • Pagano, M., Gauvreau, K., and Mattie, H. (2022). Principles of Biostatistics (3rd ed.). CRC Press. The course text. record · 35 pages
  • Rogan, W. J., and Gladen, B. (1978). Estimating prevalence from the results of a screening test. American Journal of Epidemiology, 107(1), 71–76. record