Sub topic 9
Conditional probability: shrinking the sample space
This chapter assumes you can compute a simple probability as favorable over total outcomes, work with fractions and percents, and read a two-way table. It also assumes you know what "and" and "or" mean for events. The chapter covers conditional probability, which is the probability of an event after you learn that another event happened.
The core idea
Conditional probability answers this question: given that B happened, how likely is A? It is written P(A | B) and read "the probability of A given B."
Learning that B happened removes every outcome outside B. B becomes your new sample space. You then ask what fraction of that smaller space also lies in A.
Take one roll of a fair die. The probability of a 6 is 1/6. Suppose you are told the roll is even. The sample space shrinks from {1, 2, 3, 4, 5, 6} to {2, 4, 6}. One of those three outcomes is a 6, so P(6 | even) = 1/3.
The formula
Counting works when outcomes are equally likely. The general formula also works when they are not:
P(A | B) = P(A and B) / P(B), where P(B) > 0.
The numerator counts the outcomes that are in both A and B. The denominator is the size of the new sample space. Dividing by P(B) rescales the probabilities inside B so that they add up to 1 again.
Two edge cases follow from the formula:
- P(B) = 0. The condition is impossible, so P(A | B) is undefined. GRE problems do not ask for this.
- A and B are mutually exclusive. P(A and B) = 0, so P(A | B) = 0. If B happened, A cannot have.
If B is inside A (every B outcome is also an A outcome), then P(A | B) = 1.
Worked example 1: two dice
Roll two fair dice. What is the probability that the sum is 8, given that the first die is even?
- The first die is even in 3 × 6 = 18 of the 36 outcomes, so P(first even) = 18/36.
- The outcomes with an even first die and a sum of 8 are (2,6), (4,4) and (6,2). That is 3 outcomes, so P(both) = 3/36.
- Divide: (3/36) / (18/36) = 3/18 = 1/6.
You can also count directly in the restricted space. There are 18 outcomes and 3 are favorable, which gives 3/18.
from fractions import Fraction
from itertools import product
space = list(product(range(1, 7), repeat=2))
def prob(event):
return Fraction(sum(1 for o in space if event(o)), len(space))
def cond(a, b):
"""P(a | b) = P(a and b) / P(b)."""
return prob(lambda o: a(o) and b(o)) / prob(b)
first_even = lambda o: o[0] % 2 == 0
sum_is_8 = lambda o: o[0] + o[1] == 8
print(cond(sum_is_8, first_even)) # 1/6
print(prob(sum_is_8)) # 5/36The unconditional probability of a sum of 8 is 5/36, which is about 0.139. The condition raised it to 1/6, which is about 0.167. Conditions can raise a probability, lower it, or leave it unchanged.
Worked example 2: a two-way table
Tables are the usual GRE format for conditional probability. A school has 100 students.
| Row | Passed | Failed | Total |
|---|---|---|---|
| Juniors | 36 | 9 | 45 |
| Seniors | 33 | 22 | 55 |
| Total | 69 | 31 | 100 |
P(passed | senior). Use only the Seniors row. Of 55 seniors, 33 passed, so the answer is 33/55 = 3/5.
P(senior | passed). Use only the Passed column. Of 69 students who passed, 33 are seniors, so the answer is 33/69 = 11/23.
These two answers are different. The condition tells you which row or column to use as the denominator. Swapping the condition changes the denominator.
Reading the wording
Conditional probability often appears without the word "given." These phrasings all set up a restricted sample space:
- "If a senior is chosen at random, what is the probability that the student passed?"
- "Of the students who passed, what fraction are seniors?"
- "Among the even rolls, how many are greater than 3?"
- "A person is selected from the group that ..."
In each case the group named by "if," "of," "among," or "from" is the denominator. The other event is the numerator, counted only inside that group.
Connection to independence
Events A and B are independent exactly when knowing B does not change the probability of A:
P(A | B) = P(A).
Check this with the dice. Is "sum is 7" independent of "first die even"?
from fractions import Fraction
from itertools import product
space = list(product(range(1, 7), repeat=2))
def prob(event):
return Fraction(sum(1 for o in space if event(o)), len(space))
def cond(a, b):
return prob(lambda o: a(o) and b(o)) / prob(b)
first_even = lambda o: o[0] % 2 == 0
sum_is_7 = lambda o: o[0] + o[1] == 7
print(prob(sum_is_7)) # 1/6
print(cond(sum_is_7, first_even)) # 1/6 -> unchanged, so independent
print(cond(first_even, sum_is_7)) # 1/2 -> equals P(first even), also independentBoth conditional probabilities equal the unconditional ones, so the events are independent. In the school table, P(passed | senior) = 3/5 = 60%, while P(passed) = 69%. The two differ, so passing and class year are not independent in that group.
If P(A | B) ≠ P(A), the events are dependent. Independence is symmetric. If B does not affect A, then A does not affect B.
Rearranging the formula
Multiplying both sides of the definition by P(B) gives the general multiplication rule:
P(A and B) = P(B) × P(A | B).
Use it when you know a conditional probability and need the joint probability. For example, suppose 40% of a company's employees are in sales, and 25% of sales employees work remotely. The share of all employees who are in sales and work remotely is 0.40 × 0.25 = 0.10, or 10%. A later chapter develops this rule in full, including sequential draws.
Common errors
- Using the whole sample space as the denominator. Computing 3/36 in example 1 answers "first die even and sum 8," not the conditional question.
- Reversing the condition. This is the 3/5 versus 11/23 mix-up.
- Dividing by the wrong total in a table. For a "given" question, use the row or column total, not the grand total.
- Assuming a condition changes nothing. Check with P(A | B) = P(A) if the problem suggests independence. Do not assume it.
- Treating "given" as "and." P(A and B) is a share of the whole space. P(A | B) is a share of B only. P(A and B) ≤ P(A | B) whenever P(B) ≤ 1.
Practice
Exercise
Using the school table in this chapter, what is P(junior | failed)? Give a simplified fraction.
Show answer
Restrict to the Failed column, which has 31 students. Of those, 9 are juniors. P(junior | failed) = 9/31. This fraction is already in lowest terms.
Exercise
Two fair dice are rolled. What is the probability that at least one die shows a 6, given that the sum is at least 10?
Show answer
The outcomes with sum at least 10 are (4,6), (5,5), (5,6), (6,4), (6,5) and (6,6). That is 6 outcomes. Of these, (4,6), (5,6), (6,4), (6,5) and (6,6) contain a 6, which is 5 outcomes. The probability is 5/6.
Exercise
Events A and B satisfy P(B) = 0.5 and P(A and B) = 0.2. Also P(A) = 0.4. Are A and B independent? Justify your answer using P(A | B).
Show answer
P(A | B) = 0.2 / 0.5 = 0.4. This equals P(A) = 0.4, so A and B are independent. As a check, P(A) × P(B) = 0.4 × 0.5 = 0.2, which equals P(A and B).