A rare disease affects 1% of the population. A test gives a positive result for 95% of people who have the disease, but it also gives a false positive for 5% of people who do not. Lan takes the test and gets a positive result. Is the chance that Lan has the disease 95%?
Many people, adults included, answer "yes". The right answer is much lower. This lesson gives us the tools to find it.
The law of total probability
Explore: picture 10000 people
Instead of talking about probabilities, we imagine 10000 people taking the test.
1% of them, that is 100 people, have the disease. Of these, 95%, that is 95 people, test positive.
9900 people do not have the disease. Of these, 5%, that is 495 people, test positive by mistake.
The total number of positive results is 95+495=590. Of those 590 people, only 95 really have the disease:
59095≈0.161.
So a positive result means only about a 16% chance of the disease. To get 590 we added the positive results from two cases: with the disease and without it. That is the idea behind the law of total probability.
Why is it true? The event A happens either together with B or together with B, so A=(A∩B)∪(A∩B), and these two parts are mutually exclusive. By the addition rule, P(A)=P(A∩B)+P(A∩B). Each term comes from the multiplication rule, for example P(A∩B)=P(B)⋅P(A∣B).
On a tree diagram the formula is easy to remember: multiply along each path that leads to A, then add those paths.
Tree diagram for the two machines
Bayes' theorem
The next question is often a "backwards" one: we have seen the result A, so how likely is it that it came from case B? We need P(B∣A), while we are only given P(A∣B).
Why is it true? By definition, P(B∣A)=P(A)P(A∩B). The numerator is rewritten with the multiplication rule, P(A∩B)=P(B)⋅P(A∣B); the denominator with the law of total probability. On a tree diagram: the numerator is one path, the denominator is the sum of all paths leading to A.
Choosing a box and then drawing a ball is a two-stage problem of the same kind.
With more than two cases, we use the general form of both formulas.
A test for a rare disease
Now we answer the question from the start with the formulas.
That is why, after a positive screening test, doctors usually order a second test.
Key terms
Summary
Total probability: P(A)=P(B)P(A∣B)+P(B)P(A∣B); in general, add P(Bi)P(A∣Bi) over a partition.
Bayes: P(B∣A)=P(A)P(B)P(A∣B).
On a tree diagram: multiply along each path; P(A) is the sum of the paths to A; Bayes is "one path divided by the sum".
For a rare disease, the false positives from the huge healthy group can dominate, so P(disease∣positive) can be small.
P(A∣B) is not 1−P(A∣B).
Practice
Each exercise comes with what you need and some steps to start. Try it yourself first, then open the solution.
Exercise 1
Given P(B)=0.3, P(A∣B)=0.6 and P(A∣B)=0.2, find P(A) and P(B∣A).
What you need and how to start
What you need: the law of total probability and Bayes' theorem.
A school has two campuses: 70% of its students are at campus 1 and 30% at campus 2. The proportions who cycle to school at the two campuses are 20% and 50%. A student of the school is chosen at random. Find the probability that the student cycles. If the student cycles, what is the probability that the student is at campus 2?
What you need and how to start
What you need: the two campuses are two complementary cases.
Box I holds 4 red and 6 blue balls; box II holds 7 red and 3 blue balls. A die is rolled: a 1 or a 2 chooses box I, anything else chooses box II; then one ball is drawn at random from the chosen box. Find the probability of a red ball and the probability that a red ball came from box I.
The first box holds 3 white and 2 black balls; the second box holds 2 white and 2 black balls. One ball is moved at random from the first box to the second, and then one ball is drawn at random from the second box. Find the probability that this last ball is white.
What you need and how to start
What you need: two cases: the ball moved is white or black; after the move, the second box has 5 balls.
Steps:
Moving a white ball (probability 53): the second box has 3 white out of 5.
Moving a black ball (probability 52): the second box has 2 white out of 5.
Show solution
P(white)=53⋅53+52⋅52=259+254=2513.
Answer.2513.
Exercise 5
The probability of rain on a given morning is 0.25. If it rains, the bus is late with probability 0.6; if it does not rain, the bus is late with probability 0.2. Is each claim true or false?
a) The probability that the bus is late is 0.3.
b) The probability that the bus is late when it does not rain is 0.8.
c) Given that the bus is late, the probability of rain is 0.5.
d) Given that the bus is not late, the probability of rain is less than 0.25.
What you need and how to start
What you need: the law of total probability and Bayes' theorem; P(not late∣rain)=1−0.6.
Steps:
Find P(late).
Apply Bayes' theorem to "late" and to "not late".
Show solution
a) True: 0.25⋅0.6+0.75⋅0.2=0.15+0.15=0.3.
b) False: that probability is given as 0.2; 0.8 is the probability of not being late when it does not rain.
Three factories supply parts to a phone maker in the proportions 40%, 35%, 25%, with defect rates 2%, 3%, 4%. A part chosen at random is defective. Find the probability that it came from the first factory. Give your answer to 2 decimal places.
What you need and how to start
What you need: the general form of the law of total probability and of Bayes' theorem with three cases.
Steps:
Find P(defective) as a sum of three products.
Divide 0.4⋅0.02 by that sum.
Show solution
P(defective)=0.008+0.0105+0.01=0.0285. The probability is 0.02850.008=5716≈0.2807.
Answer.0.28.
Exercise 7
In a company's inbox, 30% of emails are spam. The phrase "you have won" appears in 40% of spam emails but in only 2% of ordinary emails. A new email contains "you have won". Find the probability that it is spam, as a percentage to 1 decimal place.
What you need and how to start
What you need: Bayes' theorem; this is how a simple spam filter works.
Machine A makes 300 items, 9 of them defective; machine B makes 200 items, 10 of them defective. All the items are mixed and one is picked at random. Find the probability that it is defective in two ways: by direct counting and with the law of total probability. If the item is defective, what is the probability that machine B made it?
Formula: P(A)=500300=0.6, P(defective∣A)=3009=0.03, and similarly for machine B.
Show solution
Counting: 50019=0.038. Formula: 0.6⋅0.03+0.4⋅0.05=0.018+0.02=0.038, the same. P(machine B∣defective)=1910 (counting among the 19 defective items).
Answer.0.038; 1910.
Exercise 9 Review
Box I holds 4 red and 2 white balls; box II holds 2 red and 4 white balls. One box is chosen at random (each with probability 21), and then 2 balls are drawn at random together from that box. Find the probability of getting 2 red balls. If 2 red balls are drawn, what is the probability that box I was chosen?
A disease affects 2% of the population. A test is positive for 90% of people with the disease and gives a false positive for 4% of people without it. a) A person tests positive; find the probability that the person has the disease. b) The person retakes the test and is positive again (the two results are independent for each person); find the probability of the disease again.
What you need and how to start
What you need: Bayes' theorem; with two independent tests, the probability of two positives is 0.92 with the disease and 0.042 without it.
Steps:
a) Numerator 0.02⋅0.9; the denominator adds 0.98⋅0.04.
b) Replace 0.9 by 0.81 and 0.04 by 0.0016.
Show solution
a) 0.018+0.03920.018=0.05720.018≈0.315.
b) 0.02⋅0.81+0.98⋅0.00160.02⋅0.81=0.0177680.0162≈0.912.
Answer. a) ≈0.315; b) ≈0.912.
Mini test
Mini test
Marked like the Vietnamese graduation exam: Part I 0.25 points per question; Part II up to 1 point per question (1, 2, 3, 4 correct statements give 0.1, 0.25, 0.5, 1 point); Part III 0.5 points per question.
Part I. Multiple choice
Question 1. Given P(B)=0.4, P(A∣B)=0.5 and P(A∣B)=0.25, the value of P(A) is
Answer: D.
P(A)=0.4⋅0.5+0.6⋅0.25=0.2+0.15=0.35. A misses the B branch, B adds the two conditional probabilities, and C wrongly uses P(B)=0.4.
Question 2. Machine I makes 70% of the items with a defect rate of 1%; machine II makes 30% with a defect rate of 4%. An item is defective; the probability that machine II made it is closest to
Answer: C.
P(defective)=0.007+0.012=0.019, so P(II∣defective)=0.0190.012=1912≈0.63. A is P(defective∣II), B is the starting probability, and D is the numerator before dividing.
Question 3. Box I holds 2 red and 3 white balls; box II holds 4 red and 1 white ball. A box is chosen at random and one ball is drawn. The probability of a red ball is
Answer: B.
21⋅52+21⋅54=53. A multiplies the two conditional probabilities, C uses only the box I branch, and D forgets to multiply by 21 (a probability cannot exceed 1).
Question 4. A disease affects 0.5% of the population; a test is positive for 99% of people with it and gives a false positive for 2% of people without it. A person tests positive; the probability that the person has the disease is closest to
Answer: C.
0.005⋅0.99+0.995⋅0.020.005⋅0.99=0.024850.00495≈0.199. A confuses P(positive∣disease) with P(disease∣positive), B is 1−0.02, and D is the starting probability.
Part II. True or false
Question 1. Workshop I makes 60% of the items with a defect rate of 3%; workshop II makes 40% with a defect rate of 6%. An item is chosen at random.
a) The probability that the item is defective is 0.042.
b) The probability that the item is defective, given that it is from workshop II, is 0.024.
c) Given that the item is defective, the probability that it is from workshop II is 0.4.
d) Given that the item is not defective, the probability that it is from workshop I is greater than 0.6.
Answer: a) True; b) False; c) False; d) True.
a) True: 0.018+0.024. b) False: that probability is given as 0.06; 0.024 is the probability of "from II and defective". c) False: 0.0420.024=74≈0.571. d) True: 0.9580.6⋅0.97≈0.608.
Part III. Short answer
Question 1.40% of phone users use iOS and 60% use Android. The proportions using app X in the two groups are 30% and 25%. A phone user is chosen at random; find the probability that the user uses app X.
Answer: 0.27.
0.4⋅0.3+0.6⋅0.25=0.12+0.15=0.27.
Question 2. Box I holds 3 red and 7 blue balls; box II holds 6 red and 4 blue balls. A die is rolled: a 6 chooses box I, anything else chooses box II; then one ball is drawn and it is red. Find the probability that it came from box I. Give your answer to 2 decimal places.
Answer: 0.09.
P(red)=61⋅0.3+65⋅0.6=0.05+0.5=0.55, so P(I∣red)=0.550.05=111≈0.09.
Show answers and explanations
Part I, question 1: D. P(A)=0.4⋅0.5+0.6⋅0.25=0.2+0.15=0.35. A misses the B branch, B adds the two conditional probabilities, and C wrongly uses P(B)=0.4.
Part I, question 2: C. P(defective)=0.007+0.012=0.019, so P(II∣defective)=0.0190.012=1912≈0.63. A is P(defective∣II), B is the starting probability, and D is the numerator before dividing.
Part I, question 3: B. 21⋅52+21⋅54=53. A multiplies the two conditional probabilities, C uses only the box I branch, and D forgets to multiply by 21 (a probability cannot exceed 1).
Part I, question 4: C. 0.005⋅0.99+0.995⋅0.020.005⋅0.99=0.024850.00495≈0.199. A confuses P(positive∣disease) with P(disease∣positive), B is 1−0.02, and D is the starting probability.
Part II, question 1: a) True; b) False; c) False; d) True. a) True: 0.018+0.024. b) False: that probability is given as 0.06; 0.024 is the probability of "from II and defective". c) False: 0.0420.024=74≈0.571. d) True: 0.9580.6⋅0.97≈0.608.
Part III, question 1: 0.27. 0.4⋅0.3+0.6⋅0.25=0.12+0.15=0.27.
Part III, question 2: 0.09. P(red)=61⋅0.3+65⋅0.6=0.05+0.5=0.55, so P(I∣red)=0.550.05=111≈0.09.