Law of Total Probability

The law of total probability finds P(A) by splitting the sample space into cases B₁, B₂, …, Bₙ that don’t overlap and together cover every outcome. Then P(A) = P(A | B₁)P(B₁) + P(A | B₂)P(B₂) + ⋯ + P(A | Bₙ)P(Bₙ). So P(A) is a weighted average of the conditional probabilities.

Before this lesson: Axioms of Probability, Conditional Probability and Probability with Combinations

The idea: break a hard probability into cases

Sometimes P(A) is hard to find directly, but easy to find once you know which case you are in. A factory part might come from one of three machines. Each machine has its own defect rate, so the chance of a defect is easy to state for each machine.

The law of total probability puts the cases back together. Find the chance of A in each case, weight it by the chance of that case, and add. It is the same as drawing a tree diagram, multiplying along each branch that ends in A, and adding those branches.

Because the weights P(Bᵢ) add to 1, P(A) is a weighted average of the case probabilities P(A | Bᵢ). It always lies between the smallest and the largest of them.

Law of total probability formula

Events B₁, B₂, …, Bₙ form a partition of the sample space S if they are mutually exclusive and their union is S, so every outcome lies in exactly one of them. If every P(Bᵢ) > 0, then for any event A

P(A) = \sum_{i=1}^{n} P(A \mid B_i)\,P(B_i) = P(A \mid B_1)P(B_1) + P(A \mid B_2)P(B_2) + \cdots + P(A \mid B_n)P(B_n)

With just two cases, B and its complement Bᶜ, the law becomes P(A) = P(A | B)P(B) + P(A | Bᶜ)P(Bᶜ). The same formula holds for a countably infinite partition B₁, B₂, …, with an infinite sum.

Why the law of total probability is true

A = (A \cap B_1) \cup (A \cap B_2) \cup \cdots \cup (A \cap B_n)

Every outcome of A lies in exactly one Bᵢ.

P(A) = P(A \cap B_1) + P(A \cap B_2) + \cdots + P(A \cap B_n)

The pieces are disjoint, so use finite additivity (see axioms of probability).

P(A \cap B_i) = P(A \mid B_i)\,P(B_i)

Multiplication rule: rearrange P(A | Bᵢ) = P(A ∩ Bᵢ)/P(Bᵢ).

P(A) = \sum_{i=1}^{n} P(A \mid B_i)\,P(B_i)

Substitute each piece into the sum.

Steps

  1. Choose cases B₁, …, Bₙ that don’t overlap and cover every outcome. Usually they are the possible results of the first stage.
  2. Find each P(Bᵢ) and check that they add to 1.
  3. Find each conditional probability P(A | Bᵢ).
  4. Multiply each pair and add the products.

Law of total probability examples

Example 1: Defective parts from three machines (word problem)

A factory makes 50% of its parts on machine M₁, 30% on M₂ and 20% on M₃. The defect rates are 2%, 3% and 5%. Find the probability that a randomly chosen part is defective.

0.5 + 0.3 + 0.2 = 1

Check that the machines form a partition: every part comes from exactly one machine.

P(D \mid M_1)P(M_1) = 0.02 \cdot 0.5 = 0.010

Machine 1 branch.

P(D \mid M_2)P(M_2) = 0.03 \cdot 0.3 = 0.009

Machine 2 branch.

P(D \mid M_3)P(M_3) = 0.05 \cdot 0.2 = 0.010

Machine 3 branch.

P(D) = 0.010 + 0.009 + 0.010 = 0.029

Add the branches (law of total probability).

Answer: P(D) = 0.029, so 2.9% of all parts are defective. This lies between the smallest rate (2%) and the largest (5%), as a weighted average must.

Tree diagram. First branches: machine 1 with probability 0.5, machine 2 with 0.3 and machine 3 with 0.2. From each machine, a defective branch D with probability 0.02, 0.03 and 0.05 and a good branch. The defective paths give 0.5 × 0.02 = 0.010, 0.3 × 0.03 = 0.009 and 0.2 × 0.05 = 0.010, which add to P(D) = 0.029.
Multiply along each path that ends in D, then add the paths: 0.010 + 0.009 + 0.010 = 0.029.

Example 2: A positive test result

A disease affects 1% of a population. A test is positive for 95% of people who have the disease and for 8% of people who don’t. Find the probability that a random person tests positive. Then find the probability that a person who tests positive has the disease.

P(+) = P(+ \mid D)P(D) + P(+ \mid D^c)P(D^c)

Two cases: has the disease (D) or doesn’t (Dᶜ).

P(+) = 0.95(0.01) + 0.08(0.99)

Substitute. P(Dᶜ) = 1 − 0.01 = 0.99.

P(+) = 0.0095 + 0.0792 = 0.0887

Multiply, then add.

P(D \mid +) = \dfrac{P(+ \mid D)P(D)}{P(+)} = \dfrac{0.0095}{0.0887}

Bayes’ theorem, with the law of total probability in the denominator.

P(D \mid +) \approx 0.107

Divide.

Answer: P(+) = 0.0887, and P(D | +) ≈ 0.107. Only about 11% of positive results come from people with the disease, because healthy people are so much more common.

Example 3: The second draw without replacement

An urn holds 5 red and 3 blue marbles. You draw two marbles without replacement. Find the probability that the second marble is red.

P(R_1) = \tfrac{5}{8},\quad P(B_1) = \tfrac{3}{8}

The first draw gives the two cases.

P(R_2 \mid R_1) = \tfrac{4}{7}

After a red, 4 of the 7 marbles left are red.

P(R_2 \mid B_1) = \tfrac{5}{7}

After a blue, 5 of the 7 marbles left are red.

P(R_2) = \tfrac{4}{7} \cdot \tfrac{5}{8} + \tfrac{5}{7} \cdot \tfrac{3}{8}

Law of total probability.

P(R_2) = \tfrac{20}{56} + \tfrac{15}{56} = \tfrac{35}{56}

Multiply, then add.

P(R_2) = \tfrac{5}{8}

Divide the numerator and denominator by 7.

Answer: 5/8, the same as the chance that the first marble is red. Before you look at the first marble, every position in the drawing order is equally likely to hold any given marble.

A rectangle of total area 1 split into two columns for the first marble: red with width 5/8 and blue with width 3/8. The red column is split 4/7 and 3/7 for the second marble red or blue, giving areas 20/56 and 15/56. The blue column is split 5/7 and 2/7, giving areas 15/56 and 6/56. The two shaded second-red pieces add to 20/56 + 15/56 = 35/56 = 5/8.
Split by the first marble, then by the second: the two shaded second-red pieces, 20/56 and 15/56, add to 5/8.

Example 4: A random number of coin flips

Roll a fair die. If it shows n, flip a fair coin n times. Find the probability of getting exactly one head.

P(\text{one head} \mid n) = \dfrac{n}{2^n}

With n flips there are 2ⁿ equally likely results, and n of them have exactly one head.

P(\text{one head}) = \sum_{n=1}^{6} \dfrac{1}{6} \cdot \dfrac{n}{2^n}

Law of total probability, with the 6 die results as the cases.

= \dfrac{1}{6}\left(\dfrac{32}{64} + \dfrac{32}{64} + \dfrac{24}{64} + \dfrac{16}{64} + \dfrac{10}{64} + \dfrac{6}{64}\right)

Write 1/2, 2/4, 3/8, 4/16, 5/32 and 6/64 over 64.

= \dfrac{1}{6} \cdot \dfrac{120}{64} = \dfrac{120}{384}

Add the numerators, then multiply.

= \dfrac{5}{16}

Divide the numerator and denominator by 24.

Answer: 5/16 = 0.3125. Conditioning on the die turns one hard question into six easy ones.

Example 5: Choose a box, then draw two balls

Box 1 holds 2 white and 3 black balls. Box 2 holds 4 white and 1 black ball. You pick a box at random and draw two balls from it without replacement. Find the probability that both are white.

P(WW \mid \text{box 1}) = \dfrac{\binom{2}{2}}{\binom{5}{2}} = \dfrac{1}{10}

Count pairs of white balls in box 1 (see probability with combinations).

P(WW \mid \text{box 2}) = \dfrac{\binom{4}{2}}{\binom{5}{2}} = \dfrac{6}{10}

Count pairs of white balls in box 2.

P(WW) = \tfrac{1}{2} \cdot \tfrac{1}{10} + \tfrac{1}{2} \cdot \tfrac{6}{10}

Law of total probability; each box has probability 1/2.

P(WW) = \tfrac{1}{20} + \tfrac{6}{20} = \tfrac{7}{20}

Multiply, then add.

Answer: 7/20 = 0.35. Notice that the answer is not the chance of two whites from all 10 balls mixed together, C(6, 2)/C(10, 2) = 15/45 = 1/3. The box you pick changes the odds.

Common mistakes

MistakeExample of the errorFix
Adding the case probabilities without weightsP(D) = 0.02 + 0.03 + 0.05 = 0.10Multiply each P(A | Bᵢ) by P(Bᵢ) before adding.
Using cases that overlap or miss outcomesCases “owns a car” and “owns a bike” for all adultsThe cases must not overlap and must cover everything. Check that the P(Bᵢ) add to 1.
Swapping P(A | B) and P(B | A)Saying a 95% accurate test means P(D | +) = 0.95P(+ | D) = 0.95 is given. P(D | +) needs Bayes’ theorem (Example 2).
Ignoring that earlier draws change the later onesUsing P(R₂ | R₁) = 5/8 in Example 3Without replacement, one red marble is gone, so P(R₂ | R₁) = 4/7.
Mixing the groups when cases have different setupsTreating Example 5 as one box of 6 white and 4 black ballsFind the probability inside each case first, then weight the cases.

Related methods

Bayes’ theorem

The law of total probability is the denominator of Bayes’ theorem. Once you know P(A), you can reverse a conditional probability: P(Bⱼ | A) = P(A | Bⱼ)P(Bⱼ)/P(A). Example 2 uses this.

Tree diagrams

A tree diagram is the law of total probability in picture form. The first set of branches is the partition, the second set holds the conditional probabilities, and P(A) is the sum of the products along the paths that end in A.

Expected values by cases

The same idea works for averages. The mean of a quantity equals the weighted average of its mean in each case. That is the law of total expectation, covered in Conditional Expectation.

Practice problems

  1. P(B) = 0.4, P(A | B) = 0.7 and P(A | Bᶜ) = 0.2. Find P(A).
  2. A store buys 60% of its stock from supplier 1, 30% from supplier 2 and 10% from supplier 3. Late deliveries happen 5%, 10% and 20% of the time. Find the probability that a delivery is late.
  3. In Problem 2, a delivery is late. Find the probability that it came from supplier 3.
  4. An urn holds 4 red and 6 blue marbles. Two are drawn without replacement. Find the probability that the second marble is blue.
  5. It rains on 30% of school days. A bus is late on 40% of rainy days and 10% of dry days. Find the probability that the bus is late on a given day.
  6. Roll a die. If it shows 1 or 2, draw a ball from urn A (3 red, 1 blue). Otherwise, draw from urn B (1 red, 3 blue). Find the probability of drawing a red ball.
  7. P(A | B) = 0.2 and P(A | Bᶜ) = 0.6. Can P(A) = 0.7? Explain.
  8. Flip a fair coin. On heads, roll one die. On tails, roll two dice and add them. Find the probability that the result is 6.
  9. Box 1 holds 3 good and 2 bad fuses, and box 2 holds 1 good and 4 bad fuses. Box 1 is chosen with probability 1/3 and box 2 with probability 2/3. Two fuses are drawn from the chosen box. Find the probability that both are good.
  10. 40% of email is spam. The word “offer” appears in 25% of spam and in 2% of other email. Find the probability that an email with “offer” is spam.
Show answers

1.

P(A) = 0.7(0.4) + 0.2(0.6)

Law of total probability; P(Bᶜ) = 0.6.

P(A) = 0.28 + 0.12 = 0.40

Multiply, then add.

Answer: 0.40

2.

P(L) = 0.05(0.6) + 0.10(0.3) + 0.20(0.1)

Law of total probability over the three suppliers.

P(L) = 0.03 + 0.03 + 0.02 = 0.08

Multiply, then add.

Answer: 0.08

3.

P(S_3 \mid L) = \dfrac{0.20(0.1)}{0.08} = \dfrac{0.02}{0.08}

Bayes’ theorem, using P(L) from Problem 2.

P(S_3 \mid L) = 0.25

Divide.

Answer: 0.25, even though supplier 3 sends only 10% of deliveries

4.

P(B_2) = \tfrac{5}{9} \cdot \tfrac{6}{10} + \tfrac{6}{9} \cdot \tfrac{4}{10}

Cases: the first marble is blue (6/10) or red (4/10).

P(B_2) = \tfrac{30}{90} + \tfrac{24}{90} = \tfrac{54}{90}

Multiply, then add.

P(B_2) = \tfrac{3}{5}

Divide the numerator and denominator by 18.

Answer: 3/5, the same as for the first draw

5.

P(\text{late}) = 0.4(0.3) + 0.1(0.7)

Cases: rain (0.3) and no rain (0.7).

P(\text{late}) = 0.12 + 0.07 = 0.19

Multiply, then add.

Answer: 0.19

6.

P(R) = \tfrac{3}{4} \cdot \tfrac{1}{3} + \tfrac{1}{4} \cdot \tfrac{2}{3}

Urn A has probability 2/6 = 1/3, and urn B has 4/6 = 2/3.

P(R) = \tfrac{3}{12} + \tfrac{2}{12} = \tfrac{5}{12}

Multiply, then add.

Answer: 5/12

7.

P(A) = 0.2\,P(B) + 0.6\,(1 - P(B)) = 0.6 - 0.4\,P(B)

Law of total probability, then simplify.

0 \le P(B) \le 1 \implies 0.2 \le P(A) \le 0.6

P(A) is a weighted average of 0.2 and 0.6.

Answer: no. P(A) must lie between 0.2 and 0.6, so it can’t be 0.7.

8.

P(6 \mid \text{heads}) = \tfrac{1}{6}

One die shows 6 in 1 of 6 ways.

P(6 \mid \text{tails}) = \tfrac{5}{36}

Two dice add to 6 in 5 of 36 ways: (1,5), (2,4), (3,3), (4,2), (5,1).

P(6) = \tfrac{1}{2} \cdot \tfrac{1}{6} + \tfrac{1}{2} \cdot \tfrac{5}{36} = \tfrac{6}{72} + \tfrac{5}{72}

Law of total probability; write both over 72.

P(6) = \tfrac{11}{72}

Add.

Answer: 11/72 ≈ 0.153

9.

P(GG \mid \text{box 1}) = \dfrac{\binom{3}{2}}{\binom{5}{2}} = \dfrac{3}{10}

Pairs of good fuses in box 1.

P(GG \mid \text{box 2}) = 0

Box 2 has only 1 good fuse.

P(GG) = \tfrac{1}{3} \cdot \tfrac{3}{10} + \tfrac{2}{3} \cdot 0 = \tfrac{1}{10}

Law of total probability.

Answer: 1/10

10.

P(O) = 0.25(0.4) + 0.02(0.6)

Law of total probability: spam or not spam.

P(O) = 0.100 + 0.012 = 0.112

Multiply, then add.

P(\text{spam} \mid O) = \dfrac{0.100}{0.112} \approx 0.893

Bayes’ theorem.

Answer: about 0.893

Law of total probability FAQ

What is the law of total probability?

It says that if events B₁, …, Bₙ split the sample space into cases that don’t overlap, then P(A) is the sum of P(A | Bᵢ)P(Bᵢ). You find the chance of A in each case and weight it by the chance of the case.

What is a partition of the sample space?

A partition is a set of events that don’t overlap and together cover the whole sample space, so every outcome is in exactly one of them. Any event B and its complement Bᶜ form the simplest partition.

How is the law of total probability related to Bayes’ theorem?

Bayes’ theorem divides P(A | Bⱼ)P(Bⱼ) by P(A), and the law of total probability is how you usually find that P(A). Most Bayes’ theorem problems use both.

How does a tree diagram show the law of total probability?

The first branches are the cases with their probabilities, and the second branches are the conditional probabilities of A. Multiply along each path that ends in A, then add the products.

Summary

  • Split the sample space into cases Bᵢ that don’t overlap and cover every outcome.
  • Then P(A) = Σ P(A | Bᵢ)P(Bᵢ), the law of total probability.
  • P(A) is a weighted average of the P(A | Bᵢ), so it lies between the smallest and the largest.
  • A tree diagram shows the same calculation: multiply along the paths to A, then add.
  • The law gives the denominator in Bayes’ theorem.

Previous lesson: Probability with Combinations

Next lesson: Poisson Distribution

Back to the Probability Theory Index