Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools

How to Use Bayes' Theorem

You know how likely the evidence is under each cause and want how likely each cause is after seeing the evidence. Multiply the prior by the rate, then divide by the total chance of the evidence.

Recognize the task

The given conditional points the other way from the one asked: the test detects the disease 95%95\% of the time, but what is the chance of the disease given a positive test? Also "which machine made the defective part", "which urn was the ball from". Test: you know P(E∣H)P(E \mid H) and need P(H∣E)P(H \mid E).
The formula is in Bayes' theorem (the formula); its denominator comes from the role of total probability.

Ways to do it

Formulausual choice
P(H∣E)=P(E∣H) P(H)P(E)P(H \mid E) = \frac{P(E \mid H)\,P(H)}{P(E)}
Bayes' theorem with P(E)P(E) from the law of total probability.
Natural frequenciesno formula
true positivesall positives\frac{\text{true positives}}{\text{all positives}}
Imagine 1000010000 people, split them by the rates, and count.
Treevisual
one pathall paths with E\frac{\text{one path}}{\text{all paths with } E}
Draw the tree diagram, then divide the path you want by all paths ending in the evidence.

Steps

StepOn a test: 1% have the disease, 95% detected, 5% false positives
1Name the cause and the evidence. The cause is what you want to know; the evidence is what you observed.HH = has the disease, EE = tests positive
2Write the prior and the two rates. Read them from the question.P(H)=0.01P(H) = 0.01, P(E∣H)=0.95P(E \mid H) = 0.95, P(E∣Hc)=0.05P(E \mid H^c) = 0.05
3Find the total chance of the evidence. Add the true and the false positives.P(E)=0.0095+0.0495=0.059P(E) = 0.0095 + 0.0495 = 0.059
4Divide the cause path by the total. Round at the end only.P(H∣E)=0.00950.059=19118≈0.1610P(H \mid E) = \frac{0.0095}{0.059} = \frac{19}{118} \approx 0.1610

Worked examples

Example 1 · which machine

two causes
M1M_1: 60%60\% at 2%2\% defective, M2M_2: 40%40\% at 5%5\%
P(D)=0.012+0.02=0.032P(D) = 0.012 + 0.02 = 0.032
total probability
P(M2∣D)=0.020.032=0.625P(M_2 \mid D) = \frac{0.02}{0.032} = 0.625

Example 2 · which urn

equal priors
coin picks urn 1 (33 red of 55) or urn 2 (11 red of 55)
P(R)=310+110=25P(R) = \frac{3}{10} + \frac{1}{10} = \frac{2}{5}
both paths to red
P(urn 1∣R)=3/102/5=34P(\text{urn 1} \mid R) = \frac{3/10}{2/5} = \frac{3}{4}

Example 3 · a second positive test

posterior as new prior
new prior 19118\frac{19}{118}; healthy 99118\frac{99}{118}
result of the first test
19⋅0.9519⋅0.95+99⋅0.05=18.0523\frac{19 \cdot 0.95}{19 \cdot 0.95 + 99 \cdot 0.05} = \frac{18.05}{23}
the 118 cancels
P(H∣E1,E2)≈0.7848P(H \mid E_1, E_2) \approx 0.7848
rounded to 4 places

See it happen

Picture 1000010000 people: 100100 are sick and 9595 of them test positive; 99009900 are healthy and 495495 of them test positive too. Of the 590590 positives, only 9595 are sick, about 16%16\%. The rare cause is swamped by false alarms from the large group. Try other rates in the Bayes calculator.

Common mistakes

Reading the rate as the answer

✗ P(H∣E)=0.95P(H \mid E) = 0.95 because the test is 95%95\% accurate
✓ 0.950.95 is P(E∣H)P(E \mid H); with a 1%1\% prior P(H∣E)≈0.1610P(H \mid E) \approx 0.1610

Forgetting the false positives

✗ P(E)=0.0095P(E) = 0.0095
✓ add the healthy positives: 0.0095+0.0495=0.0590.0095 + 0.0495 = 0.059

Using the wrong numerator

✗ P(E∣H)P(E)\frac{P(E \mid H)}{P(E)}
✓ multiply by the prior: P(E∣H) P(H)P(E)\frac{P(E \mid H)\,P(H)}{P(E)}