TExcelTAD
Home › School Probability & Statistics on Paper › Law of Total Probability and Bayes' Theorem on Paper

Law of Total Probability and Bayes' Theorem on Paper

In standard probability problems, we reason forward from causes to effects: given that an item was made by Machine A, what is the probability that it is defective?

In real-world science, medicine, and engineering, we must frequently reason backward from observed effects to underlying causes: given that an item is defective, what is the probability that Machine A produced it?

The Law of Total Probability and Bayes' Theorem are the twin mathematical cornerstones that make this inverse reasoning precise.


Partitions of a Sample Space

A collection of events {B1,B2,…,Bk}\{B_1, B_2, \dots, B_k\} forms a partition of the sample space Ω\Omega if:

  1. They are pairwise mutually exclusive:
Bi∩Bj=∅for all i≠jB_i \cap B_j = \emptyset \quad \text{for all } i \neq j
  1. Their union encompasses the entire sample space:
B1∪B2∪⋯∪Bk=ΩB_1 \cup B_2 \cup \dots \cup B_k = \Omega
  1. Each event has a positive prior probability: P(Bi)>0P(B_i) > 0.

Every possible outcome in Ω\Omega belongs to one and only one partition slice BiB_i.


The Law of Total Probability

Let {B1,B2,…,Bk}\{B_1, B_2, \dots, B_k\} be a partition of Ω\Omega. Any arbitrary event A⊆ΩA \subseteq \Omega can be sliced into disjoint sub-events by intersecting it with each partition block:

A=(A∩B1)∪(A∩B2)∪⋯∪(A∩Bk)A = (A \cap B_1) \cup (A \cap B_2) \cup \dots \cup (A \cap B_k)

Because these pieces are mutually exclusive, the Law of Total Probability states:

P(A)=∑i=1kP(A∩Bi)=∑i=1kP(Bi)×P(A∣Bi)P(A) = \sum_{i=1}^k P(A \cap B_i) = \sum_{i=1}^k P(B_i) \times P(A \mid B_i)

The Two-Hypothesis Case (BB and BcB^c)

When an event BB and its complement BcB^c partition Ω\Omega:

P(A)=P(B)×P(A∣B)+P(Bc)×P(A∣Bc)P(A) = P(B) \times P(A \mid B) + P(B^c) \times P(A \mid B^c)

Bayes' Theorem (Bayes' Rule)

Using the conditional probability definition, the posterior probability of hypothesis BiB_i given that evidence AA has occurred is:

P(Bi∣A)=P(Bi∩A)P(A)P(B_i \mid A) = \frac{P(B_i \cap A)}{P(A)}

Substituting the Law of Total Probability into the denominator yields Bayes' Theorem:

P(Bi∣A)=P(Bi)×P(A∣Bi)∑j=1kP(Bj)×P(A∣Bj)P(B_i \mid A) = \frac{P(B_i) \times P(A \mid B_i)}{\displaystyle\sum_{j=1}^k P(B_j) \times P(A \mid B_j)}

Vocabulary of Bayesian Inference

  • Prior Probability P(Bi)P(B_i): The baseline probability of hypothesis BiB_i before observing the evidence.
  • Likelihood P(A∣Bi)P(A \mid B_i): The probability of observing evidence AA if hypothesis BiB_i were true.
  • Total (Marginal) Probability P(A)P(A): The overall probability of evidence AA occurring across all possible causes.
  • Posterior Probability P(Bi∣A)P(B_i \mid A): The updated probability of hypothesis BiB_i after evidence AA has been observed.

The Paper Tabular Layout Method

To avoid confusing formulas on paper, arrange your calculations in a Bayesian Calculation Table:

Hypothesis (BiB_i) Prior P(Bi)P(B_i) Likelihood P(A∣Bi)P(A \mid B_i) Joint Product P(Bi∩A)=P(Bi)⋅P(A∣Bi)P(B_i \cap A) = P(B_i) \cdot P(A \mid B_i) Posterior P(Bi∣A)=JointP(A)P(B_i \mid A) = \frac{\text{Joint}}{P(A)}
B1B_1 P(B1)P(B_1) P(A∣B1)P(A \mid B_1) P(B1)×P(A∣B1)P(B_1) \times P(A \mid B_1) P(B1∩A)P(A)\frac{P(B_1 \cap A)}{P(A)}
B2B_2 P(B2)P(B_2) P(A∣B2)P(A \mid B_2) P(B2)×P(A∣B2)P(B_2) \times P(A \mid B_2) P(B2∩A)P(A)\frac{P(B_2 \cap A)}{P(A)}
⋮\vdots ⋮\vdots ⋮\vdots ⋮\vdots ⋮\vdots
BkB_k P(Bk)P(B_k) P(A∣Bk)P(A \mid B_k) P(Bk)×P(A∣Bk)P(B_k) \times P(A \mid B_k) P(Bk∩A)P(A)\frac{P(B_k \cap A)}{P(A)}
Sum 1.001.00 — P(A)=∑JointP(A) = \sum \text{Joint} 1.001.00

Worked Examples on Paper

Example 1: Three Factory Machines

Problem Statement: An electronics factory produces microchips using three machines: M1,M2,M_1, M_2, and M3M_3.

  • M1M_1 produces 50%50\% of the factory's output with a 2%2\% defective rate.
  • M2M_2 produces 30%30\% of the output with a 3%3\% defective rate.
  • M3M_3 produces 20%20\% of the output with a 5%5\% defective rate.

A chip is selected at random from the warehouse and found to be defective (DD).

  1. What is the total probability that any randomly selected chip is defective: P(D)P(D)?
  2. What is the probability that the defective chip was produced by Machine M3M_3: P(M3∣D)P(M_3 \mid D)?

Step-by-Step Paper Solution

Step 1: Set up the paper table Identify the partition {M1,M2,M3}\{M_1, M_2, M_3\} and write their priors:

P(M1)=0.50,P(M2)=0.30,P(M3)=0.20P(M_1) = 0.50, \quad P(M_2) = 0.30, \quad P(M_3) = 0.20

Check: 0.50+0.30+0.20=1.000.50 + 0.30 + 0.20 = 1.00.

Write the likelihoods of defect (DD):

P(D∣M1)=0.02,P(D∣M2)=0.03,P(D∣M3)=0.05P(D \mid M_1) = 0.02, \quad P(D \mid M_2) = 0.03, \quad P(D \mid M_3) = 0.05

Step 2: Multiply priors by likelihoods to find joint probabilities

P(M1∩D)=P(M1)×P(D∣M1)=0.50×0.02=0.010P(M2∩D)=P(M2)×P(D∣M2)=0.30×0.03=0.009P(M3∩D)=P(M3)×P(D∣M3)=0.20×0.05=0.010\begin{aligned} P(M_1 \cap D) &= P(M_1) \times P(D \mid M_1) = 0.50 \times 0.02 = 0.010 \\ P(M_2 \cap D) &= P(M_2) \times P(D \mid M_2) = 0.30 \times 0.03 = 0.009 \\ P(M_3 \cap D) &= P(M_3) \times P(D \mid M_3) = 0.20 \times 0.05 = 0.010 \end{aligned}

Step 3: Calculate the total probability P(D)P(D) (Part 1) Add the joint products using the Law of Total Probability:

P(D)=P(M1∩D)+P(M2∩D)+P(M3∩D)=0.010+0.009+0.010=0.029(2.9%)\begin{aligned} P(D) &= P(M_1 \cap D) + P(M_2 \cap D) + P(M_3 \cap D) \\ &= 0.010 + 0.009 + 0.010 \\ &= 0.029 \quad (2.9\%) \end{aligned}

Step 4: Compute the posterior probability P(M3∣D)P(M_3 \mid D) (Part 2) By Bayes' Theorem:

P(M3∣D)=P(M3∩D)P(D)=0.0100.029=1029≈0.3448(34.5%)P(M_3 \mid D) = \frac{P(M_3 \cap D)}{P(D)} = \frac{0.010}{0.029} = \frac{10}{29} \approx 0.3448 \quad (34.5\%)

Example 2: The Base Rate Fallacy in Medical Testing

Problem Statement: A rare virus infects 11 in every 10001000 individuals in a city (P(V)=0.001P(V) = 0.001). A blood test for the virus has:

  • True Positive Rate (Sensitivity): P(T+∣V)=0.99P(T^+ \mid V) = 0.99.
  • False Positive Rate: P(T+∣Vc)=0.02P(T^+ \mid V^c) = 0.02.

A resident takes the test and receives a positive result (T+T^+). What is the probability that this resident actually carries the virus?

Step-by-Step Paper Solution

Step 1: Write down all components

  • Prior probabilities:
P(V)=0.001,P(Vc)=1−0.001=0.999P(V) = 0.001, \quad P(V^c) = 1 - 0.001 = 0.999
  • Conditional likelihoods:
P(T+∣V)=0.99,P(T+∣Vc)=0.02P(T^+ \mid V) = 0.99, \quad P(T^+ \mid V^c) = 0.02

Step 2: Calculate the two joint paths

  • True infected and tests positive:
P(V∩T+)=P(V)×P(T+∣V)=0.001×0.99=0.00099P(V \cap T^+) = P(V) \times P(T^+ \mid V) = 0.001 \times 0.99 = 0.00099
  • Uninfected healthy person and tests positive (false positive):
P(Vc∩T+)=P(Vc)×P(T+∣Vc)=0.999×0.02=0.01998P(V^c \cap T^+) = P(V^c) \times P(T^+ \mid V^c) = 0.999 \times 0.02 = 0.01998

Step 3: Total probability of testing positive P(T+)P(T^+)

P(T+)=P(V∩T+)+P(Vc∩T+)=0.00099+0.01998=0.02097\begin{aligned} P(T^+) &= P(V \cap T^+) + P(V^c \cap T^+) \\ &= 0.00099 + 0.01998 = 0.02097 \end{aligned}

Step 4: Apply Bayes' Theorem

P(V∣T+)=P(V∩T+)P(T+)=0.000990.02097=992097=33699=11233≈0.0472P(V \mid T^+) = \frac{P(V \cap T^+)}{P(T^+)} = \frac{0.00099}{0.02097} = \frac{99}{2097} = \frac{33}{699} = \frac{11}{233} \approx 0.0472

Interpretation on Paper: Despite a 99%99\% test accuracy, the probability of being infected after a positive test is only ≈4.7%\approx 4.7\%. This occurs because the baseline disease rate is so tiny (0.1%0.1\%) that false positives from the large healthy population (19981998 per 100,000100,000) dwarf the true positives (9999 per 100,000100,000).


Example 3: The Two-Urn Selection Game

Problem Statement: You have two urns:

  • Urn 1 (U1U_1): Contains 44 white balls and 22 black balls (total 66).
  • Urn 2 (U2U_2): Contains 22 white balls and 66 black balls (total 88).

A fair six-sided die is rolled. If a 11 or 22 appears, Urn 1 is chosen. If a 3,4,5,3, 4, 5, or 66 appears, Urn 2 is chosen. A single ball is drawn from the selected urn and is observed to be White (WW). What is the probability that the ball was drawn from Urn 1?

Step-by-Step Paper Solution

Step 1: Determine the prior probabilities of choosing each urn

  • Urn 1 is selected if the die shows {1,2}\{1, 2\}:
P(U1)=26=13P(U_1) = \frac{2}{6} = \frac{1}{3}
  • Urn 2 is selected if the die shows {3,4,5,6}\{3, 4, 5, 6\}:
P(U2)=46=23P(U_2) = \frac{4}{6} = \frac{2}{3}

Check: 13+23=1\frac{1}{3} + \frac{2}{3} = 1.

Step 2: Determine the likelihood of drawing a white ball from each urn

  • From Urn 1:
P(W∣U1)=46=23P(W \mid U_1) = \frac{4}{6} = \frac{2}{3}
  • From Urn 2:
P(W∣U2)=28=14P(W \mid U_2) = \frac{2}{8} = \frac{1}{4}

Step 3: Calculate the joint probabilities

P(U1∩W)=P(U1)×P(W∣U1)=13×23=29P(U2∩W)=P(U2)×P(W∣U2)=23×14=212=16\begin{aligned} P(U_1 \cap W) &= P(U_1) \times P(W \mid U_1) = \frac{1}{3} \times \frac{2}{3} = \frac{2}{9} \\ P(U_2 \cap W) &= P(U_2) \times P(W \mid U_2) = \frac{2}{3} \times \frac{1}{4} = \frac{2}{12} = \frac{1}{6} \end{aligned}

Step 4: Compute the total probability P(W)P(W) Find a common denominator for 99 and 66 (lcm⁡(9,6)=18\operatorname{lcm}(9, 6) = 18):

P(W)=29+16=418+318=718\begin{aligned} P(W) &= \frac{2}{9} + \frac{1}{6} \\ &= \frac{4}{18} + \frac{3}{18} = \frac{7}{18} \end{aligned}

Step 5: Apply Bayes' Theorem

P(U1∣W)=P(U1∩W)P(W)=418718=47P(U_1 \mid W) = \frac{P(U_1 \cap W)}{P(W)} = \frac{\frac{4}{18}}{\frac{7}{18}} = \frac{4}{7}

The probability that the white ball originated from Urn 1 is 47≈57.1%\frac{4}{7} \approx 57.1\%.


Common Mistakes & Paper Traps

  1. The Base Rate Fallacy: Assuming P(Disease∣Positive)=P(Positive∣Disease)P(\text{Disease} \mid \text{Positive}) = P(\text{Positive} \mid \text{Disease}). Neglecting the prior probability P(Disease)P(\text{Disease}) is the single most common statistical error in medicine and law.

  2. Incomplete Partition in the Denominator: Forgetting one of the branches when calculating P(A)P(A). Ensure your hypotheses B1,B2,…,BkB_1, B_2, \dots, B_k cover all possibilities (∑P(Bi)=1\sum P(B_i) = 1).

  3. Inverting the Conditional Notation: Writing P(A∣Bi)P(A \mid B_i) in the denominator instead of P(Bi∣A)P(B_i \mid A) as the goal. Always write: $Target=P(Hypothesis∣Observed Data)\text{Target} = P(\text{Hypothesis} \mid \text{Observed Data})$


Pencil & Paper Practice

Solve these problems in your notebook before reviewing the solutions.

Practice 1

A taxi company operates 70%70\% green cabs and 30%30\% blue cabs. An eyewitness to a hit-and-run accident reports that the cab was blue. Under test conditions simulating the accident, the witness correctly identifies cab color 80%80\% of the time (and misidentifies it 20%20\% of the time). What is the probability that the cab involved in the accident was actually blue?

Practice 2

Three identical boxes each contain two coins:

  • Box A contains 22 gold coins.
  • Box B contains 22 silver coins.
  • Box C contains 11 gold coin and 11 silver coin.

A box is chosen at random and one coin is drawn. It is a gold coin. What is the probability that the other coin in that box is also gold?


Solutions to Practice Problems

Solution 1

  • Hypotheses: Cab is Blue (BB) or Green (GG): $P(B)=0.30,P(G)=0.70P(B) = 0.30, \quad P(G) = 0.70$
  • Witness reports Blue (WBW_B): $P(WB∣B)=0.80,P(WB∣G)=0.20P(W_B \mid B) = 0.80, \quad P(W_B \mid G) = 0.20$
  • Joint probabilities:
P(B∩WB)=0.30×0.80=0.24P(G∩WB)=0.70×0.20=0.14\begin{aligned} P(B \cap W_B) &= 0.30 \times 0.80 = 0.24 \\ P(G \cap W_B) &= 0.70 \times 0.20 = 0.14 \end{aligned}
  • Total probability that witness reports Blue:
P(WB)=0.24+0.14=0.38P(W_B) = 0.24 + 0.14 = 0.38
  • Posterior probability:
P(B∣WB)=P(B∩WB)P(WB)=0.240.38=2438=1219≈0.6316(63.2%)P(B \mid W_B) = \frac{P(B \cap W_B)}{P(W_B)} = \frac{0.24}{0.38} = \frac{24}{38} = \frac{12}{19} \approx 0.6316 \quad (63.2\%)

Solution 2

  • Hypotheses: Box A,B,A, B, or CC selected with equal probability: $P(A)=P(B)=P(C)=13P(A) = P(B) = P(C) = \frac{1}{3}$
  • Event G1G_1: The first drawn coin is Gold.
    • Box A (22 gold): P(G1∣A)=1P(G_1 \mid A) = 1.
    • Box B (00 gold): P(G1∣B)=0P(G_1 \mid B) = 0.
    • Box C (11 gold, 11 silver): P(G1∣C)=12P(G_1 \mid C) = \frac{1}{2}.
  • Total probability of drawing a gold coin:
P(G1)=P(A)P(G1∣A)+P(B)P(G1∣B)+P(C)P(G1∣C)=(13×1)+(13×0)+(13×12)=13+0+16=26+16=36=12\begin{aligned} P(G_1) &= P(A)P(G_1 \mid A) + P(B)P(G_1 \mid B) + P(C)P(G_1 \mid C) \\ &= \left(\frac{1}{3} \times 1\right) + \left(\frac{1}{3} \times 0\right) + \left(\frac{1}{3} \times \frac{1}{2}\right) \\ &= \frac{1}{3} + 0 + \frac{1}{6} = \frac{2}{6} + \frac{1}{6} = \frac{3}{6} = \frac{1}{2} \end{aligned}
  • The "other coin is also gold" occurs if and only if Box A was chosen:
P(A∣G1)=P(A∩G1)P(G1)=13×112=1312=23P(A \mid G_1) = \frac{P(A \cap G_1)}{P(G_1)} = \frac{\frac{1}{3} \times 1}{\frac{1}{2}} = \frac{\frac{1}{3}}{\frac{1}{2}} = \frac{2}{3}

The probability that the remaining coin is gold is 23\frac{2}{3} (Bertrand's Box Paradox).


Test yourself

Let B1B_1 and B2B_2 partition Ω\Omega with P(B1)=0.6P(B_1) = 0.6 and P(B2)=0.4P(B_2) = 0.4. If P(A∣B1)=0.1P(A \mid B_1) = 0.1 and P(A∣B2)=0.2P(A \mid B_2) = 0.2, what is the total probability P(A)P(A)?

  1. 0.140.14
  2. 0.300.30
  3. 0.150.15
  4. 0.120.12

Using the values from the previous question (P(B1)=0.6P(B_1) = 0.6, P(B2)=0.4P(B_2) = 0.4, P(A)=0.14P(A) = 0.14, with P(A∣B1)=0.1P(A \mid B_1) = 0.1), what is the posterior probability P(B1∣A)P(B_1 \mid A)?

  1. 37\frac{3}{7}
  2. 47\frac{4}{7}
  3. 12\frac{1}{2}
  4. 67\frac{6}{7}

What is the primary reason why a positive medical test result may still indicate a low probability of actually having a rare condition?

  1. The low prior base rate of the disease means healthy false positives vastly outnumber true positives.
  2. The test sensitivity is mathematically equal to the false positive rate.
  3. The Law of Total Probability does not apply to clinical medicine.
  4. Conditional probability cannot be inverted.