Home / Probability

Bayes' Theorem

A test is 99% accurate and you test positive. Are you 99% likely to be ill? Almost certainly not — and this grid of 10,000 people shows exactly why.

Controls

base rate P(D)1.0%
sensitivity P(+|D)99%
specificity P(−|not D)99%

has it & tests positive
healthy but tests positive
has it, missed by test
healthy, correctly negative

10,000 People, One Square Each

natural frequencies

Live Calculation

true positives
0
false positives
0
all positives
0
P(ill | positive)
0%

Overview

Update a probability with evidence

For events A and B with P(B) > 0:

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

The prior P(A) is updated by the likelihood P(B|A), then normalised by the total chance of the evidence. For competing explanations Aᵢ, the denominator is the sum ΣᵢP(B|Aᵢ)P(Aᵢ). The conditional probability lesson explains why the direction of the condition matters.

Bayes’ Theorem

Bayes’ theorem updates a prior probability by weighting it with how likely the evidence is under each explanation.

A medical-test example

Suppose a condition affects 1% of a population. A test has 90% sensitivity and 5% false-positive rate. Among 10,000 people, about 100 have the condition and 90 test positive; among the 9,900 without it, about 495 test positive. Thus a positive result corresponds to 90/(90+495) ≈ 15.4% chance of the condition, not 90%.

These values are illustrative; a real interpretation requires validated test performance for the relevant population. Changing prevalence changes the posterior even when sensitivity and specificity stay the same.

Separate prior, likelihood, and posterior

The prior P(A) is the probability assigned to a hypothesis before the evidence. The likelihood P(B|A) says how probable the evidence would be if that hypothesis were true. The posterior P(A|B) is the updated probability after observing B. The denominator P(B) normalises the competing explanations so their posterior probabilities sum to one. A likelihood is not itself a probability that the hypothesis is true.

For the test above, the total positive rate is 0.90(0.01)+0.05(0.99)=0.0585. The positive-and-condition group has probability 0.90(0.01)=0.009, so P(condition | +)=0.009/0.0585≈0.154. The low base rate means false positives from the much larger unaffected group outnumber true positives. If prevalence rises, the same positive test produces a higher posterior. Real screening requires test-performance estimates suited to the population and protocol; this calculation is an illustration, not medical advice.

Bayes’ theorem is also used in spam filtering and reliability analysis. Include all plausible explanations in the denominator; leaving out a competing cause distorts the update.

Try this above

Adjust the prevalence while holding sensitivity and false-positive rate fixed. Notice how the posterior probability changes with the base rate.

For multiple hypotheses A₁,…,Aₖ that form a complete set, P(Aᵢ|B)=P(B|Aᵢ)P(Aᵢ)/ΣⱼP(B|Aⱼ)P(Aⱼ). This form makes explicit that evidence is compared across alternatives. New evidence can be incorporated by taking the current posterior as the next prior, provided the likelihood model is updated consistently. A Bayesian answer depends on both the likelihood and prior; where prior information comes from should be reported when it materially affects the conclusion.

A useful diagnostic is to calculate expected counts as well as probabilities. In a group of 10,000 people, 1% prevalence gives 100 affected people: 90 test positive. Of the 9,900 unaffected people, 495 are false positives, so 90 of 585 positives are true positives. This count view makes the denominator tangible and can prevent reversing sensitivity and positive predictive value. The estimate changes if the screened population has a different prevalence, even when the laboratory test is unchanged.

Sources and next steps

Predict, then reveal

About to run: set sensitivity P(+|D) to its minimum (50). Before it does — what happens to the readout?

Committing to an answer first is the point — the reveal runs the experiment on the visualisation above and reads the real value back, so nothing here is scripted.

Check yourself

0 of 2

Answer without scrolling back up.

  1. What does the prior probability represent in Bayes’ theorem?

  2. Why can a positive test have a low chance of indicating disease?

Cheat sheet

Bayes' Theorem

Update a prior belief with new evidence and see why a 99%-accurate test still gives mostly false positives when the condition is rare.

MATHS · vizlearn.in/maths/bayes_theorem.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.