Skip to content

The law of total probability

6 min read

Short answer

If events B1,…,BkB_1,\dots,B_k are disjoint and cover the whole sample space (a partition), then P(A)=∑iP(A∣Bi) P(Bi)P(A)=\sum_iP(A\mid B_i)\,P(B_i). It is "divide into cases, weigh each case by how likely it is, and add", and it is also the denominator in Bayes' theorem.

Bar chartMachine 1Machine 2Machine 3P(defect) = 0.01 + 0.012 + 0.02 = 0.042
Each bar is P(defect | machine) × P(machine). The total probability of a defect is the sum of the three contributions.

Why it works

The partition cuts AA into non-overlapping slices: A=(A∩B1)∪⋯∪(A∩Bk)A=(A\cap B_1)\cup\cdots\cup(A\cap B_k), and these slices are disjoint because the BiB_i are. By additivity,

P(A)=∑iP(A∩Bi)=∑iP(A∣Bi) P(Bi),P(A)=\sum_iP(A\cap B_i)=\sum_iP(A\mid B_i)\,P(B_i),

where the last step is the multiplication rule P(A∩B)=P(A∣B)P(B)P(A\cap B)=P(A\mid B)P(B). Conditional probabilities are easy to state ("given machine 2, the defect rate is 4%"), so this converts a hard unconditional question into easy conditional ones.

Two conditions that matter

The BiB_i must be mutually exclusive (no overlaps, or you double count) and exhaustive (together they cover every outcome, or you miss some). The simplest partition is {B,Bc}\{B,B^c\}, giving P(A)=P(A∣B)P(B)+P(A∣Bc)P(Bc)P(A)=P(A\mid B)P(B)+P(A\mid B^c)P(B^c).

The weights P(Bi)P(B_i) must add to 1. A quick sanity check is to confirm that, and that the final answer lies between the smallest and largest of the P(A∣Bi)P(A\mid B_i), since it is a weighted average of them.

Connection to Bayes' theorem

Bayes' theorem reverses a conditional: P(Bj∣A)=P(A∣Bj)P(Bj)P(A)P(B_j\mid A)=\dfrac{P(A\mid B_j)P(B_j)}{P(A)}. The denominator P(A)P(A) is generally not given directly, and the law of total probability supplies it. In words: how much of all the ways AA can happen comes through case jj?

Drawing a tree makes this concrete: branch first on the case, then on whether AA occurs, multiply along each path and add the paths that end in AA.

Worked example

Three machines make 50%, 30% and 20% of a factory's items, with defect rates 2%, 4% and 10%. Find P(defect)P(\text{defect}) and the chance a defective item came from machine 3.

P(D)=0.5(0.02)+0.3(0.04)+0.2(0.10)=0.01+0.012+0.02=0.042.P(D)=0.5(0.02)+0.3(0.04)+0.2(0.10)=0.01+0.012+0.02=0.042.

By Bayes, P(M3∣D)=0.2⋅0.100.042=0.020.042≈0.476P(M_3\mid D)=\dfrac{0.2\cdot0.10}{0.042}=\dfrac{0.02}{0.042}\approx0.476.

Machine 3 makes only 20% of items but about 48% of the defects.

Try it yourself

The chance of rain is 0.30.3. You are late with probability 0.50.5 on rainy days and 0.10.1 on dry days. What is P(late)P(\text{late})?

Show the answer

P(L)=0.5(0.3)+0.1(0.7)=0.15+0.07=0.22P(L)=0.5(0.3)+0.1(0.7)=0.15+0.07=0.22.

Keep going with practice

Vidi's conditional probability lessons use case splits like this one in tree-diagram problems.