Skip to content

Bayes’ Theorem Explained: Why a Positive Test Is Often Wrong

A grid of dots showing a few true cases and many false alarms among the positive results.

A medical test is 90% accurate, you test positive, and so the chance you have the disease is about 90%. That sounds reasonable and it is badly wrong. Bayes’ theorem is the tool that fixes this kind of reasoning, and it explains why a positive result from a good test can still be more likely false than true.

The idea in one sentence

Bayes’ theorem tells you how to update a belief after seeing evidence. You start with a prior probability, which is how likely something was before the evidence. You combine it with how likely the evidence would be if the thing were true or false, and you get a posterior probability, which is how likely it is now.

The formula

For a hypothesis H and evidence E, the probability of H given E equals the probability of E given H, times the prior probability of H, divided by the overall probability of E. Written compactly, P(H | E) = P(E | H) x P(H) / P(E). The denominator is the part people forget: it counts every way the evidence could appear, including false alarms.

A worked example

Suppose a disease affects 1% of people. A test detects it in 90% of people who have it, and wrongly flags 5% of people who do not. You test positive. How likely is it that you are sick?

prevalence = 0.01
sensitivity = 0.90          # P(positive | sick)
false_positive_rate = 0.05  # P(positive | healthy)

p_positive = sensitivity * prevalence + false_positive_rate * (1 - prevalence)
posterior = sensitivity * prevalence / p_positive
print(round(posterior, 3))   # 0.154

The answer is about 15%. Out of 1,000 people, 10 are sick and about 9 of them test positive, while of the 990 healthy people, about 50 also test positive. So roughly 9 of the 59 positives are truly sick. The disease is rare, so the false alarms from the large healthy group outnumber the true detections.

The base rate fallacy

The mistake in the opening paragraph is ignoring the base rate, which is how common the condition is to begin with. When the thing you are looking for is rare, even an accurate test produces many false positives. The same effect appears in fraud detection, spam filtering and security alerts: a model with a low false positive rate can still flood you with false alarms if real cases are scarce.

The link to precision and recall

The 15% we just computed is the model’s precision, also called positive predictive value: among the cases flagged positive, how many are real. The 90% detection rate is recall. Precision depends on how common positives are, which is why accuracy-style figures mislead on rare events, as covered in how to read a confusion matrix, precision-recall curve vs ROC curve and imbalanced datasets.

Bayes in machine learning

Naive Bayes classifiers apply the theorem directly: they estimate how likely each feature value is for each class and combine those probabilities with the class prior, as explained in naive Bayesian classifiers. More broadly, Bayesian thinking treats a model’s output as a belief to update, and it connects to whether predicted probabilities can be trusted, a topic covered in model calibration.

Using it in practice

  • Always ask how common the thing is before judging how impressive a test or model is.
  • Report precision and recall, not only accuracy.
  • When a rare event matters, expect many false positives and plan how people will handle them.
  • Use a realistic prior, and state it, since the answer depends on it.

A quick checklist

  1. Do you know the base rate of what you are detecting?
  2. Are you using the full denominator, including false alarms?
  3. Did you compute precision, not only accuracy or detection rate?
  4. Is your prior realistic and stated?
  5. Do you have a plan for handling false positives?

FAQ

What is Bayes’ theorem in simple terms?
It is a rule for updating the probability of something after seeing new evidence, by combining how likely it was beforehand with how well the evidence fits.

What is the base rate fallacy?
It is the mistake of ignoring how common something is when judging evidence, which leads people to overestimate the chance that a positive result is real when the condition is rare.

How is Bayes’ theorem related to precision?
Precision is the probability that a flagged case is truly positive. It is exactly the posterior probability from Bayes’ theorem, so it depends on the base rate as well as the test’s detection and false alarm rates.

Related posts

Leave a comment

Your email address will not be published. Required fields are marked *