Bayes' Theorem
See why a positive result from an accurate test can still be unlikely to be right
1,000 people tested
- Has the disease, tests positive: 9
- Has the disease, tests negative: 1
- Healthy, tests positive: 89
- Healthy, tests negative: 901
Natural frequency tree(counts rounded to whole people)
After a positive test
- P(disease | +)
- 9.2%
- From the counts
- 9 / 98
- P(+) overall
- 9.8%
- Likelihood ratio LR+
- 10.00
After a negative test
- P(no disease | −)
- 99.89%
- From the counts
- 901 / 902
- P(disease | −)
- 0.11%
Bayes' theorem with these numbers
P(D | +) = P(+ | D) P(D) / P(+)
= (0.9000 × 0.0100) / (0.9000 × 0.0100 + 0.0900 × 0.9900)
= 0.00900 / 0.0981
= 0.0917
Most positives here are false alarms: 89 healthy people test positive against 9 sick ones. Ignoring how rare the disease is makes the test look far more conclusive than it is: the base-rate fallacy.
Turning P(evidence | cause) into P(cause | evidence)
Tests are described by how they behave when you already know the truth. Sensitivity is P(+ | disease), the share of sick people who test positive. Specificity is P(− | healthy), the share of healthy people who test negative. But a patient holding a positive result wants the reverse: P(disease | +). Bayes' theorem is the rule that converts one into the other.
The conversion depends on the base rate. Take a test with 90% sensitivity and 91% specificity, used on a population where 1% have the disease. Out of 1,000 people, 10 are sick and 9 of them test positive. Of the 990 healthy people, 9% (about 89) also test positive. So 98 people test positive and only 9 of them are sick: P(disease | +) = 9/98 ≈ 9.2%, even though the test is "90% accurate".
Thinking in counts of people like this, called natural frequencies, makes Bayes' theorem almost obvious. The formula does the same calculation with probabilities instead of people.
Prior
Likelihood
Posterior
Updating
Key formulas
Bayes' theorem
P(D | +) = P(+ | D) P(D) / [P(+ | D) P(D) + P(+ | D′) P(D′)]
- P(D)
- prior: prevalence of the disease
- P(+ | D)
- sensitivity
- P(+ | D′)
- 1 − specificity, the false positive rate
- P(D | +)
- posterior, also called the positive predictive value
Negative result
P(D′ | −) = P(− | D′) P(D′) / [P(− | D′) P(D′) + P(− | D) P(D)]
Odds form
posterior odds = prior odds × LR+
- LR+
- positive likelihood ratio = sensitivity / (1 − specificity)
Same test, different base rates
| Prevalence | P(disease | +) | P(healthy | −) | What it means |
|---|---|---|---|
| 0.1% | 1.0% | 99.99% | About 99 of every 100 positives are false |
| 1% | 9.2% | 99.89% | About 9 of every 10 positives are false |
| 10% | 52.6% | 98.79% | A positive is roughly a coin flip |
| 50% | 90.9% | 90.10% | Now a positive is usually right |
How to use this visualizer
- 1Set the prevalence, sensitivity and specificity, or pick a preset. The grid sorts 1,000 people: circles have the disease, squares do not, and filled shapes tested positive.
- 2Tick Show only positive tests. Compare the filled circles (true positives) with the filled squares (false positives): P(disease | +) is the share of circles.
- 3Follow the natural frequency tree from 1,000 people down to the four groups, and check that the panel on the right gives the same answer from the formula.
- 4Lower the prevalence and watch false positives swamp the true ones, even with sensitivity and specificity at 99%.
- 5Press Positive again to retest the same person. The posterior becomes the new prior, and a second positive usually raises the probability a lot.
The base-rate fallacy
It is tempting to read "90% sensitive" as "a positive means a 90% chance of disease". That ignores the base rate: when the disease is rare, the healthy group is so large that even a small false positive rate produces more false alarms than there are sick people. Always ask how common the condition is among the people being tested.Practice problems
Problem 1: A screening test
Show solutionHide solution
Out of 1,000 people: 20 sick, 980 healthy.
True positives: 95% of 20 = 19. False negatives: 1.
False positives: 10% of 980 = 98. True negatives: 882.
P(D | +) = 19 / (19 + 98) = 19 / 117 ≈ 0.162
With the formula: 0.95 × 0.02 / (0.95 × 0.02 + 0.10 × 0.98) = 0.019 / 0.117 ≈ 0.162
P(D | −) = 1 / (1 + 882) = 1 / 883 ≈ 0.00113
P(disease | +) ≈ 16.2%; P(disease | −) ≈ 0.11%
Problem 2: Testing again
Show solutionHide solution
New prior: P(D) = 19/117 ≈ 0.1624
Numerator: 0.95 × 0.1624 ≈ 0.1543
Denominator: 0.1543 + 0.10 × 0.8376 ≈ 0.1543 + 0.0838 = 0.2381
P(D | +, +) ≈ 0.1543 / 0.2381 ≈ 0.648
Check with odds: prior odds 19/98 ≈ 0.194, LR+ = 0.95 / 0.10 = 9.5, posterior odds ≈ 1.842, probability = 1.842 / 2.842 ≈ 0.648
About 64.8%, up from 16.2% after one positive and 2% before testing
Related topics
Discussion
Questions, ideas or a different approach? Join the conversation.