# Conditional probability and Bayes' theorem

> IB Mathematics: Analysis and Approaches HL · Statistics & Probability
> Source: https://www.owlsprep.com/study/ib-math-aa-hl-u4-conditional-probability-and-bayes-theorem/

This module covers conditional probability definition, tree diagram applications, the law of total probability, and Bayes' theorem for single and multiple events, with worked examples for common IB exam problems.

**Prerequisites:** [Basic probability rules and set notation](https://www.owlsprep.com/study/ib-math-aa-hl-u4-basic-probability/); [Tree diagram construction](https://www.owlsprep.com/study/ib-math-aa-hl-u4-probability-tree-diagrams/)

## Learning objectives

- Calculate conditional probability using the definition and restricted sample spaces
- Apply the law of total probability to sequential probability problems
- Use Bayes' theorem to reverse conditional probability for single and multiple events
- Solve common IB exam problems including medical testing and reliability questions

## Conditional Probability: Definition & Basic Rules

**Conditional Probability** — The probability of event $A$ occurring, given that event $B$ is already known to have occurred. It restricts the sample space to only outcomes where $B$ occurs.

*Notation:* P(A|B)

*Example:* Probability the second card drawn from a deck is an ace, given the first card drawn was an ace.

From the definition, the core formula for conditional probability is derived directly from the joint probability of $A$ and $B$:

$$P(A|B) = \frac{P(A \cap B)}{P(B)}, \quad P(B) > 0$$

**Worked example:** A bag contains 5 red marbles and 3 blue marbles. Two marbles are drawn without replacement. What is the probability the second marble is red, given the first was blue?

1. Define events: $A = \{\text{second marble is red}\}$, $B = \{\text{first marble is blue}\}$
2. Calculate joint and marginal probabilities:
3. $$P(A \cap B) = \frac{3}{8} \times \frac{5}{7} = \frac{15}{56}, \quad P(B) = \frac{3}{8} = \frac{21}{56}$$
4. Apply the conditional probability formula:
5. $$P(A|B) = \frac{15/56}{21/56} = \frac{15}{21} = \frac{5}{7}$$

## Tree Diagrams & Law of Total Probability

Tree diagrams are ideal for sequential probability problems. Each branch is labeled with the conditional probability of that step given all prior steps. The law of total probability lets us calculate the total probability of an outcome from all possible paths.

1. Multiply probabilities along each path to get joint probabilities
2. Add joint probabilities for all paths that lead to the outcome you want
3. Confirm the sum of all joint probabilities equals 1

**Worked example:** Two machines produce widgets: Machine A makes 60% of widgets, 2% defective. Machine B makes 40% of widgets, 5% defective. What is the probability a randomly selected widget is defective?

1. Define events: $A = \{\text{widget from A}\}$, $B = \{\text{widget from B}\}$, $D = \{\text{widget defective}\}$
2. Label tree branches with given conditional probabilities: $P(D|A) = 0.02$, $P(D|B) = 0.05$
3. Apply the law of total probability:
4. $$P(D) = P(D|A)P(A) + P(D|B)P(B) = (0.02 \times 0.6) + (0.05 \times 0.4) = 0.012 + 0.02 = 0.032$$

*Calculator:* allowed

## Bayes' Theorem for Two Events

**Bayes' Theorem** — A formula to reverse conditional probability, calculating the posterior probability of a prior event given an observed outcome, from known prior and conditional probabilities.

$$P(B|A) = \frac{P(A|B) P(B)}{P(A)}, \quad P(A) = P(A|B)P(B) + P(A|B')P(B')$$

**Worked example:** A disease affects 1% of a population. A test for the disease returns positive for 95% of people with the disease, and positive for 10% of people without the disease. What is the probability a person who tests positive actually has the disease?

1. Define events: $D = \{\text{has disease}\}$, $+ = \{\text{tests positive}\}$. Given: $P(D) = 0.01$, $P(+|D) = 0.95$, $P(+|D') = 0.10$
2. Calculate total probability of testing positive:
3. $$P(+) = P(+|D)P(D) + P(+|D')P(D') = (0.95 \times 0.01) + (0.10 \times 0.99) = 0.1085$$
4. Apply Bayes' theorem:
5. $$P(D|+) = \frac{P(+|D)P(D)}{P(+)} = \frac{0.0095}{0.1085} \approx 0.088$$

> **Surprising Result**
>
> Even with a 95% accurate test, only ~9% of positive results are true positives for rare diseases. This is a very common IB exam question.

## Extended Bayes' Theorem for Multiple Events

For $n$ mutually exclusive, exhaustive events $B_1, B_2, ..., B_n$, Bayes' theorem extends directly to calculate the posterior probability of any individual event:

$$P(B_i|A) = \frac{P(A|B_i) P(B_i)}{\sum_{k=1}^n P(A|B_k) P(B_k)}$$

**Worked example:** Three boxes have counters: Box 1: 1 red, 2 blue; Box 2: 2 red, 1 blue; Box 3: 3 red, 6 blue. A box is chosen uniformly at random, then a counter drawn is red. What is the probability the counter came from Box 2?

1. Define events: $B_i = \{\text{Box } i \text{ chosen}\}$, $R = \{\text{red counter drawn}\}$. Given: $P(B_1) = P(B_2) = P(B_3) = \frac{1}{3}$
2. Conditional probabilities: $P(R|B_1) = \frac{1}{3}$, $P(R|B_2) = \frac{2}{3}$, $P(R|B_3) = \frac{3}{9} = \frac{1}{3}$
3. Calculate denominator (total probability of red):
4. $$\sum P(R|B_k)P(B_k) = \frac{1}{3} \left( \frac{1}{3} + \frac{2}{3} + \frac{1}{3} \right) = \frac{4}{9}$$
5. Apply extended Bayes' theorem:
6. $$P(B_2|R) = \frac{P(R|B_2)P(B_2)}{4/9} = \frac{(2/3)(1/3)}{4/9} = \frac{1}{2}$$

*Calculator:* allowed

## Common pitfalls

- **Wrong:** Dividing by $P(A \cap B)$ instead of $P(B)$ in $P(A|B)$
  - Why it fails: Mixing up which event is the given event that restricts the sample space
  - Correct: Always remember: the denominator is the probability of the event you already know has occurred, $P(\text{given event})$
- **Wrong:** Leaving probabilities unchanged for sampling without replacement on tree diagrams
  - Why it fails: Treating dependent draws as independent, leading to incorrect joint probabilities
  - Correct: Adjust counts and probabilities for each subsequent branch after drawing without replacement
- **Wrong:** Assuming $P(A|B) = P(B|A)$ without applying Bayes' theorem
  - Why it fails: Base rate neglect and confusion about the direction of conditional probability
  - Correct: Always explicitly apply Bayes' theorem when reversing the direction of conditional probability
- **Wrong:** Using extended Bayes' theorem with non-exhaustive or overlapping events
  - Why it fails: The denominator of Bayes' theorem relies on all possible outcomes being included and non-overlapping
  - Correct: Confirm all events are mutually exclusive and cover the entire sample space before calculation

## Cheatsheet

| Concept | Formula | Common Use Case |
| --- | --- | --- |
| Conditional Probability | $P(A\|B) = \frac{P(A \cap B)}{P(B)}, \, P(B) > 0$ | Find probability of A given B occurred |
| Law of Total Probability | $P(A) = P(A\|B)P(B) + P(A\|B')P(B')$ | Calculate total P(A) from two cases |
| Bayes' Theorem (2 events) | $P(B\|A) = \frac{P(A\|B)P(B)}{P(A)}$ | Reverse conditional probability |
| Extended Bayes (n events) | $P(B_i\|A) = \frac{P(A\|B_i)P(B_i)}{\sum P(A\|B_k)P(B_k)}$ | Multiple competing prior events |

## What's next

Conditional probability and Bayes' theorem are foundational for nearly all advanced topics in statistics and probability, including discrete probability distributions, expected values, and statistical inference. This topic appears regularly in both Paper 1 and Paper 2 of IB AA HL exams, often combined with tree diagrams or binomial probability concepts. Mastery of these ideas also prepares you for university-level study of statistics, data science, and quantitative fields.

- [Discrete Probability Distributions](https://www.owlsprep.com/study/ib-math-aa-hl-u4-discrete-probability-distributions/)
- [Binomial distribution](https://www.owlsprep.com/study/ib-math-aa-hl-u4-binomial-distribution/)
- [Continuous probability distributions and PDFs](https://www.owlsprep.com/study/ib-math-aa-hl-u4-continuous-probability-distributions-and-pdfs/)

---

From [OwlsPrep](https://www.owlsprep.com) — free study guides for A-Level, IB, AP and IGCSE, written against the official syllabus. Canonical page: https://www.owlsprep.com/study/ib-math-aa-hl-u4-conditional-probability-and-bayes-theorem/
