Suppliers S₁, S₂, S₃ provide 40%, 35% and 25% of a firm's chips, with failure rates 2%, 3% and 4%. A chip picked at random fails. Find the probability that it came from each supplier.
The law of total probability finds P(A) by averaging over a partition of causes; Bayes' theorem inverts the condition, turning P(evidence | cause) into P(cause | evidence). It powers diagnostic tests, spam filters, quality control and every “which box did it come from?” question.
Events B₁, B₂, …, Bₙ form a partition of the sample space when they are pairwise mutually exclusive, their union is S, and each has positive probability. Think of them as the possible causes or sources of what we observe: the machine that made a bolt, the box a ball came from, whether a patient has a disease or not.
Any event A splits into the disjoint pieces A ∩ B₁, …, A ∩ Bₙ. Adding their probabilities and applying the multiplication rule to each gives the law (theorem) of total probability — a weighted average of the conditional probabilities, with the P(Bᵢ) as weights.
Example: machines M₁, M₂, M₃ make 50%, 30% and 20% of a factory's bolts, with defect rates 3%, 4% and 5%. The probability that a randomly chosen bolt is defective is P(D) = 0.5 × 0.03 + 0.3 × 0.04 + 0.2 × 0.05 = 0.015 + 0.012 + 0.010 = 0.037.
A two-cause example: it rains on 30% of mornings; on a rainy morning a commuter is late with probability 0.4, otherwise with probability 0.1. Then P(late) = 0.3 × 0.4 + 0.7 × 0.1 = 0.12 + 0.07 = 0.19. Notice that the answer always lies between the smallest and the largest conditional probability (here between 0.1 and 0.4) — a quick plausibility check.
The proof is two lines. By definition P(Bᵢ|A) = P(Bᵢ ∩ A)/P(A). The multiplication rule rewrites the numerator as P(Bᵢ)·P(A|Bᵢ), and the law of total probability rewrites the denominator. Bayes' theorem is nothing more than the definition of conditional probability applied in both directions.
| Term | Symbol | Meaning |
|---|---|---|
| Prior | P(Bᵢ) | belief about cause i before seeing the evidence |
| Likelihood | P(A | Bᵢ) | how well cause i explains the evidence A |
| Evidence (marginal probability) | P(A) = Σ P(Bⱼ)P(A|Bⱼ) | overall probability of observing A |
| Posterior | P(Bᵢ | A) | updated belief about cause i after seeing A |
History: the Reverend Thomas Bayes (c. 1701–1761) worked out the idea, and his “Essay towards solving a Problem in the Doctrine of Chances” was presented to the Royal Society by Richard Price in 1763, after Bayes's death. Pierre-Simon Laplace independently stated and generalised the result (1774, 1812). It is now the foundation of Bayesian statistics, naive-Bayes classifiers and much of machine learning.
| Machine | Prior P(Mᵢ) | Likelihood P(D|Mᵢ) | Joint P(Mᵢ)·P(D|Mᵢ) | Posterior P(Mᵢ|D) |
|---|---|---|---|---|
| M₁ | 0.50 | 0.03 | 0.015 | 15/37 ≈ 0.405 |
| M₂ | 0.30 | 0.04 | 0.012 | 12/37 ≈ 0.324 |
| M₃ | 0.20 | 0.05 | 0.010 | 10/37 ≈ 0.270 |
| Total | 1.00 | — | P(D) = 0.037 | 1.000 |
Interpretation: M₃ has the worst defect rate but makes the fewest bolts, so a defective bolt most probably came from M₁. Every posterior balances two forces — how common the cause is (prior) and how strongly it produces the evidence (likelihood).
| Phrase in the question | What it gives you |
|---|---|
| “Machine A produces 30% of the items” | a prior: P(A) = 0.3 |
| “One of three boxes is selected at random” | equal priors: 1/3 each |
| “2% of A's items are defective” | a likelihood: P(D | A) = 0.02 |
| “The test detects the disease in 95% of patients” | sensitivity: P(+ | D) = 0.95 |
| “5% of healthy people also test positive” | false-positive rate: P(+ | D′) = 0.05 |
| “The item drawn is found to be defective” | the evidence D — the event you condition on |
| “Find the probability that it was made by A” | the posterior P(A | D) — use Bayes |
| “Find the probability that an item is defective” | the total probability P(D) — no Bayes needed |
Test vocabulary: prevalence P(D) is the base rate of the disease; sensitivity P(+|D) is the true-positive rate; specificity P(−|D′) is the true-negative rate, so the false-positive rate is P(+|D′) = 1 − specificity; and the positive predictive value P(D|+) is what a patient actually wants to know.
Take a disease with prevalence 1% and a test with 95% sensitivity and 95% specificity. Then P(+) = 0.01 × 0.95 + 0.99 × 0.05 = 0.0095 + 0.0495 = 0.059, and P(D|+) = 0.0095/0.059 ≈ 0.161. A positive result means only about a 16% chance of having the disease.
| Out of 10,000 people | Test positive | Test negative | Total |
|---|---|---|---|
| Have the disease | 95 | 5 | 100 |
| Healthy | 495 | 9,405 | 9,900 |
| Total | 590 | 9,410 | 10,000 |
The false positives win because healthy people outnumber sick ones 99 to 1. Answering “95%” — confusing P(+|D) with P(D|+) and ignoring the base rate — is the base-rate fallacy. The flip side is good news: P(D|−) = 5/9,410 ≈ 0.0005, so a negative result is very reassuring.
If a second, independent test is also positive, yesterday's posterior becomes today's prior: P(D|++) = (0.161 × 0.95)/(0.161 × 0.95 + 0.839 × 0.05) ≈ 0.785. In counts: of the 95 true positives about 90.25 test positive again, and of the 495 false positives about 24.75 do, giving 90.25/115 ≈ 78.5%.
Box chosen at random. Equal priors cancel, so the posterior is proportional to the likelihood. Boxes A, B and C give a defective screw with probabilities 1/4, 1/5 and 1/6; a box is picked at random and a defective screw is drawn. P(A | defective) = (1/4)/(1/4 + 1/5 + 1/6) = (15/60)/(37/60) = 15/37.
Two bags. Bag I has 3 red and 5 black balls, bag II has 4 red and 4 black. A coin toss chooses the bag and a red ball is drawn. P(bag I | red) = (1/2)(3/8) / [(1/2)(3/8) + (1/2)(4/8)] = 3/7.
A double-headed coin. A box holds three coins: one has heads on both sides, the other two are fair. A coin is picked at random, tossed, and shows heads. P(double-headed | heads) = (1/3)(1) / [(1/3)(1) + (2/3)(1/2)] = (1/3)/(2/3) = 1/2 — far more than the prior 1/3, because the double-headed coin explains a head perfectly.
Truth-teller. A man speaks the truth 70% of the time. He rolls a die and reports a six. The causes are “it is a six” (prior 1/6, and he reports six when truthful: 0.7) and “it is not a six” (prior 5/6, and he reports six when lying: 0.3). P(six | report) = (1/6)(0.7) / [(1/6)(0.7) + (5/6)(0.3)] = 0.7/2.2 = 7/22 ≈ 0.318.
A naive-Bayes spam filter (Sahami and colleagues, 1998; popularised by Paul Graham's “A Plan for Spam”, 2002) learns priors P(spam) and P(ham) from training mail, and likelihoods P(word | spam) and P(word | ham) from word frequencies. For a new message it computes P(spam | words) and files the message accordingly.
With two words the naive product does the work. Suppose also P(“free” | spam) = 0.3 and P(“free” | ham) = 0.05. For a message containing both words, the spam score is 0.3 × 0.2 × 0.3 = 0.018 and the ham score is 0.7 × 0.01 × 0.05 = 0.00035, so P(spam | both words) = 0.018/(0.018 + 0.00035) ≈ 0.981. Each extra spammy word multiplies the odds again.
The same machinery drives medical expert systems, fault diagnosis (“which component most probably caused this failure?”), document classification, Bayesian networks and A/B testing. Its hallmark is sequential learning: each posterior becomes the prior for the next piece of evidence.
Daniel Kahneman and Amos Tversky made this puzzle famous in the 1970s. In a city, 85% of taxis are Green and 15% are Blue. A taxi was involved in a hit-and-run at night, and a witness says it was Blue. Tested under similar conditions, the witness identifies each colour correctly 80% of the time. What is the probability that the taxi really was Blue? Most people answer 80%.
| Out of 100 cabs | Witness says Blue | Witness says Green | Total |
|---|---|---|---|
| Really Blue | 12 | 3 | 15 |
| Really Green | 17 | 68 | 85 |
| Total | 29 | 71 | 100 |
The specific, vivid evidence (an 80%-reliable witness) feels decisive, while the dull base rate (85% Green) is ignored. Kahneman and Tversky called this base-rate neglect; their work on such biases contributed to Kahneman's 2002 Nobel prize in economics. Bayes' theorem is the cure: it forces both numbers into the calculation.
Try the problem first, then reveal the working one step at a time.
Suppliers S₁, S₂, S₃ provide 40%, 35% and 25% of a firm's chips, with failure rates 2%, 3% and 4%. A chip picked at random fails. Find the probability that it came from each supplier.
5% of a population carry a virus. A test detects it in 90% of carriers but also gives a positive result for 10% of non-carriers. Find P(carrier | positive) and P(carrier | negative).
Bag I contains 3 red and 2 black balls; bag II contains 2 red and 4 black balls. One ball is moved at random from bag I to bag II, and then a ball drawn from bag II is red. Find the probability that the transferred ball was red.
In a 4-option MCQ, a student knows the answer with probability 3/4 and otherwise guesses at random. Given that the student answered correctly, what is the probability that the student knew the answer?
Bag A contains 4 white and 6 black balls; bag B contains 7 white and 3 black. A fair coin decides the bag and a ball is drawn. It is white. Find P(it came from bag A).
A disease has prevalence 2%. A test has sensitivity 90% and specificity 95%. Find P(disease | positive test).
Three identical-looking boxes are equally likely to be chosen. The chance of drawing a defective screw is 1/3 from box A, 1/4 from box B and 1/5 from box C. A defective screw is drawn. Find the probability that it came from box A.
40% of incoming mail is spam. The word “offer” appears in 25% of spam messages and 2% of legitimate ones. A message contains “offer”. What is the probability that it is spam?
A man speaks the truth 4 times out of 5. He rolls a fair die and reports that it shows a six. Using the usual textbook convention, find the probability that it really is a six.
12 questions. 70 % passes the topic quiz (+30 XP, +20 more for 100 %). Exam scoring: +1 correct, −⅓ wrong.
Modelled on real KPSC questions (reworded) with the same concept and answer; each links to its original paper.