What you'll learn
- Apply conditional probability to a test result
- Explain why P(A | B) is not the same as P(B | A)
- Use sensitivity, specificity and prevalence to work out the positive predictive value
- Recognise base-rate neglect in medicine, spam filters and fraud detection
Use conditional probability and Bayes' rule to work out what a positive test result really means.
Why this matters
A screening test is "99% accurate" and your result is positive. What is the chance you actually have the condition? Most people, including many professionals, guess about 99%. The real answer is often far lower. Medical lab staff, data scientists building classifiers, and quality engineers reading inspection results all need to get this right. The tool is conditional probabilityThe probability of A given that B has happened: P(A and B) / P(B)..
What "given" means
P(A | B) is read "the probability of A given B": the probability that A happens if we already know B happened. Knowing B shrinks the world we are looking at to only the cases where B is true.
P(A | B) = P(A and B) / P(B)Worked example. A class of 100 students: 40 study statistics, 25 study chemistry, and 10 study both.
P(chemistry | statistics) = P(both) / P(statistics) = (10/100) / (40/100) = 10/40 = 0.25
P(statistics | chemistry) = (10/100) / (25/100) = 10/25 = 0.40Notice that P(A | B) and P(B | A) are different numbers. Mixing them up is the single most common error in this topic, and it has a name: confusing the inverse.
Independence, restated
Events A and B are independent exactly when knowing B does not change A: P(A | B) = P(A). In the class, P(chemistry) = 0.25 and P(chemistry | statistics) = 0.25, so in this made-up class the two choices happen to be independent.
Test results: the four boxes
A diagnostic or inspection test has two properties you can measure in a lab:
- SensitivityThe probability a test is positive when the condition is present: how well it catches real cases. = P(test positive | condition present). How well it catches real cases.
- SpecificityThe probability a test is negative when the condition is absent: how well it clears healthy cases. = P(test negative | condition absent). How well it clears healthy cases.
And one property of the population:
- PrevalenceThe share of the tested population that actually has the condition. = P(condition present) in the people being tested.
What the patient wants is the positive predictive value (PPV)The probability the condition is present given a positive test: true positives divided by all positives. = P(condition present | test positive). That is the inverse of sensitivity, and it depends heavily on prevalence.
Worked example with counts
The easiest way to compute PPV is to imagine 10,000 people. Prevalence 1%, sensitivity 99%, specificity 95%.
Have the condition: 1% of 10,000 = 100
test positive (99%): 99 true positives
test negative: 1 false negative
Do not have it: 9,900
test negative (95%): 9,405 true negatives
test positive (5%): 495 false positives
All positives = 99 + 495 = 594
PPV = 99 / 594 ≈ 0.167Only about 1 in 6 positives is real. The test is good, but the condition is rare, so false positives from the large healthy group swamp the true positives from the small sick group. This is why positive screening results are usually followed by a second, more specific confirmatory test.
Bayes' rule
The same calculation as a formula:
P(D | +) = P(+ | D) * P(D) / P(+)
where P(+) = P(+ | D) * P(D) + P(+ | not D) * P(not D)
= sensitivity * prevalence + (1 - specificity) * (1 - prevalence)Plugging in: 0.99 × 0.01 / (0.99 × 0.01 + 0.05 × 0.99) = 0.0099 / 0.0594 ≈ 0.167. Same answer.
Change only the prevalence to 20% (for example, testing people who already have symptoms) and the PPV jumps to about 0.83. The test did not change; the population did.
Beyond medicine
- A spam filter flags an email. P(spam | flagged) depends on how much of your mail is spam to begin with.
- A fraud model flags a transaction. If 1 in 1,000 transactions is fraud, even a strong model produces mostly false alarms.
- An automated inspection rejects a part. If the process is very good, many rejects may be good parts.
Common mistakes
- Treating sensitivity as if it were PPV (confusing the inverse).
- Ignoring the base rate (prevalence). This is called base-rate neglectIgnoring how common a condition is, which leads people to overestimate what a positive result means..
- Forgetting that PPV changes when you test a different population.
Quick recap
P(A | B) = P(A and B) / P(B); it is not the same asP(B | A).- Sensitivity and specificity describe the test; prevalence describes the population.
- PPV = true positives / all positives. Rare conditions mean many false positives.
- Bayes' rule turns P(+ | D) into P(D | +).
Try it
In the Do tab, write the PPV formula and see how it changes with prevalence.
Key terms (6)
- conditional probability
- The probability of A given that B has happened: P(A and B) / P(B).
- Sensitivity
- The probability a test is positive when the condition is present: how well it catches real cases.
- Specificity
- The probability a test is negative when the condition is absent: how well it clears healthy cases.
- Prevalence
- The share of the tested population that actually has the condition.
- positive predictive value (PPV)
- The probability the condition is present given a positive test: true positives divided by all positives.
- base-rate neglect
- Ignoring how common a condition is, which leads people to overestimate what a positive result means.