Statistics Reference

Bayes' Theorem Explained with Real Tests

A screening test is “90% accurate” and yours came back positive. The probability you actually have the condition is not 90% — in the worked example below it is 9.2%. That gap between evidence strength and belief is exactly what Bayes' theorem computes, and this guide walks the full arithmetic honestly, twice: once with the formula, once with plain counts.

The Theorem and Its Parts

P(A|B) = P(B|A) × P(A) / P(B)

posterior = likelihood × prior / evidence

P(B) = P(B|A)P(A) + P(B|not A)P(not A)

The theorem's job is a direction reversal. Studies and test manufacturers measure P(evidence | condition) — how often sick patients test positive. Decisions need P(condition | evidence) — how likely a positive patient is sick. The two differ whenever the condition is rare or common, and the prior P(A) is what carries that base-rate information into the answer.

Worked Example: A Rare Condition, an Accurate Test

A condition affects 1% of the population(prevalence, the prior). The screening test has 90% sensitivity (sick people test positive 90% of the time) and a 9% false-positive rate (91% specificity). A random person tests positive — what is P(sick | positive)?

  1. Numerator (true-positive path): P(+|sick) × P(sick) = 0.90 × 0.01 = 0.009.
  2. Evidence (all positives): 0.009 + P(+|healthy) × P(healthy) = 0.009 + 0.09 × 0.99 = 0.009 + 0.0891 = 0.0981.
  3. Posterior: 0.009 / 0.0981 ≈ 0.0917 — about 9.2%.

Enter prior 0.01, P(B|A) 0.90, and P(B|¬A) 0.09 into the Bayes' theorem calculator to reproduce every intermediate value, including the total P(B) = 0.0981.

The Same Arithmetic in Natural Frequencies

The formula becomes obvious when run on 10,000 concrete people:

GroupCountTest positiveKind of positive
Sick (1%)10090 (90%)True positives
Healthy (99%)9,900891 (9%)False positives
All positives98190 / 981 ≈ 9.2% real

The 891 false alarms swamp the 90 real cases simply because the healthy group is 99 times larger. Nothing about the test is broken — rarity itself dilutes positive results. This base rate fallacy (ignoring the 1% while staring at the 90%) is among the most reliably documented reasoning errors in medicine and law.

Updating Again: The Second Test

Bayes' theorem chains: the posterior from one round becomes the prior for the next. After the first positive, the patient's probability is 9.2%. An independent second test with the same accuracy updates it to:

0.90 × 0.0917 / (0.90 × 0.0917 + 0.09 × 0.9083) ≈ 0.502

Two positives move the odds to roughly a coin flip — and a third independent positive would push past 90%. This is why screening programs confirm positives with follow-up tests rather than treating on one result, and why “independent” carries weight: tests sharing a failure mode update far less than the arithmetic pretends. The same chaining logic runs anywhere evidence accumulates — spam filters scoring words, diagnostics combining symptoms, or quality systems combining repeated inspections.

Reading Test Accuracy Claims

  • “90% accurate” is underspecified. Sensitivity and specificity are separate numbers, and the posterior depends on both plus the prevalence.
  • The same test performs differently by population. In a high-risk clinic where prevalence is 20%, the identical test's positive predictive value jumps from 9.2% to 71% — run the calculator with prior 0.20 to see it.
  • Negative results are informative too. Here P(sick | negative) = 0.001 × ... ≈ 0.11%, so a negative nearly rules the condition out — rare conditions make negatives trustworthy for the same reason they make positives weak.

Try the Bayes' Theorem Calculator

Enter a prior and the two conditional rates to get the posterior P(A|B) with the full P(B) breakdown — the worked example automated.

Frequently Asked Questions

What is Bayes' theorem in simple terms?

It is the rule for updating a probability when new evidence arrives: posterior = prior x likelihood / evidence. Concretely, P(A|B) = P(B|A) x P(A) / P(B). It converts 'how likely is the evidence given the hypothesis' - which tests and studies measure - into 'how likely is the hypothesis given the evidence' - which is the question you actually care about.

Why is a positive result from an accurate test still often a false alarm?

Because when the condition is rare, false positives from the huge healthy group outnumber true positives from the tiny sick group. With 1% prevalence, 90% sensitivity, and a 9% false-positive rate, 10,000 people yield 90 true positives but 891 false positives - a positive result is real only 9.2% of the time. The test is fine; the base rate does the damage.

What are the prior, likelihood, and posterior?

The prior P(A) is what you believed before the evidence (for a screening test, the prevalence). The likelihood P(B|A) is how probable the evidence is when the hypothesis is true (the test's sensitivity). The posterior P(A|B) is the updated belief after seeing the evidence - the number Bayes' theorem computes. Today's posterior becomes tomorrow's prior when more evidence arrives.

What is the base rate fallacy?

Judging a hypothesis from the strength of the evidence alone while ignoring how rare the hypothesis was to begin with. 'The test is 90% accurate, so a positive means 90% sick' is the classic form - it silently replaces P(sick|positive) with P(positive|sick). Physicians, judges, and security screeners all fall for it, which is why presenting numbers as natural frequencies (counts per 10,000) helps.

What is the difference between sensitivity and specificity, and where do they enter Bayes' theorem?

Sensitivity is the true-positive rate P(positive|sick); specificity is the true-negative rate P(negative|healthy), so the false-positive rate is 1 - specificity. In the theorem, sensitivity is the likelihood in the numerator; both rates build the denominator P(positive) = sensitivity x prevalence + (1 - specificity) x (1 - prevalence).

Does repeating a test fix the false-positive problem?

Substantially, if the second test's errors are independent of the first: the first positive raises the prior from 1% to 9.2%, and a second positive raises it again to about 50%. That chaining - posterior becomes the new prior - is Bayesian updating in action. The caveat matters, though: if both tests share a failure mode (same lab error, same cross-reacting condition), the second result adds much less than the arithmetic suggests.