SimuVeda

Mathematics · Simulator 049

Bayesian Updating

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.

How the model works

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.

Guided experiments

  1. Rare disease, good test. Prevalence 1%, sensitivity 99%, specificity 95%. Prediction: only about 17% of positives actually have the disease. There are about 50 false positives against 10 true ones.
  2. Test twice. Use the first posterior as the new prior and test positive again. Prediction: the probability jumps to about 80%. A second independent positive is strong evidence.
  3. Is the coin fair? Flat prior, true bias 0.7, flip 100 times. Prediction: the posterior narrows around 0.7. After 100 flips its standard deviation is about 0.045.

Challenge

A test has 90% sensitivity and 90% specificity. For what prevalence does a positive result mean exactly a 50% chance of disease?

Reveal the explanation

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.

References

  • OpenStax, Introductory Statistics, §3.2–3.3 (conditional probability).
  • Gigerenzer & Hoffrage (1995), “How to improve Bayesian reasoning without instruction: frequency formats”, Psychological Review 102: 684–704.