What Bayes' theorem does
Bayes' theorem tells you how to revise a probability when new evidence arrives. You start with a prior - how likely something was before you looked. Evidence arrives. The theorem gives you the posterior: how likely it is now.
The medical test is the standard illustration because every quantity has a name. The prior is the prevalence: how common the condition is in the group being tested. The evidence is a positive test result. The posterior is the positive predictive value: given that you tested positive, how likely is it that you actually have the condition?
The reason this needs a theorem rather than intuition is that people confuse two different conditional probabilities. Sensitivity is P(positive test | you have the condition). What a patient wants to know is P(you have the condition | positive test). Those are not the same number and can differ by an order of magnitude. Reading one as the other is called the base rate fallacy, and it is the single most consequential probability error in medicine, law and security screening.
Nothing here is specific to medicine. Substitute spam filtering, fraud detection, drug testing, machine-vision inspection or a criminal-trial forensic match and the arithmetic is identical: a rare condition plus an imperfect test produces mostly false alarms, because the false positives come from the large group and the true positives come from the small one.
The formula, term by term
Written for a diagnostic test, Bayes' theorem is
PPV = (prevalence x sensitivity) / [ prevalence x sensitivity + (1 - prevalence) x (1 - specificity) ]
The numerator is the fraction of everybody who has the condition and tests positive: the true positives. The denominator is the fraction of everybody who tests positive at all, which the law of total probability splits into two groups - the true positives, plus the false positives drawn from the healthy majority. Divide one by the other and you have the share of positive tests that are genuine.
The decisive term is the second one in the denominator. When prevalence is 1%, the healthy group is 99 times larger than the affected group, so even a small false positive rate generates a large absolute number of false alarms. At 95% specificity, 5% of that 99% is 4.95% of the whole population - five times the 0.99% of true positives that a 99% sensitive test finds.
There is a second, more compact way to write the same thing, and it is the form clinicians actually use. Convert the prior to odds, multiply by the likelihood ratio, and convert back:
posterior odds = prior odds x LR+, where LR+ = sensitivity / (1 - specificity)
The likelihood ratio is a single number summarising how much the evidence moves you, independent of the prior. An LR+ of 19.8 multiplies your odds by about 20 whatever they were. An LR+ of 1 means the test carries no information at all - which happens exactly when sensitivity equals the false positive rate. LR+ values above 10 are usually described as strongly diagnostic and values below 2 as weak, and the corresponding likelihood ratio calculator works through that framing in more detail.
Worked example: a rare condition and a very good test
A condition affects 1% of the tested population. The test has 99% sensitivity and 95% specificity. You test positive. Work it out on 100,000 people, which is the easiest way to do it in your head.
- Split the population by condition. 1% of 100,000 = 1,000 have the condition; 99,000 do not.
- Test the affected group. Sensitivity 99% flags 990 of the 1,000. The other 10 are false negatives.
- Test the healthy group. Specificity 95% clears 94,050 of the 99,000. The other 5% - 4,950 people - test positive incorrectly.
- Count the positives. 990 + 4,950 = 5,940 positive tests in total.
- Divide. PPV = 990 / 5,940 = 16.67%, exactly one in six.
So the excellent test moved you from a 1% prior to a 16.67% posterior. That is a large move - your odds went from 1:99 to 1:5, a factor of 19.8, which is precisely the positive likelihood ratio 0.99 / 0.05 = 19.8. But it still leaves five chances in six that you are fine, because 4,950 false positives swamp 990 true ones.
The negative result is a different story. Of the 94,060 negative tests, 94,050 are genuinely clear, so the negative predictive value is 94,050 / 94,060 = 99.989%. A negative result on this test is close to conclusive; a positive one is a reason for a second, more specific test. That asymmetry is the normal design of a screening programme: screen with a sensitive test, confirm with a specific one.
Change one number and the picture changes completely. Run the same test on a group where prevalence is 30% rather than 1% - people already showing symptoms - and the arithmetic gives 29,700 true positives against 3,500 false ones, a PPV of 89.5%. The test did not improve. The population did.
How to read the posterior
Compare the posterior with the prior. The difference is what the evidence bought you, and the ratio of the odds is exactly the likelihood ratio. If the posterior is close to the prior, the test barely moved you and the result should not change your decision.
Judge the posterior against the decision you face, not against 50%. A 16.67% chance of a serious condition is high enough to justify a confirmatory test in almost any clinical setting, even though it means the positive was probably wrong. Conversely a 90% posterior may not be enough to justify an irreversible intervention. The probability is an input to a decision that also involves the cost of each kind of error.
Watch which population your prevalence describes. Published prevalence figures usually describe a whole country, while the person in front of you belongs to a much narrower group defined by age, symptoms and referral route. Screening an unselected population and testing a symptomatic patient are the same test applied to different priors, and the posterior can differ by a factor of ten. When you do not have a defensible prior, run the calculation across a range of plausible values and see whether your decision changes.
The predictive values are properties of the test and the population. Sensitivity and specificity are properties of the test alone, which is why manufacturers quote them and why they transfer between settings. Never quote a PPV from one study as though it applied to a different population - that is the most common way the base rate fallacy re-enters through the back door.
The same 99%/95% test at different prevalences
| Prevalence | True positives per 100,000 | False positives per 100,000 | PPV | NPV |
|---|---|---|---|---|
| 0.01% | 9.9 | 4,999.5 | 0.198% | 99.99989% |
| 0.1% | 99 | 4,995 | 1.943% | 99.99895% |
| 1% | 990 | 4,950 | 16.667% | 99.98937% |
| 5% | 4,950 | 4,750 | 51.031% | 99.94463% |
| 10% | 9,900 | 4,500 | 68.750% | 99.88318% |
| 30% | 29,700 | 3,500 | 89.458% | 99.55090% |
| 50% | 49,500 | 2,500 | 95.192% | 98.95833% |
The positive likelihood ratio is 19.8 in every row - the test is unchanged. What changes is the prior odds it multiplies. PPV crosses 50% at the prevalence where true and false positives balance, which for this test is about 4.81%.
Where Bayesian reasoning goes wrong
- Reading sensitivity as the answer. A 99% sensitive test does not mean a positive result is 99% likely to be right. Sensitivity conditions on having the condition; the patient's question conditions on the test result. Swapping the two is the base rate fallacy.
- Using a population prevalence for a selected patient. The prior should describe the group your subject actually belongs to. Symptoms, exposure history and referral all raise the prior long before the test is run.
- Assuming a second test is independent of the first. Repeating the same test rarely gives independent evidence - the same biological or technical reason that produced the first false positive is usually still present. Multiplying likelihood ratios requires conditional independence, which is a strong assumption.
- Setting a prior to exactly 0 or exactly 1. Bayes' theorem multiplies the prior, so a probability of zero stays zero no matter what evidence arrives, and a probability of one stays one. Reserve those values for logical impossibility and certainty.
- Ignoring the negative result. Predictive value cuts both ways. A highly sensitive test with a modest PPV can still rule a condition out very effectively, which is often the clinically useful half.
- Quoting specificity when you mean the false positive rate. They are complements: a 95% specificity is a 5% false positive rate. Entering 5 where 95 belongs inverts the entire calculation and usually produces a suspiciously reassuring answer.
Related tools and the wider framework
Sensitivity and specificity come from a validation study in which the test was compared against a reference standard, and the sensitivity and specificity calculator derives them from the raw counts. Going the other way, the PPV and NPV calculator works directly in predictive values, and the likelihood ratio calculator expresses the same evidence as a single multiplier on the odds.
For general probability questions that do not involve a test - unions, intersections, conditional probabilities among arbitrary events - the probability calculator handles the algebra, and the identity behind Bayes' theorem is visible there as the definition of conditional probability. The odds ratio calculator works in the odds scale that makes the likelihood ratio form so convenient.
Bayes' theorem is also the foundation of an entire school of statistical inference. In that setting the prior is a distribution over an unknown parameter rather than a single probability, the likelihood is a function rather than a number, and the posterior is another distribution. The arithmetic on this page is that machinery at its smallest scale - two hypotheses, one binary observation - but the structure is identical: prior times likelihood, normalised.
One practical habit is worth adopting from this page's table. Whenever a conditional probability confuses you, stop doing algebra and count people. Take 100,000 of them, split them by the condition, apply the test to each group, and read the answer off the four resulting cells. Natural frequencies make the base rate visible, and experiments consistently show that people reason far more accurately when the question is posed that way.
