01 / 21
A B

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.

Discrete Math

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

Sample Space S B A
\( A \cap B \)
Given B occurred, what fraction is also in A?

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.

What we know
\( P(\text{positive} \mid \text{disease}) \): the test's sensitivity
What we want
\( P(\text{disease} \mid \text{positive}) \): the patient's actual risk

Bayes' Theorem: The Formula

\( P(A) \)
Prior: initial belief about \( A \) before seeing evidence
\( P(B \mid A) \)
Likelihood: how probable the evidence is if \( A \) is true
\( P(B) \)
Marginal: total probability of the evidence across all cases

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

Start
\( P(A) \)
\( A \)
\( P(A^c) \)
\( A^c \)
\( P(B \mid A) \)
\( A \cap B \)
\( P(B^c \mid A) \)
\( A \cap B^c \)
\( P(B \mid A^c) \)
\( A^c \cap B \)
\( P(B^c \mid A^c) \)
\( A^c \cap B^c \)
\( P(A \mid B) = \)
top green / both greens

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

1
Identify the events. Determine what \( A \) (hypothesis) and \( B \) (evidence) represent in the problem.
2
Find the prior \( P(A) \). This is the base rate of your hypothesis before any evidence.
3
Find the likelihood \( P(B \mid A) \). How probable is the evidence if the hypothesis is true?
4
Compute \( P(B) \). Use the Law of Total Probability: sum over all hypotheses.
5
Apply the formula. Divide: \( P(A \mid B) = \frac{P(B \mid A) \cdot P(A)}{P(B)} \).

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.

9.5 True + (sick & detected) 49.5 False + (healthy but flagged) Out of 1,000 people tested

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

✕ Ignoring the base rate
Assuming a 95% accurate test means a 95% chance of disease. The prior \( P(A) \) matters enormously.
✕ Confusing the direction
Treating \( P(A \mid B) \) as equal to \( P(B \mid A) \). These are generally not the same.
✕ Wrong denominator
Forgetting to use the Law of Total Probability to compute \( P(B) \), or omitting a branch.

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) \)?