Paradoxes of Conditional Probability
Conditional probability is where intuition fails most often. The famous paradoxes are not tricks: each one teaches a rule that matters in real data analysis. The cure for all of them is the same: write down the sample space, condition properly, and check by simulation.
The Monty Hall problem
A prize is behind one of three doors. You pick door 1. The host, who knows where the prize is, opens another door that hides no prize, and offers a switch. Should you switch?
Yes: switching wins with probability . Your first pick is right with probability , and the host's action does not change that, because he can always open an empty door. Switching wins exactly when the first pick was wrong.
import random
rng = random.Random(1)
def play(switch):
prize = rng.randint(1, 3)
pick = 1
opened = rng.choice([d for d in (2, 3) if d != prize]) # host never reveals the prize
if switch:
pick = next(d for d in (1, 2, 3) if d not in (pick, opened))
return pick == prize
n = 100_000
print("stay: ", sum(play(False) for _ in range(n)) / n)
print("switch:", sum(play(True) for _ in range(n)) / n)stay: 0.33556
switch: 0.66482
The answer depends on the host's rule. If the host opened a door at random and it just happened to be empty, switching would win only half the time. The information is in the process that produced the evidence, not only in the evidence.
The prosecutor's fallacy
"The chance of a DNA match for an innocent person is 1 in a million, so the defendant is guilty with probability 999,999 in a million." This confuses with . In a city of 5 million, about 5 innocent people would match. If the defendant was found by searching a database, the posterior probability of guilt may be only about 1/6. This is Bayes' theorem with a large population as the base rate.
Simpson's paradox
A trend in every group can reverse when the groups are combined. Two treatments for kidney stones (numbers made up for illustration):
| Treatment A | Treatment B | |
|---|---|---|
| small stones | 90 of 100 (90%) | 220 of 260 (85%) |
| large stones | 150 of 250 (60%) | 50 of 90 (56%) |
| all patients | 240 of 350 (69%) | 270 of 350 (77%) |
A is better for small stones and for large stones, yet worse overall. The reason: A was mostly given for hard (large) cases. Overall success is a weighted average, and the weights differ.
from fractions import Fraction as F
data = {"A": {"small": (90, 100), "large": (150, 250)},
"B": {"small": (220, 260), "large": (50, 90)}}
for t, groups in data.items():
rates = {g: round(s / n, 3) for g, (s, n) in groups.items()}
s_all = sum(s for s, n in groups.values())
n_all = sum(n for s, n in groups.values())
share_large = F(groups["large"][1], n_all)
print(t, rates, "overall:", round(s_all / n_all, 3), " share of large stones:", round(float(share_large), 2))A {'small': 0.9, 'large': 0.6} overall: 0.686 share of large stones: 0.71
B {'small': 0.846, 'large': 0.556} overall: 0.771 share of large stones: 0.26
The lesson: when a variable (stone size) affects both the choice of treatment and the outcome, compare within groups, or adjust for it. Which comparison is right depends on the causal story, not on the numbers alone.
The boy or girl paradox
"A family has two children and at least one is a boy" gives . "A family has two children and you meet one of them, a boy" gives . The difference is again the process: the first conditions on an event about the whole family, the second on a randomly selected child.
import random
rng = random.Random(2)
n = 200_000
fam = [(rng.choice("BG"), rng.choice("BG")) for _ in range(n)]
at_least_one = [f for f in fam if "B" in f]
print("given at least one boy:", round(sum(f == ("B", "B") for f in at_least_one) / len(at_least_one), 3))
met = [(f, f[rng.randint(0, 1)]) for f in fam]
met_boy = [f for f, child in met if child == "B"]
print("given a random child is a boy:", round(sum(f == ("B", "B") for f in met_boy) / len(met_boy), 3))given at least one boy: 0.333
given a random child is a boy: 0.5
In software
Simpson's paradox appears in A/B tests split by platform, in performance benchmarks across machine types, and in fairness audits of models across groups. Selection effects like Monty Hall's appear whenever data is filtered by a process that depends on the outcome: survivorship bias in "successful startups do X", or crash reports that only come from users whose app could still send them.
Exercises
Exercise 1: Four doors
Monty Hall with 4 doors: you pick one, the host opens one empty door among the other three, and you switch to one of the two remaining closed doors at random. What is the probability of winning?
Answer
, better than for staying.
Solution
Your pick is wrong with probability ; then the prize is behind one of the 2 doors you can switch to, chosen with probability : .
Exercise 2: Database search
A DNA profile matches one innocent person in a million. Police search a database of 2 million people and find exactly one match. Assume the true culprit is in the database with probability 1/2. Roughly how likely is the match to be the culprit?
Answer
About .
Solution
The number of innocent matches is approximately Poisson with mean . If the culprit is in the database, "exactly one match" means zero innocent matches: probability . If not, it means exactly one innocent match: probability . Bayes:
Far from in a million.
Exercise 3: Host opens at random (code)
Simulate Monty Hall where the host opens one of the two other doors at random, and discard games where he reveals the prize. Show that switching then wins half the time.
Answer
About 0.5 for both strategies.
Solution
import random
rng = random.Random(3)
stay = switch = games = 0
for _ in range(200_000):
prize = rng.randint(1, 3)
opened = rng.choice([2, 3])
if opened == prize:
continue
games += 1
stay += prize == 1
switch += prize == 5 - opened
print(round(stay / games, 3), round(switch / games, 3))0.5 0.5
The remaining closed door after opening door 2 is door 3 and vice versa, so 5 - opened is the switch target.
Test yourself
In the standard Monty Hall game, switching wins with probability…
- 1/3
- 1/2
- 2/3
- 1
Simpson's paradox happens when…
- samples are too small
- group sizes differ and a variable affects both treatment choice and outcome
- a probability exceeds 1
- events are independent
The prosecutor's fallacy confuses…
- with
- with
- mean with median
- independence with disjointness