IB Diploma Mathematics AA · Statistics and probability
Bayes' theorem (HL)
1Reversing a condition
Often you know $P(B \mid A)$ but want $P(A \mid B)$. For example, a test tells you $P(\text{positive} \mid \text{disease})$, but a patient wants $P(\text{disease} \mid \text{positive})$.
Bayes' theorem reverses the condition:
$$P(A \mid B) = \frac{P(B \mid A)\,P(A)}{P(B \mid A)\,P(A) + P(B \mid A')\,P(A')}$$
The bottom line is just $P(B)$, found by adding both ways that $B$ can happen.
Check yourself
What does Bayes' theorem let you do?
Show the answer
Find P(A | B) when you know P(B | A)
It turns a condition around.
2Bayes on a tree diagram
Bayes' theorem on a tree diagram: add the positive paths, then divide
A tree diagram makes Bayes' theorem easy:
- The tree goes in the order you are told: cause first, then result.
- $P(B)$ is the sum of every path that ends in $B$.
- $P(A \mid B)$ is the path through $A$ and $B$, divided by $P(B)$.
A screening test
- 1% of people have a condition. The test is positive for 90% of people with it and for 5% of people without it.
- $P(C \cap +) = 0.01 \times 0.90 = 0.009$.
- $P(C' \cap +) = 0.99 \times 0.05 = 0.0495$.
- $P(+) = 0.009 + 0.0495 = 0.0585$.
- $P(C \mid +) = \frac{0.009}{0.0585} = 0.154$.
Only 15% of people who test positive actually have the condition. When a condition is rare, false positives dominate.
Check yourself
In Bayes' theorem, how do you find P(B) on a tree diagram?
Show the answer
Add all the paths that end in B
B can happen through A or through A′.
3More than two causes
Bayes' theorem works with any number of causes $A_1, A_2, A_3, \ldots$ that cover all possibilities:
$$P(A_i \mid B) = \frac{P(B \mid A_i)\,P(A_i)}{\sum_j P(B \mid A_j)\,P(A_j)}$$
Three machines
- A factory's bolts come from machines A (50%), B (30%) and C (20%). They are faulty 2%, 3% and 5% of the time.
- $P(\text{faulty}) = 0.5(0.02) + 0.3(0.03) + 0.2(0.05) = 0.010 + 0.009 + 0.010 = 0.029$.
- A bolt is faulty. $P(C \mid \text{faulty}) = \frac{0.010}{0.029} = 0.345$.
- Machine C makes only 20% of bolts but 34.5% of the faulty ones.
Check yourself
In the factory example, why is P(C | faulty) larger than P(C)?
Show the answer
Machine C has the highest fault rate
Faults point more strongly to the worst machine.
4Prior and posterior
In Bayes' language:
- $P(A)$ is the prior: your belief before the evidence.
- $P(A \mid B)$ is the posterior: your belief after seeing evidence $B$.
A second piece of evidence can be added by using the posterior as the new prior.
Testing twice
- After one positive test, $P(C) = 0.154$.
- A second, independent test is also positive. Now the prior is $0.154$.
- $P(C \cap +) = 0.154 \times 0.9 = 0.1386$ and $P(C' \cap +) = 0.846 \times 0.05 = 0.0423$.
- $P(C \mid ++) = \frac{0.1386}{0.1809} = 0.766$.
Two positive tests make the condition much more likely.
Check yourself
In Bayes' theorem, what is the prior?
Show the answer
The probability before the new evidence
It is updated into the posterior.
5Medical testing and false positives
Bayes' theorem shows why positive test results for rare conditions can be misleading.
A test for a rare disease
- 1% of people have the disease.
- The test detects 95% of cases (sensitivity).
- It wrongly gives a positive result for 5% of healthy people.
- $P(\text{positive}) = 0.01 \times 0.95 + 0.99 \times 0.05 = 0.0095 + 0.0495 = 0.059$.
- $P(\text{disease} \mid \text{positive}) = \frac{0.0095}{0.059} \approx 0.161$.
- Only about 16% of people who test positive actually have the disease.
Check yourself
Why can a positive result for a rare disease still be likely to be false?
Show the answer
Healthy people far outnumber sick ones, so false positives outnumber true ones
Base rates matter.
6Updating probabilities
Bayes' theorem lets us update a probability with new evidence. The updated probability (posterior) becomes the prior for the next piece of evidence.
Testing twice
- After one positive test, $P(\text{disease}) \approx 0.161$.
- A second, independent positive test: $P(\text{positive}) = 0.161 \times 0.95 + 0.839 \times 0.05 \approx 0.153 + 0.042 = 0.195$.
- $P(\text{disease} \mid \text{two positives}) \approx \frac{0.153}{0.195} \approx 0.785$.
- A second test greatly increases confidence.
Check yourself
What is a prior probability?
Show the answer
The probability before new evidence is considered
Before updating.
7Going deeper: a screening test, three causes and updating twice
Bayes' theorem reverses a condition: $P(B \mid A) = \frac{P(B)\,P(A \mid B)}{P(B)\,P(A \mid B) + P(B')\,P(A \mid B')}$. The denominator is $P(A)$, found by adding the routes through a tree.
Worked example (screening): 1% of people have a condition. The test is positive for 95% of those who have it and for 4% of those who do not.
- $P(\text{has it and positive}) = 0.01 \times 0.95 = 0.0095$.
- $P(\text{does not and positive}) = 0.99 \times 0.04 = 0.0396$.
- $P(\text{positive}) = 0.0491$.
- $P(\text{has it} \mid \text{positive}) = \frac{0.0095}{0.0491} \approx 0.193$.
- Only about 19% of positives are true positives. The condition is rare, so false positives from the large healthy group outnumber true positives.
- In whole numbers: of 10,000 people, 100 have it and 95 test positive; of the 9,900 without it, 396 test positive. $\frac{95}{491} \approx 0.193$.
Worked example (updating): the same person takes an independent second test and is positive again.
- The new prior is 0.193.
- Numerator: $0.193 \times 0.95 \approx 0.184$.
- Other route: $0.807 \times 0.04 \approx 0.0323$.
- Posterior: $\frac{0.184}{0.184 + 0.0323} \approx 0.85$.
- Each piece of evidence updates the probability. Yesterday's posterior is today's prior.
Worked example (three causes): machines A, B and C make 50%, 30% and 20% of the output, with defect rates 1%, 2% and 5%.
- $P(\text{defective}) = 0.5(0.01) + 0.3(0.02) + 0.2(0.05) = 0.005 + 0.006 + 0.010 = 0.021$.
- $P(C \mid \text{defective}) = \frac{0.010}{0.021} \approx 0.476$.
- $P(A \mid \text{defective}) = \frac{0.005}{0.021} \approx 0.238$.
- C makes a fifth of the items and nearly half of the defective ones.
Vocabulary
- Prior: the probability before the evidence.
- Likelihood: the probability of the evidence under each hypothesis.
- Posterior: the probability after the evidence.
- Base rate: how common the condition is. Ignoring it is the base rate fallacy.
Common mistakes
- Confusing $P(\text{positive} \mid \text{ill})$ with $P(\text{ill} \mid \text{positive})$.
- Leaving a route out of the denominator.
- Rounding intermediate products too early, which distorts a small numerator.
Check yourself
Bag X holds 3 red and 1 blue counter; bag Y holds 1 red and 3 blue. A bag is chosen at random and a red counter is drawn. What is the probability it came from bag X?
Show the answer
0.75
(0.5 × 0.75) ÷ (0.5 × 0.75 + 0.5 × 0.25) = 0.375 ÷ 0.5.
Now test yourself
This lesson has a 8-question quiz and 5 exam-style questions with mark schemes in Impera. Free, with your progress saved.
Practise in Impera