Bayes' theorem
Reverses a conditional probability: from how likely the evidence is if A is true, to how likely A is given the evidence.
Calculator
The live calculator needs JavaScript. The worked example below shows the same steps it would.
See it move
- P(A | B) = 0.009 ÷ (0.009 + 0.0891) = 0.09174: the share of the B branches (thick) that come through A.
What the symbols mean
- the updated (posterior) probability of A after seeing B
- the prior probability of A, before the evidence (for example how common a disease is)
- the probability of the evidence when A is true (a test's sensitivity)
- the probability of the evidence when A is false (a test's false-positive rate)
- "not A"
When to use it
Use it for medical tests, spam filters, fault diagnosis and any "how likely is the cause, given what I observed?" question. The calculator takes the three numbers you usually know (base rate, true-positive rate and false-positive rate) and works out P(B) for you. The result is often surprising: a good test for a rare condition still gives many false alarms.
Worked example
A disease affects 1% of people. A test detects it 90% of the time, but it also gives a positive result for 9% of healthy people. If you test positive, what is the probability you have the disease?
Start from Bayes’ theorem, with P(B) expanded by the law of total probability.
First, the overall probability of B, true positives plus false positives:
Then the share of those cases where A is true:
As a percentage, about 9.174%. It is low because A is rare to begin with: most cases of B come from the much larger group where A is false.
Answer P(disease | positive) ≈ 0.0917
Why it works
can be written two ways, and . Setting them equal and dividing by P(B) gives the theorem. The tree diagram shows the same thing as counts of branches.
Common mistakes
- Taking the test's accuracy (90%) as the answer and ignoring how rare the disease is (the base-rate fallacy).
- Using P(B) = P(B | A) instead of the total probability over both branches.
- Mixing up the false-positive rate with sensitivity, which is the false-negative rate.