Understanding your Bayes' theorem result
Holding the sensitivity at 95% and the false-positive rate at 5% fixed, the table below shows how dramatically the posterior probability changes with the prior — this is the base-rate effect at the heart of Bayes' theorem.
| Prior P(A) | Posterior P(A | B), at 95% sensitivity / 5% false-positive rate |
|---|---|
| 0.1% | ≈ 1.87% |
| 1% | ≈ 16.10% |
| 10% | ≈ 67.86% |
| 50% | ≈ 95.00% |
- The posterior probability is highly sensitive to the prior probability, especially when the prior is small — this is why base rates cannot be ignored when interpreting a positive test result or other new evidence.
- This calculator's formula applies to a binary partition: an event A and its complement ¬A. Situations with more than two mutually exclusive possibilities (for example, more than one candidate diagnosis) require the fuller form of the law of total probability across all possibilities.
- The false-positive rate, P(B | ¬A), is not the same as specificity — it equals 1 minus specificity, so a test described as '95% specific' has a 5% false-positive rate.
- Rounding intermediate probabilities before combining them can distort the final posterior noticeably, particularly when the prior is small; carry full precision through the calculation where possible.
What is Bayes' theorem?
Bayes' theorem is a formula for updating the probability of an event (A) after observing new evidence (B), combining a prior probability with how likely that evidence is under different scenarios. It is written P(A | B) = P(B | A) × P(A) / P(B), and it converts a 'forward' probability, such as how likely a positive test result is given a disease, into the 'reverse' probability that is usually of real interest: how likely the disease is given a positive result.
This calculator uses the common diagnostic-testing framing: P(A) is the prior probability (base rate) of the condition in the relevant population before any test is run, P(B | A) is the sensitivity — the probability of a positive result given the condition is present — and P(B | ¬A) is the false-positive rate — the probability of a positive result given the condition is absent (equal to 1 minus specificity).
The base-rate fallacy is the common error of focusing on a test's sensitivity while ignoring the prior probability. A test can have high sensitivity and a low false-positive rate and still produce a posterior probability far below what intuition suggests, whenever the condition being tested for is rare in the population.
How to use this Bayes' theorem calculator
- Enter the prior probability P(A) — the base rate of the event or condition in the relevant population, as a percentage.
- Enter P(B | A), the sensitivity — the probability of observing the evidence given the event is true.
- Enter P(B | ¬A), the false-positive rate — the probability of observing the evidence given the event is not true.
- Read the posterior probability P(A | B), the total probability of the evidence P(B), and the likelihood ratio (Bayes factor), which compares how much more likely the evidence is under A versus under ¬A.
The formula behind Bayes' theorem
Bayes' theorem expands the denominator P(B) using the law of total probability across the two possibilities A and ¬A: P(A | B) = [P(B | A) × P(A)] / [P(B | A) × P(A) + P(B | ¬A) × (1 − P(A))].
Worked example: prior P(A) = 1%, sensitivity P(B | A) = 95%, false-positive rate P(B | ¬A) = 5%. Numerator: 0.95 × 0.01 = 0.0095. Total probability of a positive result: P(B) = 0.95 × 0.01 + 0.05 × 0.99 = 0.0095 + 0.0495 = 0.059. Posterior: P(A | B) = 0.0095 / 0.059 ≈ 0.1610, so the posterior probability is approximately 16.10% — even though the test correctly identifies 95% of true cases, most positive results in this scenario come from the much larger pool of people who do not have the condition.
The likelihood ratio (Bayes factor) is P(B | A) / P(B | ¬A). In the worked example, 0.95 / 0.05 = 19, meaning a positive result is 19 times more likely to occur if A is true than if A is false.
Common mistakes
- Confusing P(B | A), the sensitivity, with P(A | B), the posterior probability — assuming a highly sensitive test result means a high probability of actually having the condition, while ignoring the base rate, is the classic base-rate fallacy.
- Ignoring the prior probability entirely — a test with 95% sensitivity and a 5% false-positive rate still gives a posterior of only about 16% when the prior is 1%, because most positive results come from the much larger pool of true negatives.
- Treating specificity and the false-positive rate as interchangeable without converting — this calculator asks for P(B | ¬A), the false-positive rate, which equals 1 minus specificity.
- Applying the two-term formula when there are more than two mutually exclusive possibilities — the simple A versus ¬A version only holds for a binary partition of outcomes.
- Rounding intermediate probabilities before combining them, which compounds error in a calculation that is especially sensitive to small changes in the prior at low base rates.
常见问题
Why can a 95%-accurate test still be wrong most of the time on a positive result?
When the underlying condition is rare, most positive results come from the much larger pool of people without the condition who tested false-positive, rather than from the small pool of people who actually have it. With a 1% prior, 95% sensitivity and 5% false-positive rate, the posterior probability given a positive result is only about 16.10%, even though the test is 95% accurate on true cases.
What is the base-rate fallacy?
The base-rate fallacy is the common error of judging the probability of an event given evidence (such as a positive test) based mainly on the evidence's accuracy while ignoring how rare or common the event is in the first place. Bayes' theorem corrects for this by explicitly incorporating the prior probability.
What is the difference between sensitivity, specificity and the false-positive rate?
Sensitivity is the probability of a positive result given the condition is present, P(B | A). Specificity is the probability of a negative result given the condition is absent. The false-positive rate is the complement of specificity — the probability of a positive result given the condition is absent, P(B | ¬A) = 1 − specificity.
What is a Bayes factor (likelihood ratio)?
The Bayes factor, or likelihood ratio, is P(B | A) divided by P(B | ¬A) — how many times more likely the observed evidence is under A than under ¬A. In the worked example on this page (95% sensitivity, 5% false-positive rate), the Bayes factor is 19, meaning a positive result is 19 times more likely if the condition is present than if it is absent.
How does the prior probability affect the posterior?
Dramatically. Holding sensitivity and the false-positive rate fixed, a lower prior produces a much lower posterior, because a larger share of positive results comes from false positives among the many true negatives. Raising the prior from 1% to 10% (holding 95% sensitivity and 5% false-positive rate fixed) raises the posterior from about 16.10% to about 67.86%.
Do the prior, sensitivity and false-positive rate need to sum to 100%?
No. These are three separate probabilities describing different things — the base rate of the event, and the two conditional probabilities of the evidence under each scenario — and none of them need to sum to any particular total.
参考文献
- Bayes T, Price R. An Essay towards Solving a Problem in the Doctrine of Chances. Philosophical Transactions of the Royal Society of London 1763; 53: 370-418.
- Kahneman D, Tversky A. On the psychology of prediction. Psychological Review 1973; 80(4): 237-251 (base-rate neglect in probability judgment).
- National Institute of Standards and Technology (NIST). NIST/SEMATECH e-Handbook of Statistical Methods — probability rules and Bayes' theorem. nist.gov.
- Moore DS, McCabe GP, Craig BA. Introduction to the Practice of Statistics. W. H. Freeman (conditional probability and Bayes' rule).
- Casella G, Berger RL. Statistical Inference (2nd ed). Duxbury, 2002 (Bayes' theorem and conditional probability).