SimuVeda/ Mathematics

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.

Class 11–12CollegeClass 12 Maths: Probability (Bayes' theorem)

Experiments 0 of 0 Challenge not tried

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.

Related simulators

Worked example

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.

Common questions

What is Bayes' theorem?

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.

Why can a positive test for a rare disease still mean you are probably healthy?

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.

What are a prior and a posterior?

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.

Keyboard shortcuts

Space
Play or pause
S
Step
R
Reset
F
Full screen
?
Show this list