From a hunch to a number — how evidence should change your mind
Your friend coughs once. Are they sick? A cough is a clue, not proof — plenty of healthy people cough too. To guess well you need two things: how common the sickness is right now, and how much more often sick people cough than healthy people do. Bayes' theorem is just the careful way of putting "how common" together with "how strong the clue is." Begin with what you believed before the clue, then nudge that belief up or down depending on how surprising the clue is.
Give the pieces names. The prior $P(D)$ is the base rate — the fraction of people who really have the condition before any test. The likelihood describes how the test behaves: sensitivity $P(+\mid D)$ is the chance a sick person tests positive, and specificity $P(-\mid\lnot D)$ is the chance a healthy person tests negative. What you actually want is the posterior $P(D\mid +)$ — given a positive test, how likely is it you are truly sick? Count it out: among $10{,}000$ people with a $1\%$ base rate, $100$ are sick. A $99\%$-sensitive test flags about $99$ of them. But a $95\%$-specific test wrongly flags $5\%$ of the $9{,}900$ healthy people — about $495$ false alarms. So a positive result is correct only $99/(99+495)\approx 17\%$ of the time.
Written exactly, $$P(D\mid +)=\frac{P(+\mid D)\,P(D)}{P(+\mid D)\,P(D)+P(+\mid\lnot D)\,P(\lnot D)},$$ where the denominator $P(+)$ adds true positives and false positives so the answer is a proper probability. In the simulation above the Prior slider sets $P(D)$, Sensitivity sets $P(+\mid D)$, and Specificity sets the false-positive rate through $P(+\mid\lnot D)=1-\text{specificity}$. When the disease is rare, that false-positive term dominates the denominator — the famous base-rate fallacy.
Set the Prior to $0.1\%$ and watch the posterior collapse even though the test itself never changed. Then push Specificity from $95\%$ toward $99.9\%$ and see the posterior climb — for rare conditions, ruling healthy people out matters more than catching sick people. Finally open the Natural Freq Grid tab: the yellow false-positive dots are exactly what intuition forgets to count.
Bayes' Theorem — Thomas Bayes 1763 / Richard Price (published posthumously)
$$\boxed{P(A|B) = \frac{P(B|A)\,P(A)}{P(B)} = \frac{P(B|A)\,P(A)}{P(B|A)P(A)+P(B|A^c)P(A^c)}}$$
| Symbol | Meaning | Interpretation |
|---|---|---|
| $P(A)$ | Prior probability | Belief about A BEFORE seeing B (base rate) |
| $P(B|A)$ | Likelihood | How probable is evidence B if A is true? |
| $P(A|B)$ | Posterior probability | Updated belief about A AFTER seeing B |
| $P(B)$ | Marginal probability | Total probability of evidence (normalizing constant) |
Bayes' theorem tells us how to update a prior belief P(A) when we observe new evidence B. The posterior P(A|B) is proportional to the prior times the likelihood: P(A|B) ∝ P(B|A)·P(A).
$$P(A|B) = \frac{P(A\cap B)}{P(B)} = \frac{P(B|A)P(A)}{P(B)}$$
Using the law of total probability: $P(B) = P(B|A)P(A)+P(B|A^c)P(A^c)$.
A = has disease, B = tests positive. $P(+|D)$ = sensitivity, $P(-|\lnot D)$ = specificity.
$$P(D|+) = \frac{P(+|D)\cdot P(D)}{P(+|D)\cdot P(D)+P(+|\lnot D)\cdot P(\lnot D)}$$
Even a very accurate test can have low PPV when the disease is rare. If P(disease)=0.01, sensitivity=0.99, specificity=0.95: P(D|+)=P(+|D)·P(D)/P(+)=0.99·0.01/(0.99·0.01+0.05·0.99)≈0.167. Only 16.7% of positive tests are true positives! This is the base rate fallacy.
Problem: HIV prevalence in a low-risk population = 0.1%. Test sensitivity=99.9%, specificity=99.9%. If test is positive, what's P(HIV|+)?
$P(+)=0.999\times0.001+0.001\times0.999=0.001998$
$$P(HIV|+)=\frac{0.999\times0.001}{0.001998}\approx\mathbf{0.500}$$
Only 50% — even with a near-perfect test! The low base rate (0.1%) dominates. Confirmatory testing is essential for rare diseases.
"A test with 99% accuracy means a positive result means 99% chance you have the disease."
This ignores the base rate P(disease). For rare diseases, most positives are false positives even with highly accurate tests — as shown in the simulation. P(D|+) depends on ALL three quantities: prior P(D), sensitivity P(+|D), and specificity P(-|¬D). The base rate fallacy is one of the most consequential errors in medical reasoning.
📖 Gigerenzen — Calculated Risks (2002)
"P(B|A) = P(A|B) — they are the same thing (confusion of the inverse)."
P(positive test | has disease) ≠ P(has disease | positive test). This is the prosecutor's fallacy in law: P(evidence | innocent) ≠ P(innocent | evidence). The two are related by Bayes' theorem, but swapping them is wrong. Example: P(drunk|stumbling)≠P(stumbling|drunk).
📖 Ross — A First Course in Probability, Ch. 3.3
Forgetting the denominator P(B) — using P(B|A)·P(A) as the posterior
✅ The denominator P(B) normalizes the posterior so it sums to 1. P(A|B) = P(B|A)P(A) / [P(B|A)P(A) + P(B|Ac)P(Ac)]. Without dividing by P(B), the result is not a proper probability.
🔍 Students compute numerator only and report 0.0099 instead of dividing by P(+)≈0.059.
Using sensitivity = specificity confusion
✅ Sensitivity = P(+|Disease) = true positive rate. Specificity = P(−|No Disease) = true negative rate. False positive rate = 1 − specificity. False negative rate = 1 − sensitivity. These four rates form a 2×2 confusion matrix.
🔍 Plugging specificity into the sensitivity slot in Bayes' formula.
Ignoring that probability must be between 0 and 1 when computing Bayes
✅ All probabilities (prior, likelihood, marginal, posterior) must lie in [0,1] and conditional probabilities must sum to 1 over the conditioning set. Check: P(+|D)+P(-|D)=1 and P(D|+)+P(¬D|+)=1.
🔍 Using percentages (99 instead of 0.99) in Bayes formula without dividing by 100.