📊 Section 1 -- Interactive Simulation
Controls
Scenario
Display
💡 Section 2 -- The Idea, Step by Step
Picture a rare disease that only about 1 person in 100 actually has, and a test that is "pretty good." If your own test comes back positive, should you panic? Surprisingly, often not. Because the healthy crowd is so much larger than the sick crowd, most of the positive results in the whole population come from healthy people who were flagged by mistake. The real question is not "how accurate is the test?" but "out of everyone who tests positive, what share are truly sick?"
Three numbers settle it. The prior $P(A)$ is how common the condition is before any testing — here 1%. The likelihood (or sensitivity) $P(B|A)$ is how often a sick person tests positive — say 99%. The false-positive rate $P(B|A^c)$ is how often a healthy person tests positive — say 5%. Now count out 10,000 people. About 100 are sick, and 99 of them test positive. Of the 9,900 healthy people, 5% — about 495 — also test positive. So out of $99+495=594$ positive results, only 99 are real: $99/594 \approx 16.7\%$.
$$P(A|B)=\frac{\text{truly positive}}{\text{everyone who tests positive}}=\frac{99}{99+495}\approx 0.167.$$
Written exactly, that fraction is Bayes' theorem: $P(A|B)=\dfrac{P(B|A)\,P(A)}{P(B|A)\,P(A)+P(B|A^c)\,P(A^c)}$. The denominator is just every way of testing positive — the sick branch plus the healthy branch — each weighted by how likely that group is to begin with (the law of total probability). The three sliders map straight onto the inputs: Prior $P(A)$, Sensitivity $P(B|A)$, and FP rate $P(B|A^c)$. The frequency tree on the canvas splits the 10,000 people exactly as above, and the posterior readout updates live as you drag.
Try this in the sim above. First, keep sensitivity at 0.99 but drag the prior from 0.01 up toward 0.5 and watch the posterior leap from about 17% to over 95% — the base rate, not the test, is doing most of the work. Second, set the FP rate down to 0.001 and see how a single positive becomes almost conclusive even for a rare disease. Third, press Animate to sweep the prior across its whole range and watch the posterior curve climb — gentle at first, then steeply once the condition stops being rare.
📐 Section 3 -- Probability Spaces & Bayes
$$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)}.$$
| Term | Meaning | Example (disease) |
|---|---|---|
| $P(A)$ | Prior probability of event | Prevalence: 1% |
| $P(B|A)$ | Likelihood / sensitivity | Test+|Disease: 99% |
| $P(B|A^c)$ | False positive rate | Test+|No disease: 5% |
| $P(A|B)$ | Posterior probability | Disease|Test+: ~16.7% |
$(\Omega,\mathcal{F},P)$ where $\Omega$ = sample space, $\mathcal{F}$ = $\sigma$-algebra of events, $P$ = probability measure. Axioms: $P(\Omega)=1$, $P(A)\geq0$, countable additivity $P(igcup A_i)=\sum P(A_i)$ for disjoint $A_i$.
$P(A|B)=P(A\cap B)/P(B)$ for $P(B)>0$. Intuition: restrict the sample space to $B$ and re-normalize. This is NOT the same as $P(B|A)$ -- the classic base-rate neglect error.
If $\{B_i\}$ is a partition of $\Omega$: $P(A)=\sum_i P(A|B_i)P(B_i)$. For two events: $P(B)=P(B|A)P(A)+P(B|A^c)P(A^c)$. This is the denominator in Bayes.
Disease prevalence 1%, sensitivity 99%, false positive 5%. Positive test: $P(D|+)=0.99 imes0.01/(0.99 imes0.01+0.05 imes0.99)=0.0099/0.0099+0.0495)=0.0099/0.0594pprox16.7\%$. Despite 99% sensitivity, most positives are false -- because disease is rare. Move the slider!
$A,B$ independent iff $P(A\cap B)=P(A)P(B)$ iff $P(A|B)=P(A)$ (knowing $B$ gives no information about $A$). Independence is symmetric: $A\perp B\Rightarrow B\perp A$. Pairwise independence does NOT imply mutual independence (see Bernstein example).
Odds $O(A)=P(A)/P(A^c)$. Posterior odds $=$ prior odds $ imes$ likelihood ratio: $rac{P(A|B)}{P(A^c|B)}=rac{P(A)}{P(A^c)}\cdotrac{P(B|A)}{P(B|A^c)}$. The likelihood ratio $P(B|A)/P(B|A^c)$ is how much the evidence updates the odds.
❓ Section 4 -- FAQ
They are completely different. P(Disease|Test+) is what you want (probability of disease given a positive test). P(Test+|Disease) is the sensitivity -- probability of a positive test given you have disease. Confusing them is the "inverse probability fallacy" or "prosecutor's fallacy." Bayes converts one into the other.
Key takeaway: P(A|B) and P(B|A) are different quantities. Bayes theorem converts between them using P(A) and P(B).A frequency tree (natural frequencies): 10000 people, P(A)*10000 have condition A. Of those, P(B|A)*[count A] test positive. Of the others P(A^c)*10000, P(B|Ac)*[count Ac] test positive. The posterior P(A|B) is the fraction of all positives who truly have A. Visualizing natural frequencies dramatically reduces base-rate neglect errors.
Key takeaway: Natural frequency visualization: out of 10000 people, count who are truly positive vs false positive.Medical diagnosis (as shown). Spam filters: P(spam|contains "free") updated by each word. Bayesian inference in ML: update parameter distribution as data arrives. Search and rescue: update location probability as new evidence arrives. Credit scoring: update default probability with payment history. DNA forensics.
Key takeaway: Medical diagnosis, spam filters, Bayesian ML, search/rescue, DNA forensics -- all Bayes theorem.Yes -- when prevalence is 1% and false positive rate is ~1%. Example: 99% sensitivity, 1% FPR, 1% prevalence. P(D|+) = 0.99*0.01/(0.99*0.01+0.01*0.99) = 0.5. The test is 50-50! This is why screening tests for rare diseases require confirmatory testing.
Key takeaway: With 1% prevalence and 1% FPR, even a 99% sensitive test gives only 50% posterior -- base rate dominates.P(B) = 0.7*0.3 + 0.2*0.7 = 0.21+0.14 = 0.35. P(A|B) = 0.7*0.3/0.35 = 0.21/0.35 = 0.6. So knowing B occurred increases probability of A from 30% to 60%.
Key takeaway: Bayes: posterior = 0.21/0.35 = 0.6. Prior 30% updated to posterior 60% upon observing B.Frequentist: probability = long-run frequency in repeated experiments. P(heads) = fraction of heads in many flips. Cannot assign probability to one-off events. Bayesian: probability = degree of belief. Can say P(hypothesis|data). Uses prior distribution updated by likelihood to get posterior. Machine learning largely uses Bayesian thinking; classical statistics uses frequentist. Both are self-consistent frameworks.
Key takeaway: Frequentist: probability = long-run frequency. Bayesian: probability = degree of belief, updated by Bayes theorem.