Mathematics · Simulator 049
Start with a belief, then update it with evidence. In test mode, see why a positive result for a rare disease often still means you're probably healthy. In coin mode, flip a possibly biased coin and watch the probability distribution for its bias sharpen with each flip.
Class 11–12CollegeClass 12 Maths: Probability (Bayes' theorem)
Bayes' theorem turns a prior belief into a posterior after seeing evidence E:
P(H | E) = P(E | H) · P(H) / P(E)
Medical test. With prevalence p, sensitivity (true positive rate) s and specificity (true negative rate) c:
P(disease | +) = s·p / (s·p + (1 − c)(1 − p))
The icon grid shows 1000 people, so you can count the true and false positives directly. When the disease is rare, false positives from the large healthy group can outnumber true positives.
Coin bias. The prior for the probability of heads θ is a Beta(α, β) distribution. After h heads and t tails, the posterior is Beta(α + h, β + t) (a conjugate update). Its mean (α + h)/(α + β + h + t) moves towards the observed frequency, and its spread shrinks as data accumulate.
Assumes the test result or flips are independent given the true state, and that the stated rates are exact.
A test has 90% sensitivity and 90% specificity. For what prevalence does a positive result mean exactly a 50% chance of disease?
Set s·p = (1 − c)(1 − p): 0.9p = 0.1(1 − p), so p = 0.1. At 10% prevalence, true and false positives are equally common. Below that, most positives are false.
A screening test: prevalence 2%, sensitivity 90%, specificity 97%. Picture 1 000 people.
Sick: 20 people, of whom 90% test positive: 18 true positives. Healthy: 980 people, of whom 3% test positive: about 29 false positives.
P(disease | positive) = 18 / (18 + 29.4) ≈ 38%. Most positives are false, because the healthy group is so much larger.
A negative result is reassuring: only 2 of about 953 negatives are sick, 0.2%.
Coin: start with a flat prior Beta(1, 1) and see 7 heads and 3 tails. The posterior is Beta(8, 4), with mean 8/12 ≈ 0.67. Set prevalence 2%, sensitivity 90% and specificity 97% to count the icons.
A rule for updating a probability with new evidence: P(H | E) = P(E | H) P(H) / P(E). The prior belief is combined with how likely the evidence is under each possibility.
When few people have the disease, even a small false-positive rate among the many healthy people produces more false positives than there are true ones.
The prior is what you believe before seeing the data, and the posterior is the updated belief after. Today's posterior becomes the prior for the next piece of evidence.