James's Math Hub
← Statistics & Probability

Lesson 5 / 13 · 13 min read

Conditional Probability & Bayes' Theorem

Updating probabilities when you learn something new — and why base rates matter.

Conditional probability

P(A∣B)P(A \mid B) is the probability of AA given that BB has happened:

P(A∣B)=P(A∩B)P(B)P(A \mid B) = \frac{P(A \cap B)}{P(B)}

The symbol ∩\cap means "and" (both happen). Rearranging gives the multiplication rule:

P(A∩B)=P(A∣B) P(B)P(A \cap B) = P(A \mid B)\,P(B)

Independence, revisited

AA and BB are independent when knowing one tells you nothing about the other: P(A∣B)=P(A)P(A \mid B) = P(A). In that case the multiplication rule simplifies to P(A∩B)=P(A) P(B)P(A \cap B) = P(A)\,P(B).

Two-way tables make it concrete

Suppose 100 people are classified by whether they exercise and whether they sleep well:

Sleeps wellPoor sleepTotal
Exercises401050
No exercise203050
Total6040100
  • P(sleeps well)=60100=0.6P(\text{sleeps well}) = \frac{60}{100} = 0.6
  • P(sleeps well∣exercises)=4050=0.8P(\text{sleeps well} \mid \text{exercises}) = \frac{40}{50} = 0.8

Since 0.8≠0.60.8 \neq 0.6, sleeping well and exercising are not independent — exercisers sleep well more often.

Law of total probability

If BB can occur through disjoint cases AA and "not AA" (written AcA^c):

P(B)=P(B∣A) P(A)+P(B∣Ac) P(Ac)P(B) = P(B \mid A)\,P(A) + P(B \mid A^c)\,P(A^c)

Bayes' theorem

Bayes flips a conditional probability around:

P(A∣B)=P(B∣A) P(A)P(B)P(A \mid B) = \frac{P(B \mid A)\,P(A)}{P(B)}

where P(B)P(B) comes from the law of total probability. It's how you go from "probability of a positive test given disease" to the thing you actually want: "probability of disease given a positive test."

The medical-test surprise

A disease affects 1%1\% of people. A test is 99%99\% accurate on the sick (true positive) and has a 5%5\% false-positive rate on the healthy. You test positive. What's the chance you actually have it?

Let DD = disease and ++ = positive test.

  • P(D)=0.01P(D) = 0.01, so P(Dc)=0.99P(D^c) = 0.99
  • P(+∣D)=0.99P(+ \mid D) = 0.99, P(+∣Dc)=0.05P(+ \mid D^c) = 0.05

First the total probability of a positive test:

P(+)=0.99(0.01)+0.05(0.99)=0.0099+0.0495=0.0594P(+) = 0.99(0.01) + 0.05(0.99) = 0.0099 + 0.0495 = 0.0594

Now Bayes:

P(D∣+)=0.99⋅0.010.0594≈0.167P(D \mid +) = \frac{0.99 \cdot 0.01}{0.0594} \approx 0.167

Only about 17%. Because the disease is rare, the few real cases are swamped by false positives from the huge healthy group. Ignoring this is the base-rate fallacy.

Key takeaways

  • P(A∣B)=P(A∩B)P(B)P(A \mid B) = \dfrac{P(A \cap B)}{P(B)}; rearrange it for the multiplication rule.
  • Independent means P(A∣B)=P(A)P(A \mid B) = P(A).
  • Two-way tables turn conditional probabilities into simple ratios.
  • Bayes' theorem flips a conditional using the base rate — and rare conditions make even accurate tests produce mostly false positives.