Conditional Probability and Bayes' Theorem with Examples
When New Information Changes the Odds
The chance that a randomly chosen student is late today might be 20%. But if you are told it rained this morning, that chance goes up. A medical test comes back positive. How likely is it that the patient really has the disease? It is usually much less likely than people think. Questions like these are about conditional probability: the probability of an event given that another event has happened. This tutorial covers conditional probability and Bayes' theorem for further mathematics, JAMB and first-year university statistics (STA 111 and similar): the definition and formula, Venn diagrams and two-way counts, the multiplication rule, drawing without replacement, independence, tree diagrams, the law of total probability, and Bayes' theorem with real-world examples. It builds on the tutorial on basic probability.
What Is Conditional Probability?
The conditional probability of A given B, written P(A | B), is the probability that A happens when we already know that B has happened. Knowing B shrinks the sample space: only outcomes in B are now possible, and we ask what fraction of them are also in A.
P(A | B) = P(A ∩ B) ÷ P(B), provided P(B) ≠ 0
Here A ∩ B means "A and B both happen".
Worked example 1
A fair die is rolled. Find the probability of a 6, given that the result is even.
Given "even", the possible outcomes are only 2, 4 and 6. One of these three is a 6, so P(6 | even) = 1/3.
Using the formula: P(6 and even) = 1/6 and P(even) = 1/2, so P(6 | even) = (1/6) ÷ (1/2) = 1/3.
Without the extra information, P(6) = 1/6. Knowing the result is even doubles the probability.
Conditional Probability from Counts
When data are given as counts, such as in a Venn diagram or a two-way table, conditional probability is simply a fraction of a restricted group.
Worked example 2
In a class of 40 students, 25 study economics, 18 study geography, and 10 study both. A student is chosen at random. Find (a) the probability that the student studies geography, given that they study economics, and (b) the probability that they study economics, given that they study geography.
(a) Restrict to the 25 economics students. Ten of them also study geography, so P(G | E) = 10/25 = 0.4.
(b) Restrict to the 18 geography students: P(E | G) = 10/18 = 5/9.
Notice that P(G | E) and P(E | G) are different. Confusing them is one of the most common errors in probability, and Bayes' theorem is the tool for switching between them.
The Multiplication Rule
Rearranging the definition gives the multiplication rule for the probability that two events both happen:
P(A ∩ B) = P(A) × P(B | A)
This is exactly what you do along the branches of a tree diagram.
Worked example 3: drawing without replacement
A bag contains 5 red and 3 blue balls. Two balls are drawn one after the other without replacement. Find (a) the probability that both are red, and (b) the probability that the second is red, given that the first is blue.
(a) P(first red) = 5/8. Given that, 4 red balls remain out of 7, so P(second red | first red) = 4/7.
P(both red) = 5/8 × 4/7 = 20/56 = 5/14.
(b) If the first ball is blue, all 5 red balls remain among 7 balls, so P(second red | first blue) = 5/7.
"Without replacement" is a signal that the second probability is conditional on the first.
Independent Events
Events A and B are independent if knowing that one has happened does not change the probability of the other:
P(A | B) = P(A), which is equivalent to P(A ∩ B) = P(A) × P(B)
Worked example 4
A card is drawn from a standard pack of 52. Let A = "the card is a heart" and B = "the card is a king". Are A and B independent?
P(A) = 13/52 = 1/4. Given that the card is a king, one of the four kings is a heart, so P(A | B) = 1/4.
Since P(A | B) = P(A), the events are independent. Check: P(A ∩ B) = 1/52, and P(A) × P(B) = 1/4 × 1/13 = 1/52.
Do not confuse independent events with mutually exclusive events. Mutually exclusive events cannot happen together, so if one happens the other is impossible, which makes them strongly dependent.
Tree Diagrams and the Law of Total Probability
If an event A can happen through several separate routes B1, B2, …, which together cover every possibility, then:
P(A) = P(B1) P(A | B1) + P(B2) P(A | B2) + …
This is the law of total probability. On a tree diagram, multiply along each branch that ends in A, then add the results.
Worked example 5
The probability that it rains on a given morning is 0.3. If it rains, the probability that Tolu is late for school is 0.4. If it does not rain, the probability is 0.1. Find the probability that Tolu is late.
Rain and late: 0.3 × 0.4 = 0.12. No rain and late: 0.7 × 0.1 = 0.07.
P(late) = 0.12 + 0.07 = 0.19.
Bayes' Theorem
Often we know P(A | B) but want the reverse, P(B | A). Bayes' theorem turns the conditional around:
P(B | A) = P(B) × P(A | B) ÷ P(A)
where P(A) usually comes from the law of total probability. In words: the probability of a cause, given an observed effect, equals the probability of that route to the effect divided by the total probability of the effect.
Worked example 6
Continuing Worked example 5: Tolu was late today. What is the probability that it rained?
P(rain | late) = P(rain and late) ÷ P(late) = 0.12 ÷ 0.19 ≈ 0.63.
Before we knew Tolu was late, the probability of rain was 0.3. The new information more than doubled it. In Bayesian language, 0.3 is the prior probability and 0.63 is the posterior probability.
Worked example 7: defective products
A factory has two machines. Machine A makes 60% of the products, and 2% of its products are defective. Machine B makes 40%, and 5% of its products are defective. A product is chosen at random and found to be defective. Find the probability that it was made by machine A.
P(defective) = 0.6 × 0.02 + 0.4 × 0.05 = 0.012 + 0.020 = 0.032.
P(A | defective) = 0.012 ÷ 0.032 = 0.375.
Although machine A makes most of the products, a defective item is more likely to have come from machine B (probability 0.625).
A Surprising Example: Medical Tests
A disease affects 1% of a population. A test detects the disease in 95% of people who have it, but also gives a false positive for 5% of people who do not. A person tests positive. How likely is it that they have the disease?
P(positive) = 0.01 × 0.95 + 0.99 × 0.05 = 0.0095 + 0.0495 = 0.059.
P(disease | positive) = 0.0095 ÷ 0.059 ≈ 0.16.
Only about 16%. Most people guess 95%, confusing P(positive | disease) with P(disease | positive). Imagine 10,000 people: 100 have the disease and about 95 test positive, but of the 9,900 healthy people about 495 also test positive. So only 95 of the 590 positives are genuine. When a disease is rare, false positives outnumber true positives, which is why doctors confirm results with a second, different test. This reasoning, called base-rate thinking, is one of the most useful ideas in statistics, medicine, law and machine learning, where it powers spam filters and naive Bayes classifiers.
Common Mistakes with Conditional Probability
- Confusing P(A | B) with P(B | A). Always ask: what do we already know, and what are we finding?
- Forgetting to reduce the sample space when drawing without replacement.
- Ignoring the base rate, the prior probability, as in the medical test example.
- Treating mutually exclusive events as independent.
Conditional Probability: Practice Questions
- Two fair dice are rolled. Find the probability that the total is 8, given that the first die shows 3. Then find the probability that the first die shows 3, given that the total is 8.
- P(A) = 0.5, P(B) = 0.4 and P(A ∩ B) = 0.2. Find P(A | B). Are A and B independent?
- A bag holds 4 white and 6 black balls. Two are drawn without replacement. Find the probability that both are black.
- 70% of students pass mathematics. Of those, 80% pass physics. Of those who fail mathematics, 30% pass physics. Find the probability that a student passes physics, and the probability that a student who passed physics also passed mathematics.
Answers: 1. The second die must show 5, so 1/6. Totals of 8 are (2,6), (3,5), (4,4), (5,3) and (6,2), so P(first is 3 | total 8) = 1/5. 2. P(A | B) = 0.2 ÷ 0.4 = 0.5 = P(A), so yes, they are independent. 3. 6/10 × 5/9 = 1/3. 4. P(physics) = 0.7 × 0.8 + 0.3 × 0.3 = 0.65. P(maths | physics) = 0.56 ÷ 0.65 ≈ 0.86.
Conclusion
Conditional probability, P(A | B) = P(A ∩ B)/P(B), measures how likely A is once we know B has happened, by restricting attention to the outcomes in B. The multiplication rule multiplies along tree branches, the law of total probability adds the branches that lead to an event, and events are independent when the condition makes no difference. Bayes' theorem reverses a conditional probability, updating a prior belief with new evidence, and it explains why even an accurate test for a rare disease produces many false alarms.