Understanding the Bayes' theorem calculator — concept and principle
Bayes' theorem updates a probability when new evidence arrives. The classic use is a diagnostic or screening test: given how common a condition is (the prior), how often the test detects it (sensitivity) and how often it falsely alarms (false positive rate), what is the chance that a person with a positive result really has the condition? The same logic drives spam filters and fraud alerts.
How it is calculated
Let A be "has the condition" and B be "test is positive". Enter the three rates as percentages.
- P(B) = P(B|A)·P(A) + P(B|not A)·(1 − P(A)) — total probability of a positive result.
- P(A|B) = P(B|A)·P(A) ÷ P(B) — positive predictive value (PPV).
- P(A|not B) = P(A)·(1 − P(B|A)) ÷ (1 − P(B)) — the chance the condition is present despite a negative result.
The principle
Bayes' theorem follows from writing the same overlap two ways: P(A ∩ B) = P(B|A)·P(A) = P(A|B)·P(B). Dividing by P(B) turns "how likely is the evidence if A is true" into "how likely is A given the evidence". The key insight is that positives come from two groups: true positives among the few who have the condition and false positives among the many who do not. When the condition is rare, the second group can be far larger, even with a good test.
Worked example
Imagine 10,000 people, using the defaults: prior 1%, sensitivity 90%, false positive rate 5%.
- With the condition: 1% of 10,000 = 100 people; 90% test positive = 90 true positives.
- Without: 9,900 people; 5% test positive = 495 false positives.
- P(B) = (90 + 495) ÷ 10,000 = 5.85%.
- P(A|B) = 90 ÷ 585 = 15.38%. Only about one positive in six or seven is real.
- Negatives: 10 missed cases among 10,000 − 585 = 9,415 negatives, so P(A|not B) = 10 ÷ 9,415 = 0.11%.
| P(B|not A) — false positive rate (%) | P(A|B) |
|---|---|
| 1.25 | 42.11% |
| 2.5 | 26.67% |
| 3.75 | 19.51% |
| 5 | 15.38% |
| 6.25 | 12.7% |
| 7.5 | 10.81% |
| 10 | 8.33% |
How to read the result
P(A|B) depends strongly on the prior. With the same test, a prior of 10% would give P(A|B) = 9 ÷ 13.5 ≈ 66.7%. This is why a positive screening result for a rare condition is usually followed by a second, more specific test, and why the same test means more in a high-risk group. P(A|not B) shows how reassuring a negative result is.
Common mistakes
- Base-rate neglect: treating 90% sensitivity as a 90% chance of having the condition.
- Confusing the false positive rate (P(B|not A)) with specificity, which is 1 minus it (here 95%).
- Mixing up P(B|A) and P(A|B), sometimes called the prosecutor's fallacy.
Frequently asked questions
What happens if I test positive twice?
If the two tests are independent, use the first posterior (15.38%) as the new prior and apply the theorem again; with the same test it rises to about 76.6%.
What is the difference between PPV and sensitivity?
Sensitivity is P(positive | condition) and is a property of the test. PPV is P(condition | positive) and also depends on how common the condition is.
Sources: Sheldon M. Ross, A First Course in Probability, Pearson — conditional probability and Bayes' formula · Gerd Gigerenzer, Calculated Risks, Simon & Schuster — natural frequencies for test results