Day 2. Conditional Probability, Independence & Bayes
Updating probabilities when you learn something, and the four rules that do it.
- ●Compute conditional probabilities and test events for independence.
- ●Use the law of total probability to combine subgroup rates.
- ●Derive and apply Bayes' theorem, including in low-prevalence settings.
- ●Explain why aggregate comparisons can reverse within subgroups (Simpson's paradox preview).
Theory
Conditioning restricts the sample space
Causal questions are almost never about raw probabilities. We want the probability of employment given training, or of recovery given a drug. Learning that happened shrinks the world to :
Rearranged, this is the multiplication rule: .
Independence
and are independent if
Knowing tells you nothing about . Randomisation makes treatment independent of every pre-treatment characteristic, observed or not. That single fact is why experiments identify causal effects.
Law of total probability (LTP)
If partition :
An overall rate is a weighted average of subgroup rates, with weights equal to subgroup shares. Keep this in mind: when two groups have different weights, their overall rates can mislead.
Bayes' theorem
Bayes reverses the direction of conditioning: from "how likely is the evidence given the hypothesis" to "how likely is the hypothesis given the evidence". The base rate matters enormously.
Causal link. "Treatment is independent of potential outcomes" is the key identifying assumption of an experiment. Today's definition of independence is what that sentence means.
Part 1 · Warm-up
Exercise 1 · Basic conditioning
Given , and , compute .
Show solution
Exercise 2 · Checking independence
Are and from Exercise 1 independent?
Show solution
Yes. ; equivalently .
Exercise 3 · Multiplication rule
In a trial, and a treated patient recovers with probability . What is ?
Show solution
.
Exercise 4 · Law of total probability
In the same trial, . What is the overall recovery rate ?
Show solution
Exercise 5 · Basic Bayes
A recovered patient is chosen at random. What is the probability they were treated?
Show solution
Part 2 · Proofs
Exercise 6 · Deriving Bayes' theorem
Using only the definition of conditional probability, prove Bayes' theorem.
Show solution
- By definition, .
- Also by definition, , so .
- Substitute into step 1: .
- Expanding by the LTP over gives the second form.
Exercise 7 · Independence is symmetric
Show that if then (assume both probabilities are positive).
Show solution
- means , i.e. .
- Then .
Exercise 8 · Independence of complements
Prove that if and are independent, so are and .
Show solution
- Partition : .
- So .
Exercise 9 · Conditional probability is a probability
Show that for fixed with , satisfies the normalisation axiom and that .
Show solution
- .
- and are disjoint with union , so
(Non-negativity and additivity carry over the same way, so every rule from Day 1 holds conditionally.)
Exercise 10 · Disjoint is not independent
Prove that two disjoint events with positive probabilities cannot be independent.
Show solution
Step 1. Disjoint means , but .
Step 2. So .
Step 3. Intuitively, disjoint events are maximally dependent: learning tells you for certain that did not happen.
Part 3 · Applied
Exercise 11 · Randomisation balances covariates
In an experiment, 60% of participants are women and every participant is treated with probability 0.5, regardless of sex. What share of the treated group is women?
Show solution
Step 1. Collect what we know: , , and (everyone has the same chance of treatment).
Step 2. Apply Bayes' theorem:
Answer: 60% of the treated group are women, the same as in the whole sample. Because treatment is independent of sex, the treated group mirrors the population. The same argument holds for any characteristic, including ones nobody measured.
Exercise 12 · Screening and the base rate
A test has sensitivity and false-positive rate .
(a) If prevalence is 5%, what is ? (b) Repeat with prevalence 30%.
Show solution
(a) Prevalence 5%
Step 1. Overall share testing positive (law of total probability):
Step 2. Bayes' theorem:
(b) Prevalence 30%
Step 3. .
Step 4. .
Answer: about 32% at 5% prevalence and 79% at 30% prevalence. The same test means very different things in different populations (try it in the Simulation Lab).
Exercise 13 · Inflation and interest rates
Historically (inflation rises), (rates rise) and . Find and . Are the events independent?
Show solution
Step 1. Multiplication rule:
Step 2. Definition of conditional probability:
Step 3. Independence check: .
Answer: , , and the events are not independent: rising rates make rising inflation twice as likely as its unconditional rate.
Exercise 14 · Take-up in an encouragement design
A subsidy offer is randomised 50/50. Take-up is and .
(a) What share of the population takes the subsidy? (b) If nobody is put off by the offer, what share are "compliers" (take it only if offered)?
Show solution
(a) Overall take-up
Step 1. Law of total probability over the two arms:
(b) Share of compliers
Step 2. People who take the subsidy without an offer ("always-takers") make up 10% of the control arm. Randomisation makes the two arms alike, so they are also 10% of the offer arm.
Step 3. If nobody refuses because of the offer (no "defiers"), the extra take-up in the offer arm comes from compliers:
Answer: 35% take the subsidy; half the population are compliers. This difference in take-up is the first stage of an instrumental-variables design (Phase 5).
Exercise 15 · Simpson's paradox with numbers
Hospital data:
| Severe: deaths / patients | Mild: deaths / patients | |
|---|---|---|
| Treatment A | 24 / 80 | 1 / 20 |
| Treatment B | 8 / 20 | 8 / 80 |
Compute mortality for each treatment within each severity level and overall. Explain the reversal with the LTP.
Show solution
Step 1. Mortality within each severity level:
| Severe | Mild | |
|---|---|---|
| A | ||
| B |
A has lower mortality in both strata.
Step 2. Overall mortality: A ; B . B looks better.
Step 3. Write each overall rate with the LTP, using each arm's own case mix (, ):
Answer: the reversal happens because A's overall rate puts 80% weight on the deadly severe stratum, while B's puts only 20% there. Severity is a confounder; Day 15 shows how to compare the arms fairly.
Verify in Python
def bayes(prior, sens, fpr):
p_pos = sens * prior + fpr * (1 - prior)
return sens * prior / p_pos, p_pos
for prev in (0.05, 0.30):
post, p_pos = bayes(prev, 0.90, 0.10)
print(f"prevalence {prev:.2f}: P(+) = {p_pos:.3f}, P(V|+) = {post:.3f}")
# Simpson's paradox table (Exercise 15)
data = {"A": {"severe": (24, 80), "mild": (1, 20)},
"B": {"severe": (8, 20), "mild": (8, 80)}}
for arm, strata in data.items():
rates = {s: d / n for s, (d, n) in strata.items()}
deaths = sum(d for d, _ in strata.values()); n = sum(n for _, n in strata.values())
print(arm, {k: round(v, 2) for k, v in rates.items()}, "overall", deaths / n)
Key takeaways
- Conditioning shrinks the sample space; independence means conditioning changes nothing.
- Overall rates are weighted averages of subgroup rates (LTP).
- Bayes' theorem turns into , and the base rate matters.
Simulation Lab: Bayes' Theorem Calculator
Open full screen →A probability tree and a 1,000-person grid: see how prevalence drives the meaning of a positive test.
Each dot is one person in a city of 1,000. The posterior P(V | +) is the share of blue among all dots that tested positive (blue + orange).