Bayesian Updater
Update a prior probability with sensitivity and false-positive rate.
Overview
The Bayesian Updater turns a prior probability and a noisy test result into a posterior probability. The classic example is a medical screening: if a disease has a base rate of 1% and the test has 95% sensitivity and 5% false-positive rate, what is the chance you actually have it after a positive result?
It is a must-have for anyone learning Bayes' theorem, doctors interpreting screening results, security engineers reasoning about false alarms and product managers thinking about anomaly-detection thresholds. The intuition almost always feels wrong, and seeing the numbers fixes that.
How it works
Bayes' theorem in two-class form is P(H | E) = P(E | H) * P(H) / P(E). With P(H) = prior, sensitivity = P(E | H) (true positive rate) and false-positive rate = P(E | not H), the denominator expands to sensitivity * prior + falsePositive * (1 - prior).
The output is the posterior probability that the hypothesis (e.g., "patient has the disease") is true given the evidence (positive test). Repeating the update with new independent tests is just feeding the posterior back in as the next prior.
Examples
Prior 1%, sensitivity 95%, FPR 5%
→ posterior ≈ 16.1%
Prior 50%, sensitivity 95%, FPR 5%
→ posterior ≈ 95%
Prior 1%, sensitivity 99%, FPR 1%
→ posterior ≈ 50%
Two consecutive positive tests with prior 1%, sens 95%, FPR 5%
→ first posterior 16.1%, second posterior ≈ 78.6%
FAQ
Why is a positive test so often misleading?
When the disease is rare, false positives from the much-larger healthy population outweigh true positives. A 1% prior and a 5% false-positive rate means most positives are healthy people.
What's the difference between sensitivity and specificity?
Sensitivity is the true-positive rate, P(positive | disease). Specificity is the true-negative rate, P(negative | no disease), which equals 1 - false positive rate.
Can I chain multiple tests?
Yes, as long as they are independent. Use the posterior from one as the prior for the next.
What happens with a 0% prior?
The posterior stays at 0%. Bayes' theorem can't lift you out of a hypothesis you've assigned zero credibility to.
Is this just for medical testing?
No — the same formula works for spam filtering, fraud detection, A/B test priors and any binary inference problem.