Probability Basics and Bayes’ Theorem
Conditional probability, independence and Bayes' theorem, and why intuition fails with rare medical tests.
Basic rules
- \(0 \le P(A) \le 1\).
- \(P(A \cup B) = P(A) + P(B) – P(A \cap B)\).
- Conditional probability: \(P(A \mid B) = \dfrac{P(A \cap B)}{P(B)}\).
Bayes' theorem
$$P(H \mid D) = \frac{P(D \mid H)\, P(H)}{P(D)}$$
| Symbol | Name | Meaning |
|---|---|---|
| P(H) | Prior probability | Our belief before the data |
| P(D | H) | Likelihood | How well the data fits the hypothesis |
| P(H | D) | Posterior probability | Our belief after the data |
The medical test example
A disease with 1% prevalence, and a test with 90% sensitivity and 90% specificity. Out of 1,000 people:
- 10 are sick, and the test detects 9 of them.
- 990 are healthy, and the test gives 99 of them a false positive result.
- Of 108 positive results, only 9 are real: about 8%.
The link to machine learning
- The classifier Naive Bayes applies the theorem with the assumption that the features are conditionally independent.
- When a model is moved to a population with a different prevalence, the positive predictive value changes even if sensitivity and specificity stay the same.
- The metrics Precision and Recall correspond to positive predictive value and sensitivity.
prev, sens, spec = 0.01, 0.90, 0.90
ppv = sens * prev / (sens * prev + (1 - spec) * (1 - prev))
print(round(ppv, 3)) # 0.083Lesson terms
- Conditional probability
- The probability of an event given that another event occurred, equal to the probability of both occurring divided by the probability of the condition.
- Independence
- Two events are independent if knowing one does not change the probability of the other.
- Bayes' theorem
- A relationship linking the posterior probability to the prior probability and the likelihood: P(y|x) = P(x|y)P(y)/P(x).
Abstract
Probability measures uncertainty. The conditional probability P(A|B) is the probability of A given that B occurred. Bayes' theorem reverses the condition, linking the posterior probability to the prior probability and the likelihood. Ignoring the prior probability (the prevalence) leads to a common fallacy: an accurate test for a rare disease may have mostly false positive results.
Review questions
-
Why does a test with 99% sensitivity have a low positive predictive value for a rare disease?
Because the number of healthy people is very large, so even a small proportion of false positives among them exceeds the number of truly sick people.
-
What is the difference between P(A|B) and P(B|A)?
The first is the probability of A given B, and the second is the reverse, and they are generally not equal.
Sources and references
Complete the lesson
You have completed all the lessons in the track! You can now request the track completion certificate.
Request the certificate