Independent Events and Variables
Two events are independent when knowing that one happened tells you nothing about the other. Independence is what makes most probability calculations tractable, and assuming it when it is false is behind many real-world disasters, from financial risk models to correlated server failures.
Definition
Events and are independent if
equivalently (when ) . Events are mutually independent if the product rule holds for every subcollection; checking only pairs is not enough.
Random variables and are independent if for all values (for continuous variables, the joint density factors; see Marginals and Independence).
Checking independence
Two dice: "first die is even" and "sum is 7" are independent; "first die is even" and "sum is 8" are not.
from fractions import Fraction
from itertools import product
omega = list(product(range(1, 7), repeat=2))
P = lambda e: Fraction(sum(1 for w in omega if e(w)), 36)
A = lambda w: w[0] % 2 == 0
for target in [7, 8]:
B = lambda w, t=target: w[0] + w[1] == t
both = P(lambda w: A(w) and B(w))
print(f"sum {target}: P(A and B) = {both}, P(A) P(B) = {P(A) * P(B)}, independent: {both == P(A) * P(B)}")sum 7: P(A and B) = 1/12, P(A) P(B) = 1/12, independent: True
sum 8: P(A and B) = 1/12, P(A) P(B) = 5/72, independent: False
For sum 7, whatever the first die shows, exactly one value of the second die completes the 7, so the first die carries no information. For sum 8, a first die of 1 makes 8 impossible.
Pairwise is not mutual
Toss two fair coins. Let = "first is heads", = "second is heads", = "the two coins agree". Each pair is independent, but all three are not: and together determine .
from fractions import Fraction
from itertools import product
omega = list(product("HT", repeat=2))
P = lambda e: Fraction(sum(1 for w in omega if e(w)), len(omega))
A = lambda w: w[0] == "H"
B = lambda w: w[1] == "H"
C = lambda w: w[0] == w[1]
for name, X, Y in [("A,B", A, B), ("A,C", A, C), ("B,C", B, C)]:
print(name, P(lambda w: X(w) and Y(w)) == P(X) * P(Y))
print("A,B,C:", P(lambda w: A(w) and B(w) and C(w)), "vs", P(A) * P(B) * P(C))A,B True
A,C True
B,C True
A,B,C: 1/4 vs 1/8
The same structure explains why XOR-based secret sharing works: each share alone reveals nothing, yet two shares together reveal the secret.
Independent trials
Repeating an experiment under the same conditions, with no influence between repetitions, gives independent trials, the model behind Bernoulli trials. Independence lets you multiply: the chance that 3 independent replicas, each down 1% of the time, are all down at once is . If the replicas share a power supply, the events are not independent and the real figure can be close to 0.01.
import random
rng = random.Random(6)
n = 1_000_000
indep = shared = 0
for _ in range(n):
# independent replicas
indep += all(rng.random() < 0.01 for _ in range(3))
# replicas sharing a power supply that fails 0.5% of the time
power_out = rng.random() < 0.005
shared += power_out or all(rng.random() < 0.005 for _ in range(3))
print("independent: all down", indep / n)
print("shared power: all down", shared / n)independent: all down 1e-06
shared power: all down 0.004986
In software
Redundancy only helps as much as failures are independent, which is why cloud providers offer separate availability zones. In statistics and machine learning, "independent and identically distributed" (i.i.d.) samples are the default assumption; data leakage and time-correlated data break it. Hash functions are designed so that bits of the output behave as if independent.
Exercises
Exercise 1: A die and a coin
A die is rolled and a coin tossed. Are "die shows 6" and "coin shows heads" independent? What is the probability of both?
Answer
Yes; .
Solution
The 12 outcomes (face, side) are equally likely and the product rule holds: .
Exercise 2: Disjoint versus independent
Can two disjoint events with positive probabilities be independent?
Answer
No.
Solution
Disjoint means , but . In fact disjoint events are strongly dependent: if one happens, the other cannot.
Exercise 3: Reliability (code)
A system works if component A works and at least one of B and C works. Each works independently with probability 0.9. Compute the reliability exactly and by simulation.
Answer
.
Solution
import random
rng = random.Random(1)
n = 200_000
ok = 0
for _ in range(n):
a, b, c = (rng.random() < 0.9 for _ in range(3))
ok += a and (b or c)
print(ok / n, 0.9 * (1 - 0.1 ** 2))0.891695 0.891
Test yourself
Events and are independent when…
Three events are pairwise independent. Are they necessarily mutually independent?
- Yes
- No
- Only if they are disjoint
- Only for coins