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.
| Disease status | Positive | Negative | Total |
|---|---|---|---|
| D | 80 | 20 | 100 |
| ¬D | 190 | 1,710 | 1,900 |
| Σ | 270 | 1,730 | 2,000 |
Notation
- Disease present, disease absent.
- The event that a test is positive.
- Probability of event B among people satisfying C.
- Expected count of people with disease and a positive test in this example.
Derivation
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.
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.
Conditioning on a positive test restricts the denominator to both positive branches.
R analysis
Download the complete R scriptpositive <- 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.
- Illowsky B, Dean S. Introductory Statistics. 2nd ed. OpenStax, 2023. §3.5.
Conditional probabilities along the branches of a probability tree.
- Deeks JJ, Altman DG. Diagnostic tests 4: likelihood ratios. BMJ. 2004;329:168–169.
Updating prior odds using a likelihood ratio.
- Altman DG, Bland JM. Diagnostic tests 2: predictive values. BMJ. 1994;309:102.
Why predictive values depend on disease prevalence.