Bayes' Theorem
calculator.
Bayes' rule updates a probability when evidence arrives, such as a positive test.
- Prior
- 1%
- P(B), how often B occurs
- 9.81%
- Likelihood ratio
- 10
This evidence raises the chance from 1% to 9.17%. Most positives are false, because 990 people without it give 89.1 false alarms.
The same answer as counts of people
Of 1,000 people, 10 have it and 9 of them show the evidence. Of the 990 without it, 89.1 show it too.
How the base rate drives the answer
Drag the point to change the base rateWith a hit rate of 90% and a false alarm rate of 9%, the posterior runs from 0.1% at a 0.01% prior to 99.9% at 99%. Your prior of 1% gives 9.17%.
Other base rates
| Prior | P(A | B) | True, per 10,000 with B |
|---|---|---|
| 0.1% | 1% | 99 |
| 1% | 9.2% | 917 |
| 5% | 34.5% | 3,448 |
| 10% | 52.6% | 5,263 |
| 25% | 76.9% | 7,692 |
| 50% | 90.9% | 9,091 |
What base rate would you need?
- Base rate needed
- 9.091%
- Your base rate
- 1%
More positives in a row
| Positives in a row | P(A | all of them) |
|---|---|
| 1 | 9.17% |
| 2 | 50.25% |
| 3 | 90.99% |
This holds only if each result is independent given the true state. Repeating the same test usually falls short of that.
Reading the likelihood ratio
- LR+, how much a positive multiplies the odds
- 10
- LR−, how much a negative multiplies the odds
- 0.11
A positive ratio above 10 and a negative ratio below 0.1 are usually taken as strong evidence to rule in and to rule out.
Working
- 1The chance A is falseP(not A) = 1 − 1% = 99%
- 2How often the evidence turns upP(B) = 90% × 1% + 9% × 99% = 9.81%
- 3Bayes’ theoremP(A | B) =90% × 1%9.81%= 9.17%
- 4The same thing in oddsPosterior odds = likelihood ratio × prior odds = 10 × 0.0101 = 0.101
- 5Check: true positives over all positives gives the same answer998.1= 9.17%
How it's worked out
You need three numbers: how common A is before the evidence, how often the evidence shows up when A is true, and how often it shows up when A is false. The theorem combines them.
P(A) is the prior, or base rate. P(B | A) is the hit rate, which a medical test calls sensitivity. P(B | not A) is the false alarm rate, which is 1 minus the specificity. P(B) is how often the evidence turns up at all, counting both the true and the false cases.
The same rule is simpler in odds. Odds are the chance of A over the chance of not A. The likelihood ratio compares how well A and not A predict the evidence, and it multiplies the odds:
A test with a 90% hit rate and a 9% false alarm rate has a likelihood ratio of 10. A base rate of 1% is odds of 1 to 99, so the odds after a positive are 10 to 99. That is a chance of 9.2%.
Worked examples
A screening test for a condition 1 in 100 people have
Picture 1,000 people. About 10 have the condition, and the test catches 9 of them. Of the 990 without it, 89.1 still test positive.
So 98.1 people test positive and only 9 are true cases, which gives 9.2%. A second, independent positive raises it to 50.3%, and a third to 91%. To reach even odds with one positive, this test needs a base rate of about 9.1%.
The mammography problem from the 1995 study
Gigerenzer and Hoffrage used a 1% base rate, an 80% hit rate and a 9.6% false alarm rate. The answer is 7.8%. As counts, that is 8 true positives against 95 false ones per 1,000 women.
They report an earlier study in which 95 of 100 physicians put this chance between 70% and 80%. In their own studies, Bayesian answers rose from 16% with percentages to about 46% to 50% when the same problem was given as counts.
A spam filter, where the base rate is high
Say 60% of incoming mail is spam, and the filter flags 98% of spam and 2% of good mail. A flagged message is spam with a chance of 98.7%. The 8 good messages flagged per 1,000 matter little next to 588 real catches.
Here the prior does much of the work. That is why the same maths gives such different answers from the screening test, which has a far lower base rate and a false alarm rate of 9% in place of 2%.
Reading your result
The base rate often matters more than the accuracy. The table holds a test at a 95% hit rate and a 5% false alarm rate, and changes only the base rate. Reading P(B | A) as if it were P(A | B) is called the base rate fallacy, or confusion of the inverse.
| Base rate | P(A | positive) |
|---|---|
| 0.1% | 1.9% |
| 1% | 16.1% |
| 5% | 50% |
| 10% | 67.9% |
| 20% | 82.6% |
| 50% | 95% |
The likelihood ratio tells you how far the evidence moves you. Deeks and Altman write that likelihood ratios above 10 and below 0.1 are taken as strong evidence to rule a diagnosis in or out. A ratio of exactly 10, as in the screening example, sits right at that line, and it still leaves a positive result under 10% at a 1% base rate.
A negative result has its own answer. P(A | no B) is the chance that A is still true after a negative. For the screening example it is 0.111%, so a negative leaves little doubt here, while a positive leaves a lot. One minus this figure is the negative predictive value.
Use the right base rate. The rate in a clinic, where people arrive with symptoms, can be much higher than in the general public, and so the same test gives a higher answer there. This tool checks arithmetic and teaches the idea. It does not interpret anyone's own test result, so take that to a clinician.
Common mistakes
- Swapping the two conditionals. A 90% hit rate says what happens to people who have the condition. It does not tell a person with a positive result that they have a 90% chance.
- Leaving out the false alarms. Without P(B | not A) there is no answer at all, since the healthy group is where most positives come from when A is rare.
- Treating a repeat as independent. A second run of the same test can repeat the same error for the same reason, so the climb in the repeat table is a best case. A different kind of test is closer to the assumption.
- Comparing two hypotheses that have no clear rates. When a study gives you a t statistic or a chi-square and not hit rates, the Bayes factor calculator is the better fit.