Bayes' Theorem
and Applications
Master the art of updating probabilities with new evidence: from medical tests to spam filters, Bayes' theorem is the backbone of modern reasoning under uncertainty.
What is Conditional Probability?
Conditional probability answers a simple but powerful question: how does knowing one event change the likelihood of another? We write this as \( P(A \mid B) \), read "the probability of \( A \) given \( B \)."
This formula restricts our sample space to only those outcomes where \( B \) has already occurred, then asks: what fraction of those also satisfy \( A \)?
Visualizing Conditional Probability
Why Do We Need Bayes' Theorem?
In practice, we often know \( P(B \mid A) \) but need \( P(A \mid B) \). For example: a medical test tells us the probability of a positive result given disease, but the patient wants to know the probability of disease given a positive result.
Bayes' Theorem: The Formula
Expanding \( P(B) \) with the Law of Total Probability
When \( P(B) \) is not given directly, we compute it by considering all ways \( B \) can happen. If \( A \) and \( A^c \) partition the sample space:
Substituting into Bayes' theorem gives the expanded form:
The Probability Tree View
Prior vs. Posterior
| Prior \( P(A) \) | Posterior \( P(A \mid B) \) | |
|---|---|---|
| When | Before observing evidence | After observing evidence \( B \) |
| Reflects | Background knowledge / base rate | Updated belief |
| Example | \( P(\text{disease}) = 0.01 \) | \( P(\text{disease} \mid +) = 0.08 \) |
| Direction | No conditioning | Conditioned on new data |
How to Apply Bayes' Theorem
Example 1: Medical Test
A disease affects 1% of the population. A test has a sensitivity (true positive rate) of 95% and a false positive rate of 5%. If a patient tests positive, what is \( P(\text{disease} \mid +) \)?
The Base Rate Effect
Even with a 95% accurate test, a positive result only means a 16.1% chance of disease. Why? Because the disease is rare: the 5% false positives among the 99% healthy people overwhelm the true positives from the 1% sick.
Example 2: Spam Filter
40% of incoming emails are spam. The word "free" appears in 80% of spam emails and 10% of legitimate emails. An email contains "free": what is the probability it is spam?
An email with "free" has an 84.2% chance of being spam: the high base rate of spam (40%) and strong likelihood (80%) make this a confident classification.
Example 3: Factory Defects
Factory \( F_1 \) produces 60% of parts with a 3% defect rate. Factory \( F_2 \) produces 40% with a 7% defect rate. A randomly selected part is defective: what is the probability it came from \( F_2 \)?
Even though \( F_2 \) produces fewer parts, its higher defect rate means a defective part is more likely from \( F_2 \) (about 61%).
Generalized Bayes: Multiple Hypotheses
When we have \( n \) mutually exclusive, exhaustive hypotheses \( A_1, A_2, \ldots, A_n \), Bayes' theorem generalizes to:
Common Mistakes
Bayes' Theorem Summary
| Component | Symbol | Meaning |
|---|---|---|
| Prior | \( P(A) \) | Baseline probability of hypothesis |
| Likelihood | \( P(B \mid A) \) | Probability of evidence given hypothesis |
| Marginal | \( P(B) \) | Total probability of evidence |
| Posterior | \( P(A \mid B) \) | Updated probability after evidence |
| Formula | \( \dfrac{P(B \mid A) \cdot P(A)}{P(B)} \) | |
Question 1 of 5
A disease has a prevalence of 2%. A test has sensitivity \( P(+ \mid D) = 0.90 \) and false positive rate \( P(+ \mid D^c) = 0.05 \). What is \( P(D \mid +) \)?
Question 2 of 5
In Bayes' theorem \( P(A \mid B) = \frac{P(B \mid A) \cdot P(A)}{P(B)} \), the term \( P(A) \) is called the:
Question 3 of 5
Box 1 contains 3 red and 7 blue balls. Box 2 contains 6 red and 4 blue balls. A box is chosen at random (50/50), then a ball is drawn and found to be red. What is the probability it came from Box 2?
Question 4 of 5
The "base rate fallacy" refers to the mistake of:
Question 5 of 5
If \( P(A) = 0.3 \), \( P(B \mid A) = 0.5 \), and \( P(B) = 0.4 \), what is \( P(A \mid B) \)?