All lab tutorials

Probability and inferential statistics

Bayes’ rule after a positive test

How many people with a positive test actually have the condition?

Population and data

Predict disease status for a person drawn from the screening population who tests positive. The first decision is which population to count: the tested population, people with disease, or people with positive results. Each answers a different question.

Consider 2,000 people. Prevalence is 5%, sensitivity is 80%, and the false-positive rate is 10%. Use expected counts to see which people belong in the denominator.

Working data
Disease statusPositiveNegativeTotal
D8020100
¬D1901,7101,900
Σ2701,7302,000

Notation

D,DˉD,\bar D
Disease present, disease absent.
++
The event that a test is positive.
P(B∣C)P(B\mid C)
Probability of event B among people satisfying C.
nD,+n_{D,+}
Expected count of people with disease and a positive test in this example.

Derivation

P(D∣+)P(+)=P(D∩+)=P(+∣D)P(D)P(D\mid +)P(+)=P(D\cap +)=P(+\mid D)P(D)

Both products count the same joint event. Divide by the marginal probability of a positive result, which must be positive. The two branches in the denominator exhaust the population because disease presence and absence are mutually exclusive and exhaustive. [1][2]

Read the first row horizontally: 80 of 100 people with disease test positive. Now read the positive column vertically: only 80 of its 270 people have disease. The numerator stays at 80. Turning from row to column changes the question.

P(D∣+)P(Dˉ∣+)=P(D)P(Dˉ)×P(+∣D)P(+∣Dˉ)=119×8=819\frac{P(D\mid +)}{P(\bar D\mid +)}=\frac{P(D)}{P(\bar D)}\times\frac{P(+\mid D)}{P(+\mid\bar D)}=\frac{1}{19}\times8=\frac{8}{19}

A positive result multiplies prior odds by eight. Convert the new odds to probability by dividing 8 by 8 + 19. This gives the same answer as counting down the column. [1][2]

Multiply within each branch. D denotes disease and + denotes a positive test.

nD,+=2000(0.05)(0.80)=80,nDˉ,+=2000(0.95)(0.10)=190n_{D,+}=2000(0.05)(0.80)=80,\quad n_{\bar D,+}=2000(0.95)(0.10)=190

Conditioning on a positive test restricts the denominator to both positive branches.

P(D∣+)=P(+∣D)P(D)P(+∣D)P(D)+P(+∣Dˉ)P(Dˉ)=80270P(D\mid +)=\frac{P(+\mid D)P(D)}{P(+\mid D)P(D)+P(+\mid\bar D)P(\bar D)}=\frac{80}{270}

R analysis

Download the complete R script
positive <- c(true = 2000*.05*.80, false = 2000*.95*.10)
round(unname(positive["true"] / sum(positive)), 4)

R output

[1] 0.2963

About 30 of every 100 positive tests correspond to disease in this population. The larger disease-free group generates more positives despite its lower positive-test rate.

At what prevalence do true positives become the majority?

Hold sensitivity and specificity fixed and vary only prevalence. First predict which row will cross 50%.

prev <- c(.01, .05, .10, .20)
ppv <- .80 * prev / (.80 * prev + .10 * (1 - prev))
data.frame(prevalence = prev, PPV = round(ppv, 3))

R output

  prevalence   PPV
1       0.01 0.075
2       0.05 0.296
3       0.10 0.471
4       0.20 0.667

The threshold solves 0.80p = 0.10(1 − p), giving p = 1/9. Above about 11.1%, true positives outnumber false positives. A test can have the same sensitivity and yield quite different post-test probabilities across populations. [3]

Try a variation

What if prevalence rises to 20%?

Reveal the explanation

Holding test performance fixed gives 320 true and 160 false positives, so the probability becomes 2/3.

References

The datasets and calculations are teaching examples created for this tutorial. The sources below explain the methods used.

  1. Illowsky B, Dean S. Introductory Statistics. 2nd ed. OpenStax, 2023. §3.5.

    Conditional probabilities along the branches of a probability tree.

  2. Deeks JJ, Altman DG. Diagnostic tests 4: likelihood ratios. BMJ. 2004;329:168–169.

    Updating prior odds using a likelihood ratio.

  3. Altman DG, Bland JM. Diagnostic tests 2: predictive values. BMJ. 1994;309:102.

    Why predictive values depend on disease prevalence.