Bayes' Theorem
What You’ll Learn
Section titled “What You’ll Learn”In this lesson you’ll learn Bayes’ theorem, how to flip a conditional probability around, the vocabulary of prior and posterior, and why base rates dominate the interpretation of medical tests.
The Concept
Section titled “The Concept”The problem Bayes solves
Section titled “The problem Bayes solves”You know and you want . The previous lesson established these are different. Bayes’ theorem is the conversion.
Deriving it takes two lines. The joint probability can be written two ways:
Set them equal and divide by . That’s the whole proof.
The vocabulary
Section titled “The vocabulary”- Prior, - what you believed before the evidence. Often the base rate, the overall prevalence.
- Likelihood, - how probable the evidence is if is true.
- Posterior, - your updated belief after seeing the evidence.
- Evidence or marginal, - how probable the evidence is overall.
The structure to remember: posterior ∝ likelihood × prior. Evidence doesn’t replace your prior belief, it updates it. A strong prior takes strong evidence to move.
Finding the denominator
Section titled “Finding the denominator”Usually isn’t handed to you. Compute it with the law of total probability: the evidence can arise whether or not holds, so add both routes.
Substituting gives the expanded form:
It looks heavy. In practice it’s just “the path you want, divided by all the paths that produce the evidence,” which is exactly the tree-diagram reasoning from the last lesson.
Medical testing vocabulary
Section titled “Medical testing vocabulary”- Sensitivity = . The true positive rate. Catches the sick.
- Specificity = . The true negative rate. Clears the healthy.
- False positive rate = .
- Prevalence = . The base rate.
- Positive predictive value = . This is what a patient wants to know.
Sensitivity and specificity describe the test. Positive predictive value describes your situation, and it depends on prevalence.
Why base rates dominate
Section titled “Why base rates dominate”Here’s the result that surprises everyone, including doctors.
A disease affects 1 in 1,000 people. A test has 99% sensitivity and 99% specificity. You test positive. What’s the probability you have it?
Most people say around 99%. The answer is about 9%.
Think in counts over 100,000 people, which avoids the algebra entirely:
- 100 have the disease. The test catches 99% of them → 99 true positives.
- 99,900 are healthy. The test wrongly flags 1% of them → 999 false positives.
Total positives: . Of those, only 99 are genuinely sick.
The test is excellent. The problem is arithmetic: there are 999 healthy people for every sick one, so even a 1% error rate applied to that huge group swamps the true positives.
Ignoring the base rate is called the base rate fallacy, and it’s the most consequential error in this section.
The counts trick
Section titled “The counts trick”Whenever a Bayes problem appears, convert to counts over a convenient population instead of manipulating fractions. Pick a round number like 10,000 or 100,000, walk the four cases, and read the answer off the table. It’s faster, harder to get wrong, and immediately explainable to someone else.
The four cases are always the same:
| Has disease | No disease | |
|---|---|---|
| Test positive | true positive | false positive |
| Test negative | false negative | true negative |
Worked Examples
Section titled “Worked Examples”Example 1: The formula directly.
, , . Find .
Solution. First the denominator:
Then Bayes:
The evidence raised belief in from 0.30 to 0.63.
Example 2: A rare disease, by counts.
Prevalence 0.5%. Sensitivity 98%. Specificity 95%. Find the positive predictive value.
Solution. Take 100,000 people.
- Diseased:
- True positives:
- False negatives: 10
- Healthy: 99,500
- False positives:
- True negatives: 94,525
About 9%. Despite a 98% sensitive test, a positive result leaves a 91% chance you’re fine. This is why screening programs use a second, different confirmatory test.
Example 3: How prevalence changes everything.
Same test as Example 2, but now applied to a high-risk group with 20% prevalence.
Solution. Take 100,000 again.
- Diseased: 20,000 → true positives
- Healthy: 80,000 → false positives
83% instead of 9%. Identical test, different population.
This is precisely why doctors don’t screen everyone for everything. Testing a low-risk population generates mostly false positives, causing anxiety, cost, and risk from follow-up procedures. Targeting testing at higher-prevalence groups makes the same test far more informative.
Example 4: Spam filtering.
30% of email is spam. The word “winner” appears in 40% of spam and 2% of legitimate email. An email contains “winner.” Is it spam?
Solution.
About 90%. The prior of 30% jumped to 90% on one word. Real filters chain many such words together, which is where “Naive Bayes” gets its name: it naively assumes the words are independent.
Example 5: Updating twice.
Continuing Example 4, the same email also contains “free,” which appears in 50% of spam and 5% of legitimate mail. Update again.
Solution. Use the posterior from before as the new prior: .
Now 98.9%. Bayesian updating is sequential: yesterday’s posterior becomes today’s prior. This is the mathematical core of learning from evidence.
Example 6: A negative result.
Using Example 2’s test (98% sensitivity, 95% specificity, 0.5% prevalence), what’s the probability of disease given a negative result?
Solution. From the counts: false negatives 10, true negatives 94,525.
About 1 in 9,400, down from a prior of 1 in 200. A negative result on a rare disease is highly reassuring, which is the mirror image of why the positive result was so weak. Screening tests are built to rule things out, not to rule them in.
Real-World Applications
Section titled “Real-World Applications”Medical screening policy is set by these calculations. Debates about the right age to begin mammography or prostate screening are arguments about prevalence: at younger ages the base rate is lower, so the same test yields more false positives per true case detected, and the harms of follow-up biopsies can outweigh the benefits.
COVID testing made this public. Rapid antigen tests had good specificity, but when prevalence was very low, a large share of positives were false, which is why confirmatory PCR was recommended. When prevalence spiked, the same positive result became much more trustworthy.
Spam filters, as shown, are direct applications. So is much of medical AI, where a model’s reported accuracy on a balanced test set can be wildly optimistic about performance in a population where the condition is rare.
Criminal justice suffers the base rate fallacy badly. DNA databases searched across millions of profiles will produce coincidental matches, and interpreting a match without accounting for how many people were searched is the prosecutor’s fallacy in Bayesian form.
Airport security screening and fraud detection face the same tension: with a very low base rate of genuine threats, even a highly accurate system produces mostly false alarms, which is why layered screening exists.
In machine learning, class imbalance is the base rate problem restated. A model predicting a 1-in-1000 event can achieve 99.9% accuracy by always predicting “no,” which is why practitioners use precision, recall, and confusion matrices instead of accuracy.
Retrying will remove your ✅ checkmark until you pass again.