MathsStatistics & Probability

Bayes' Theorem
calculator.

Bayes' rule updates a probability when evidence arrives, such as a positive test.

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|B)\displaystyle P(A \mid B)=P(B|A)P(A)P(B)\displaystyle {}= \frac{P(B \mid A)\, P(A)}{P(B)}
P(B)\displaystyle P(B)=P(B|A)P(A)\displaystyle {}= P(B \mid A)\, P(A)+P(B|not A)P(not A)\displaystyle {}+ P(B \mid \text{not } A)\, P(\text{not } A)

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:

posterior odds\displaystyle \text{posterior odds}=P(B|A)P(B|not A)×prior odds\displaystyle {}= \frac{P(B \mid A)}{P(B \mid \text{not } A)} \times \text{prior 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%.

Open this example in the tool

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.

Open this example in the tool

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%.

Open this example in the tool

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.

One test at different base rates
Base rateP(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.

Questions people ask

Because the healthy group is so much bigger. At a 1% base rate and a 9% false alarm rate, about 89.1 of every 1,000 people test positive falsely, and only 9 test positive truly. A low rate applied to a huge group beats a high rate applied to a small one.

Sources