Bayes' Rule
Updating Beliefs with Evidence
Learn how to reverse conditional probabilities and compute the probability of a hypothesis given observed data using the most powerful tool in probability theory.
What is Conditional Probability?
Conditional probability measures the likelihood of an event given that another event has already occurred. It is the foundation of Bayes' Rule.
The Big Question Bayes Answers
In many real situations, we know \( P(B \mid A) \) but actually need \( P(A \mid B) \). Bayes' Rule lets us flip the conditioning.
Prior, Likelihood, and Posterior
Bayes' Rule connects three key ingredients. Understanding each one is essential before applying the formula.
Bayes' Rule: The Formula
Expanding \( P(B) \) with the Law of Total Probability
Often \( P(B) \) is not given directly. We compute it by summing over all ways B can occur, partitioned by whether A is true or not.
Here \( A^c \) denotes "not A". This expanded version is what you will use in most textbook problems.
Visualizing with a Probability Tree
\( P(A \mid B) \) vs \( P(B \mid A) \)
The most common source of confusion: these two conditional probabilities are not the same, and confusing them is called the inverse fallacy.
| \( P(B \mid A) \) | \( P(A \mid B) \) | |
|---|---|---|
| Name | Likelihood | Posterior |
| Reads as | "Prob of data given hypothesis" | "Prob of hypothesis given data" |
| Medical example | P(+test | disease) | P(disease | +test) |
| Typically | Given in the problem | What you solve for |
Step-by-Step Application
Example 1: Medical Testing
A disease affects 1% of the population. A test has a sensitivity of 95% and a false positive rate of 3%. If a patient tests positive, what is \( P(\text{disease} \mid +) \)?
Interpreting the Result
Even with a 95% accurate test, a positive result only gives about a 24.2% chance of actually having the disease. Why so low?
Example 2: Email Spam Filter
Suppose 40% of emails are spam. 90% of spam emails contain the word "free", while only 5% of legitimate emails do. If an email contains "free", what is the probability it is spam?
An email containing "free" has about a 92.3% chance of being spam: the high prior (40%) and strong likelihood (90%) reinforce each other.
Example 3: Manufacturing Defects
A factory has two machines. Machine A produces 60% of items and has a 2% defect rate. Machine B produces 40% and has a 5% defect rate. A defective item is found: what is the probability it came from Machine B?
There is a 62.5% chance the defective item came from Machine B, even though Machine B only makes 40% of items: its higher defect rate shifts the posterior.
Common Mistakes
Summary Cheat Sheet
| Component | Symbol | Role in Bayes' Rule |
|---|---|---|
| Prior | \( P(A) \) | Base rate of hypothesis |
| Likelihood | \( P(B \mid A) \) | How well data fits hypothesis |
| Evidence | \( P(B) \) | Normalizing constant (denominator) |
| Posterior | \( P(A \mid B) \) | Updated belief (what we solve for) |
| Complement likelihood | \( P(B \mid A^c) \) | False positive / alternative explanation rate |
Question 1 of 5
In Bayes' Rule \( P(A \mid B) = \frac{P(B \mid A)\,P(A)}{P(B)} \), what does \( P(A) \) represent?
Question 2 of 5
A disease has prevalence \( P(D) = 0.02 \). A test has sensitivity \( P(+ \mid D) = 0.90 \) and false positive rate \( P(+ \mid D^c) = 0.05 \). What is \( P(+) \)?
Question 3 of 5
Using the values from Question 2, what is \( P(D \mid +) \), the probability a person who tests positive actually has the disease?
Question 4 of 5
If the prior probability \( P(A) \) increases while \( P(B \mid A) \) and \( P(B \mid A^c) \) stay fixed, what happens to the posterior \( P(A \mid B) \)?
Question 5 of 5
30% of students study the night before an exam. Of those who study, 85% pass. Of those who don't study, 40% pass. A student passed: what is \( P(\text{studied} \mid \text{passed}) \)?