Tasks 07-05 - Bayes’ Theorem
Section 07: Probability & Statistics
A: Skills
Problem 1: Bayes’ Theorem with Two Machines (x)
A factory makes the same plastic part on two machines. Machine \(A\) makes 65 % of the parts, machine \(B\) the other 35 %. 2 % of the parts from machine \(A\) and 6 % of the parts from machine \(B\) are defective (\(D\)).
Give probabilities as fractions or decimals. Where a decimal has to be rounded, round to four decimal places and keep all intermediate results unrounded. This rule holds for the whole sheet.
Compute the probability that a part is defective and name the rule you use.
A part is defective. Compute the probability that it comes from machine \(A\) with Bayes’ theorem. Write the formula with the law of total probability in the denominator.
Compute the probability that a defective part comes from machine \(B\). Compare it with the share of machine \(B\) in the production and explain the difference.
\(D'\) (also written \(\bar{D}\)) is the complement of \(D\). A part is not defective. Compute the probability that it comes from machine \(A\).
Given: \(P(A) = 0.65\), \(P(B) = 0.35\), \(P(D \mid A) = 0.02\), \(P(D \mid B) = 0.06\).
Law of total probability:
\[P(D) = P(D \mid A) \cdot P(A) + P(D \mid B) \cdot P(B) = 0.02 \cdot 0.65 + 0.06 \cdot 0.35 = 0.013 + 0.021 = 0.034\]
So 3.4 % of all parts are defective.
Bayes’ theorem, the defect is known, so \(P(D)\) is the denominator:
\[P(A \mid D) = \frac{P(D \mid A) \cdot P(A)}{P(D \mid A) \cdot P(A) + P(D \mid B) \cdot P(B)} = \frac{0.013}{0.034} = \frac{13}{34} \approx 0.3824\]
\[P(B \mid D) = \frac{P(D \mid B) \cdot P(B)}{P(D)} = \frac{0.021}{0.034} = \frac{21}{34} \approx 0.6176\]
Check: \(\frac{13}{34} + \frac{21}{34} = 1\) \(\checkmark\) (a defective part comes from \(A\) or from \(B\)).
Machine \(B\) makes only 35 % of the parts, but about 62 % of the defective parts. Its defect rate is three times as high (6 % instead of 2 %), so its parts are overrepresented among the defective ones.
\(P(\bar{D}) = 1 - 0.034 = 0.966\) and \(P(\bar{D} \mid A) = 1 - 0.02 = 0.98\):
\[P(A \mid \bar{D}) = \frac{P(\bar{D} \mid A) \cdot P(A)}{P(\bar{D})} = \frac{0.98 \cdot 0.65}{0.966} = \frac{0.637}{0.966} = \frac{91}{138} \approx 0.6594\]
This is slightly more than 65 %: machine \(A\) makes fewer defective parts, so its share among the good parts is a bit larger.
Typical mistake: in b), answering \(P(D \mid A) = 0.02\) or the path probability \(0.013\). The question starts with “a part is defective”, so \(D\) is the condition and the base is all defective parts.
Problem 2: Positive and Negative Predictive Value (x)
A veterinary practice (a doctor’s practice for animals) tests dogs for a parasite (\(D\)) with a quick test. 8 % of the dogs tested in the practice have the parasite. The test is positive (\(+\)) for 75 % of the dogs with the parasite and negative (\(-\)) for 95 % of the dogs without it.
Write the three given values in probability notation and name them. Give the false positive rate and the false negative rate.
Compute the positive predictive value \(P(D \mid +)\) and interpret it.
Compute the negative predictive value \(P(\bar{D} \mid -)\) and interpret it.
Complete a table for a hypothetical population of 5,000 tested dogs (rows: test positive or negative, columns: parasite or not, with sums). Check your results from b) and c) with the table.
Base rate \(P(D) = 0.08\), true positive rate \(P(+ \mid D) = 0.75\), true negative rate \(P(- \mid \bar{D}) = 0.95\).
False positive rate \(P(+ \mid \bar{D}) = 1 - 0.95 = 0.05\), false negative rate \(P(- \mid D) = 1 - 0.75 = 0.25\).
Law of total probability for the denominator:
\[P(+) = P(+ \mid D) \cdot P(D) + P(+ \mid \bar{D}) \cdot P(\bar{D}) = 0.75 \cdot 0.08 + 0.05 \cdot 0.92 = 0.06 + 0.046 = 0.106\]
\[P(D \mid +) = \frac{P(+ \mid D) \cdot P(D)}{P(+)} = \frac{0.06}{0.106} = \frac{30}{53} \approx 0.5660\]
Of the dogs with a positive test, about 57 % really have the parasite. The other 43 % are false alarms.
\[P(-) = 1 - 0.106 = 0.894, \qquad P(\bar{D} \mid -) = \frac{P(- \mid \bar{D}) \cdot P(\bar{D})}{P(-)} = \frac{0.95 \cdot 0.92}{0.894} = \frac{0.874}{0.894} = \frac{437}{447} \approx 0.9776\]
Of the dogs with a negative test, about 98 % are really free of the parasite.
\(5000 \cdot 0.08 = 400\) dogs with the parasite, \(4600\) without. Then \(400 \cdot 0.75 = 300\) true positives and \(4600 \cdot 0.05 = 230\) false positives:
parasite (\(D\)) no parasite (\(\bar{D}\)) sum positive (\(+\)) 300 230 530 negative (\(-\)) 100 4,370 4,470 sum 400 4,600 5,000 Check: \(\frac{300}{530} = \frac{30}{53}\) \(\checkmark\) and \(\frac{4370}{4470} = \frac{437}{447}\) \(\checkmark\)
Typical mistake: in b), taking the true positive rate \(0.75\) as the answer. The true positive rate looks at the dogs with the parasite, the positive predictive value at the dogs with a positive test (row sum 530).
Problem 3: Bayes’ Theorem with Three Suppliers (xx)
A bicycle manufacturer buys its brake cables from three suppliers: 45 % from supplier \(A\), 35 % from supplier \(B\) and 20 % from supplier \(C\). 1 % of the cables from \(A\), 4 % of the cables from \(B\) and 5 % of the cables from \(C\) are faulty (\(F\)).
Draw a tree diagram with all branch and path probabilities and compute the probability that a cable is faulty.
A cable is faulty. Compute the probability that it comes from supplier \(C\).
Compute the probabilities that a faulty cable comes from \(A\) and from \(B\). Check that the three results from b) and c) add up to 1.
The purchasing manager wants to talk first to the supplier “that causes the most problems”. Explain why one could name supplier \(C\) as well as supplier \(B\), and which supplier fits which goal.
First stage: supplier, second stage: faulty or not.
- \(A\) (\(0.45\))
- \(F\) (\(0.01\)): \(0.45 \cdot 0.01 = 0.0045\)
- \(\bar{F}\) (\(0.99\)): \(0.45 \cdot 0.99 = 0.4455\)
- \(B\) (\(0.35\))
- \(F\) (\(0.04\)): \(0.35 \cdot 0.04 = 0.014\)
- \(\bar{F}\) (\(0.96\)): \(0.35 \cdot 0.96 = 0.336\)
- \(C\) (\(0.20\))
- \(F\) (\(0.05\)): \(0.20 \cdot 0.05 = 0.01\)
- \(\bar{F}\) (\(0.95\)): \(0.20 \cdot 0.95 = 0.19\)
Law of total probability with three branches:
\[P(F) = 0.0045 + 0.014 + 0.01 = 0.0285\]
- \(A\) (\(0.45\))
Bayes’ theorem, the base is all faulty cables:
\[P(C \mid F) = \frac{P(F \mid C) \cdot P(C)}{P(F)} = \frac{0.01}{0.0285} = \frac{20}{57} \approx 0.3509\]
\[P(A \mid F) = \frac{0.0045}{0.0285} = \frac{3}{19} \approx 0.1579, \qquad P(B \mid F) = \frac{0.014}{0.0285} = \frac{28}{57} \approx 0.4912\]
Check: \(\frac{9}{57} + \frac{28}{57} + \frac{20}{57} = \frac{57}{57} = 1\) \(\checkmark\)
Supplier \(C\) has the highest defect rate (5 %), so a single cable from \(C\) is the most likely to be faulty. If the goal is the quality of each delivery, the manager should talk to \(C\).
Supplier \(B\) causes the most faulty cables in the factory: about 49 % of them, because \(B\) delivers almost twice as many cables as \(C\). If the goal is to reduce the number of faulty cables quickly, the manager should talk to \(B\).
Typical mistake: in d), comparing only the defect rates 1 %, 4 % and 5 %. The share of the faulty cables also depends on how many cables each supplier delivers, and that is exactly what Bayes’ theorem takes into account.
Problem 4: From Statements to Notation (xx)
The owner of a café with a large terrace plans the staff for the terrace with a weather app. Let \(R\) = “it rains on the day” and \(+\) = “the app predicts rain for the day”. Last summer, it rained on 20 % of the days. The owner has noted two statements:
- “On 90 % of the rainy days, the app had predicted rain.”
- “On 15 % of the dry days, the app predicted rain anyway.”
Translate the two statements into probability notation and name the rates. Give the true negative rate and the false negative rate.
Compute \(P(R \cap -)\) and say in words what it describes.
Compute \(P(R \mid -)\) and give \(P(- \mid R)\). Explain which question each of the three probabilities \(P(R \cap -)\), \(P(R \mid -)\) and \(P(- \mid R)\) answers.
The terrace season has 150 days. Estimate on how many days it rains although the app predicted no rain, and on how many days the app predicts rain, but it stays dry.
“Of the rainy days” names the condition \(R\):
- \(P(+ \mid R) = 0.9\), the true positive rate
- \(P(+ \mid \bar{R}) = 0.15\), the false positive rate (a rain forecast on a dry day)
True negative rate \(P(- \mid \bar{R}) = 1 - 0.15 = 0.85\), false negative rate \(P(- \mid R) = 1 - 0.9 = 0.1\). The base rate is \(P(R) = 0.2\).
Multiplication rule along the path \(R \to -\):
\[P(R \cap -) = P(R) \cdot P(- \mid R) = 0.2 \cdot 0.1 = 0.02\]
On 2 % of all days, it rains and the app had not predicted rain (a false negative).
\(P(-) = P(R \cap -) + P(\bar{R} \cap -) = 0.02 + 0.8 \cdot 0.85 = 0.02 + 0.68 = 0.7\), so
\[P(R \mid -) = \frac{P(R \cap -)}{P(-)} = \frac{0.02}{0.7} = \frac{1}{35} \approx 0.0286, \qquad P(- \mid R) = 0.1\]
- \(P(R \cap -) = 0.02\) (joint probability): of all days, how many are rainy days without a rain forecast?
- \(P(R \mid -) \approx 0.0286\) (conditional probability): if the app predicts no rain, how likely does it rain anyway?
- \(P(- \mid R) = 0.1\) (false negative rate): of the rainy days, on how many did the app miss the rain?
Same numerator, three different bases: all days, the days without a rain forecast and the rainy days.
Relative frequency ≈ probability:
- rain without a forecast: \(150 \cdot 0.02 = 3\) days
- rain forecast on a dry day: \(150 \cdot P(\bar{R} \cap +) = 150 \cdot 0.8 \cdot 0.15 = 150 \cdot 0.12 = 18\) days
Typical mistake: in a), writing the second statement as \(P(\bar{R} \mid +) = 0.15\). The 15 % refer to the dry days, so \(\bar{R}\) is the condition and goes behind the bar.
Problem 5: The Base Rate Effect (xx)
A test for a condition \(D\) has a true positive rate of 80 % and a true negative rate of 96 %. It is used in three groups with different base rates: 20 %, 2 % and 0.2 %.
Compute the positive predictive value \(P(D \mid +)\) for each of the three base rates.
For the base rate 0.2 %, complete a table for a hypothetical population of 100,000 people and check your result from a).
Describe how the positive predictive value changes with the base rate. Explain with the table from b) why a positive result is so weak evidence in the group with the base rate 0.2 %, and suggest what should follow a positive result there.
False positive rate \(P(+ \mid \bar{D}) = 1 - 0.96 = 0.04\). With base rate \(p\), Bayes’ theorem gives \(P(D \mid +) = \frac{0.8p}{0.8p + 0.04(1 - p)}\):
- \(p = 0.2\): \(\frac{0.16}{0.16 + 0.032} = \frac{0.16}{0.192} = \frac{5}{6} \approx 0.8333\)
- \(p = 0.02\): \(\frac{0.016}{0.016 + 0.0392} = \frac{0.016}{0.0552} = \frac{20}{69} \approx 0.2899\)
- \(p = 0.002\): \(\frac{0.0016}{0.0016 + 0.03992} = \frac{0.0016}{0.04152} = \frac{20}{519} \approx 0.0385\)
\(100{,}000 \cdot 0.002 = 200\) people with the condition, \(99{,}800\) without. True positives \(200 \cdot 0.8 = 160\), false positives \(99{,}800 \cdot 0.04 = 3{,}992\):
condition (\(D\)) no condition (\(\bar{D}\)) sum positive (\(+\)) 160 3,992 4,152 negative (\(-\)) 40 95,808 95,848 sum 200 99,800 100,000 Check: \(\frac{160}{4152} = \frac{20}{519} \approx 0.0385\) \(\checkmark\)
The lower the base rate, the lower the positive predictive value (83 %, 29 %, 4 %), although the test itself stays the same.
In the group with 0.2 %, almost everybody is free of the condition. 4 % of the 99,800 people without the condition are still 3,992 false positives, while only 160 of the 200 people with the condition test positive. So about 24 of 25 positive results are false alarms. A positive result there should be followed by a second, more precise test before anybody acts on it.
Typical mistake: in a), using the true negative rate \(0.96\) in the denominator instead of the false positive rate \(0.04\). The second term of the denominator counts the positive results among the people without the condition.
B: Set Up & Check
Problem 6: From Words to Rates (xx)
Translate each statement into probability notation. Then answer the check question: it tells you whether your translation works.
A car workshop uses a diagnostic device (a device that reads out the car’s electronics). The device shows a battery fault (\(+\)) for 94 % of the cars that have a battery fault (\(B\)). Write the statement in probability notation, name the rate and give the false negative rate.
Check: A classmate writes \(P(B \mid +) = 0.94\) and reads it as “94 % of the cars with a fault message have a battery fault”. Explain which event is the condition in the workshop’s statement.
A sorting machine on a potato farm sorts out (\(+\)) potatoes with damage (\(D\)). It wrongly sorts out 2.5 % of the undamaged potatoes. Write the statement in probability notation, name the rate and give the true negative rate.
Check: The farmer concludes: “So 2.5 % of the potatoes that the machine sorts out are undamaged.” Decide whether this follows from the statement.
A building surveyor (an expert who checks the condition of buildings) checks 800 old houses for hidden mould (\(M\)) with a moisture meter. 120 of the houses have mould. 18 houses have mould, but the meter says there is none (\(-\)). In total, the meter shows no mould for 650 houses. Write the probability that a house has mould but the meter says there is none, and the probability that a house with a negative result has mould, in probability notation. Compute both and \(P(- \mid M)\).
Check: A local newspaper writes: “Only 2.25 % of the houses with a negative result have mould.” Decide whether this is right.
A security company runs alarm systems in shops. Last year, the alarms went off (\(+\)) 200 times, and 48 of these alarms were real break-ins (\(E\)). In total, there were 50 break-ins in these shops. Compute the probability that an alarm really is a break-in and name this value.
Check: The company advertises: “Our alarm is right in 96 % of the cases.” Find out what the 96 % are and explain why the advertisement is misleading.
A vegetable farm buys 2,000 young tomato plants. The supplier states that 5 % of its plants carry a plant disease (\(D\)). The farm tests all plants with a quick test that has a true positive rate of 88 % and a false positive rate of 3 %, and 145 plants test positive. Write the base rate and the probability of a positive test in probability notation.
Check: A classmate uses \(\frac{145}{2000} = 7.25\,\%\) as the base rate. Explain the mistake and check with the law of total probability that 145 positive tests fit the supplier’s 5 %.
“Of the cars that have a battery fault” names the condition \(B\):
\[P(+ \mid B) = 0.94 \quad \text{(true positive rate)}, \qquad P(- \mid B) = 1 - 0.94 = 0.06 \quad \text{(false negative rate)}\]
Check: the workshop’s statement starts from the cars with a battery fault, so \(B\) goes behind the bar. The classmate’s \(P(B \mid +)\) starts from the cars with a fault message. That is the positive predictive value, and it cannot be computed without the base rate and the false positive rate.
Typical mistake: writing \(P(B \cap +) = 0.94\). The 94 % refer only to the cars with a battery fault, not to all cars.
“Of the undamaged potatoes” names the condition \(\bar{D}\):
\[P(+ \mid \bar{D}) = 0.025 \quad \text{(false positive rate)}, \qquad P(- \mid \bar{D}) = 1 - 0.025 = 0.975 \quad \text{(true negative rate)}\]
Check: the farmer’s sentence is \(P(\bar{D} \mid +)\), with the sorted-out potatoes as the base. It does not follow: this share depends on how many potatoes are damaged and how many damaged potatoes the machine finds.
Typical mistake: calling the 2.5 % the true negative rate. “Wrongly” means a positive result for an undamaged potato, i.e. a false positive.
“Has mould but the meter says there is none” is the joint probability \(P(M \cap -)\) with all 800 houses as the base. “A house with a negative result has mould” is the conditional probability \(P(M \mid -)\) with the 650 negative results as the base. \(P(- \mid M)\) has the 120 houses with mould as the base:
\[P(M \cap -) = \frac{18}{800} = 0.0225, \qquad P(M \mid -) = \frac{18}{650} = \frac{9}{325} \approx 0.0277, \qquad P(- \mid M) = \frac{18}{120} = 0.15\]
Check: the newspaper is wrong. 2.25 % is the joint probability \(P(M \cap -)\): of all 800 houses, 2.25 % have mould and a negative result. Of the 650 houses with a negative result, about 2.77 % have mould.
Typical mistake: using the same base for all three values. The numerator is always 18, but each probability has its own base.
The alarm is known, so the base is all 200 alarms:
\[P(E \mid +) = \frac{48}{200} = 0.24 \quad \text{(positive predictive value)}\]
Check: \(\frac{48}{50} = 0.96 = P(+ \mid E)\) is the true positive rate: 96 % of the break-ins trigger an alarm. The advertisement suggests that an alarm is right in 96 % of the cases, but only 24 % of the alarms are real break-ins. The other 152 alarms are false alarms.
Typical mistake: dividing by the 50 break-ins when the question starts with “an alarm”. The event that is known (the alarm) gives the base.
\(P(D) = 0.05\) (base rate) and \(P(+) = \frac{145}{2000} = 0.0725\) (share of positive tests).
Check: the positive tests are not the same as the diseased plants. They contain false positives, and some diseased plants test negative. Law of total probability:
\[P(+) = P(+ \mid D) \cdot P(D) + P(+ \mid \bar{D}) \cdot P(\bar{D}) = 0.88 \cdot 0.05 + 0.03 \cdot 0.95 = 0.044 + 0.0285 = 0.0725 \;\checkmark\]
In counts: 100 diseased plants give 88 positive tests, 1,900 healthy plants give 57 false positives, and \(88 + 57 = 145\).
Typical mistake: taking the share of positive tests as the base rate. The base rate belongs to the plants, not to the test results.
Problem 7: One Paragraph, All Rates (xx)
A software company checks every change to the code of its app with an automatic test tool before the change goes live. From past data, 12 % of the changes contain a bug (\(D\)), i.e. an error in the code. The prevalence (base rate) of bugs is therefore 0.12. The tool flags (\(+\)) 85 % of the changes with a bug, so its sensitivity (true positive rate) is 0.85. For 96 % of the changes without a bug, the tool does not raise a flag (\(-\)), so its specificity (true negative rate) is 0.96. The team lead wants to know the probability that a flagged change really contains a bug, the probability that a change contains a bug but is incorrectly identified as free of bugs, and the probability that a change without a flag is really free of bugs. The team lead also asks how many flags to expect for the 1,500 changes of one month.
List every given value in probability notation with its course name. Then write every question of the team lead as a mathematical statement and name the rule you would use. Do not compute anything.
Check: An assistant writes the specificity as \(P(+ \mid \bar{D}) = 0.96\). Explain the mistake and give the false positive rate.
Given values:
- Base rate (prevalence): \(P(D) = 0.12\), so \(P(\bar{D}) = 1 - 0.12\)
- True positive rate (sensitivity): \(P(+ \mid D) = 0.85\), so the false negative rate is \(P(- \mid D) = 1 - 0.85\)
- True negative rate (specificity): \(P(- \mid \bar{D}) = 0.96\), so the false positive rate is \(P(+ \mid \bar{D}) = 1 - 0.96\)
Questions as mathematical statements:
- A flagged change really contains a bug: positive predictive value \(P(D \mid +) = \frac{P(+ \mid D) \cdot P(D)}{P(+ \mid D) \cdot P(D) + P(+ \mid \bar{D}) \cdot P(\bar{D})}\), Bayes’ theorem with the law of total probability in the denominator
- A change contains a bug but is incorrectly identified as free of bugs: \(P(D \cap -) = P(D) \cdot P(- \mid D)\), multiplication rule (one path, a joint probability with all changes as the base)
- A change without a flag is really free of bugs: negative predictive value \(P(\bar{D} \mid -) = \frac{P(- \mid \bar{D}) \cdot P(\bar{D})}{P(-)}\) with \(P(-) = P(- \mid D) \cdot P(D) + P(- \mid \bar{D}) \cdot P(\bar{D})\), Bayes’ theorem
- Expected number of flags: \(1500 \cdot P(+)\) with \(P(+) = P(+ \mid D) \cdot P(D) + P(+ \mid \bar{D}) \cdot P(\bar{D})\), law of total probability and relative frequency ≈ probability
Check: the specificity describes the changes without a bug that correctly get no flag, so it is \(P(- \mid \bar{D}) = 0.96\). \(P(+ \mid \bar{D})\) is the false positive rate, \(1 - 0.96 = 0.04\).
Typical mistake: writing question 5 as \(P(D \mid -)\). “A change contains a bug but is incorrectly identified as free of bugs” speaks about all changes, so it is the joint probability \(P(D \cap -)\), not a probability among the changes without a flag.
C: Applied
Problem 8: Cork Taint in Two Test Stages (xx)
A cork producer delivers natural corks for wine bottles in batches. Some batches have cork taint (\(D\)), a musty smell that spoils the wine in the bottle. From past data, 4 % of the batches are tainted. Every batch first goes through a smell test by trained staff (\(T_1\) = “the smell test is positive”). The smell test is positive for 80 % of the tainted batches, but also for 25 % of the clean batches, because the staff pass on every batch with the slightest doubt. Only batches with a positive smell test go to a lab test (\(T_2\) = “the lab test is positive”). The lab test is positive for 95 % of the tainted batches and for 1 % of the clean batches, whatever the smell test showed. Batches with two positive results are destroyed, all other batches are sold.
- Create a tree diagram for the smell test with all branch and path probabilities and compute the probability that a batch has a positive smell test.
(for verification: 27.2 %)
- Compute the positive predictive value of the smell test alone and interpret it.
(for verification: about 11.76 %)
- Compute the probability that a batch with two positive results is really tainted.
Hint: The batches with a positive smell test are the population for the lab test. Their base rate is your result from b).
For 10,000 batches, estimate the number of lab tests, the number of tainted batches that are sold and the number of clean batches that are destroyed.
Compute the share of the tainted batches that the two-stage procedure finds. Compare it with a lab test for every batch and explain why the producer still uses the smell test first.
a) First stage: tainted or clean, second stage: result of the smell test.
- \(D\) (\(0.04\))
- \(T_1\) (\(0.8\)): \(0.04 \cdot 0.8 = 0.032\)
- \(\bar{T}_1\) (\(0.2\)): \(0.04 \cdot 0.2 = 0.008\)
- \(\bar{D}\) (\(0.96\))
- \(T_1\) (\(0.25\)): \(0.96 \cdot 0.25 = 0.24\)
- \(\bar{T}_1\) (\(0.75\)): \(0.96 \cdot 0.75 = 0.72\)
Check: \(0.032 + 0.008 + 0.24 + 0.72 = 1\) \(\checkmark\)
Law of total probability: \(P(T_1) = 0.032 + 0.24 = 0.272\)
b) Bayes’ theorem, the base is all batches with a positive smell test:
\[P(D \mid T_1) = \frac{P(T_1 \mid D) \cdot P(D)}{P(T_1)} = \frac{0.032}{0.272} = \frac{2}{17} \approx 0.1176\]
Only about 12 % of the batches that fail the smell test are really tainted. Almost 9 of 10 of them are clean. The smell test alone would destroy far too many good batches.
c) For the lab test, the base rate is \(\frac{2}{17}\) and the share of clean batches is \(\frac{15}{17}\):
\[P(D \mid T_1 \cap T_2) = \frac{0.95 \cdot \frac{2}{17}}{0.95 \cdot \frac{2}{17} + 0.01 \cdot \frac{15}{17}} = \frac{1.9}{1.9 + 0.15} = \frac{1.9}{2.05} = \frac{38}{41} \approx 0.9268\]
(Multiplying the numerator and the denominator by 17 removes the fractions.)
Check with counts: of 10,000 batches, \(2{,}720\) fail the smell test, \(320\) tainted and \(2{,}400\) clean ones. The lab test is positive for \(320 \cdot 0.95 = 304\) tainted and \(2400 \cdot 0.01 = 24\) clean batches, and \(\frac{304}{328} = \frac{38}{41}\) \(\checkmark\)
d) Relative frequency ≈ probability, with the counts from c):
- lab tests: \(10{,}000 \cdot 0.272 = 2{,}720\)
- tainted batches sold: \(400 - 304 = 96\) (80 missed by the smell test and \(320 - 304 = 16\) missed by the lab test)
- clean batches destroyed: \(24\)
e) A tainted batch is only found if both tests are positive:
\[P(T_1 \cap T_2 \mid D) = 0.8 \cdot 0.95 = 0.76 = \frac{304}{400}\]
The procedure finds 76 % of the tainted batches. A lab test for every batch would find 95 %. The batches that the smell test misses never reach the lab, so the second stage cannot repair these mistakes.
The producer still starts with the smell test because it saves lab tests: only 2,720 instead of 10,000 lab tests for 10,000 batches. The price is that more tainted batches are sold (96 instead of 20).
Typical mistake: in c), using the base rate 4 % again for the lab test. The lab only sees the batches that failed the smell test, and among them about 12 % are tainted.
Problem 9: Payment Classes of a Food Wholesaler (xx)
A food wholesaler (a company that sells food in large amounts to other businesses) supplies restaurants. It sorts its restaurant customers into three payment classes: 60 % are in class \(A\), 30 % in class \(B\) and 10 % in class \(C\). An invoice of a class \(A\) customer is paid late (\(L\)) with a probability of 2 %, an invoice of a class \(B\) customer with 10 % and an invoice of a class \(C\) customer with 30 %.
- Create a tree diagram with all branch and path probabilities and compute the probability that an invoice is paid late.
(for verification: 7.2 %)
An invoice was paid late. Compute the probability that it comes from a class \(C\) customer. Compare the result with the share of class \(C\) and explain the difference.
A new restaurant becomes a customer. The wholesaler does not know its class yet, and the shares above also hold for new customers. For a customer of a given class, each invoice is paid late or on time independently of the other invoices. Compute the probability that the new customer pays its first three invoices on time.
(for verification: about 0.8177)
- The wholesaler gives a customer a longer payment term (30 days instead of 14) as soon as the probability that the customer is in class \(C\) is below 5 %. Compute this probability for a new customer who has paid its first three invoices on time and for a new customer who has paid its first two invoices on time. Decide after how many invoices paid on time the new customer gets the longer payment term.
a) First stage: payment class, second stage: invoice paid late or on time.
- \(A\) (\(0.6\))
- \(L\) (\(0.02\)): \(0.6 \cdot 0.02 = 0.012\)
- \(\bar{L}\) (\(0.98\)): \(0.6 \cdot 0.98 = 0.588\)
- \(B\) (\(0.3\))
- \(L\) (\(0.1\)): \(0.3 \cdot 0.1 = 0.03\)
- \(\bar{L}\) (\(0.9\)): \(0.3 \cdot 0.9 = 0.27\)
- \(C\) (\(0.1\))
- \(L\) (\(0.3\)): \(0.1 \cdot 0.3 = 0.03\)
- \(\bar{L}\) (\(0.7\)): \(0.1 \cdot 0.7 = 0.07\)
Check: \(0.012 + 0.588 + 0.03 + 0.27 + 0.03 + 0.07 = 1\) \(\checkmark\)
Law of total probability: \(P(L) = 0.012 + 0.03 + 0.03 = 0.072\)
b) Bayes’ theorem, the base is all late invoices:
\[P(C \mid L) = \frac{P(L \mid C) \cdot P(C)}{P(L)} = \frac{0.03}{0.072} = \frac{5}{12} \approx 0.4167\]
Class \(C\) has only 10 % of the customers, but about 42 % of the late invoices. A class \(C\) invoice is paid late 15 times as often as a class \(A\) invoice (30 % instead of 2 %), so class \(C\) is strongly overrepresented among the late invoices.
c) Let \(K\) = “the first three invoices are paid on time”. Within one class, the three invoices are independent, so the probabilities multiply:
\[P(K \mid A) = 0.98^3 = 0.941192, \qquad P(K \mid B) = 0.9^3 = 0.729, \qquad P(K \mid C) = 0.7^3 = 0.343\]
Law of total probability over the three classes:
\[P(K) = 0.6 \cdot 0.941192 + 0.3 \cdot 0.729 + 0.1 \cdot 0.343 = 0.5647152 + 0.2187 + 0.0343 = 0.8177152 \approx 0.8177\]
d) Three invoices on time, Bayes’ theorem with \(P(K)\) from c):
\[P(C \mid K) = \frac{P(K \mid C) \cdot P(C)}{P(K)} = \frac{0.0343}{0.8177152} \approx 0.0419\]
Two invoices on time (\(K_2\)): \(P(K_2) = 0.6 \cdot 0.98^2 + 0.3 \cdot 0.9^2 + 0.1 \cdot 0.7^2 = 0.57624 + 0.243 + 0.049 = 0.86824\) and
\[P(C \mid K_2) = \frac{0.049}{0.86824} \approx 0.0564\]
After two invoices on time, the probability for class \(C\) is still 5.64 % > 5 %. After three invoices on time, it is 4.19 % < 5 %. So the new customer gets the longer payment term after the third invoice paid on time.
Each invoice paid on time lowers the probability for class \(C\) (10 %, then about 7.54 % after one, 5.64 % after two, 4.19 % after three invoices), because a class \(C\) customer pays on time less often than the others.
Typical mistake: in c), computing \(0.928^3 \approx 0.7992\) with \(P(\bar{L}) = 1 - 0.072\). The invoices are only independent within one class. For a new customer, the first invoice on time already makes class \(C\) less likely, so the class must be the first stage of the tree.
Problem 10: Leak Detection in a Water Network (xxx)
The water utility of a city (the company that supplies the city with drinking water) has 5,000 pipe sections. An acoustic sensor listens to the noise in a pipe and flags (\(+\)) the sections that might have a leak (\(L\)). The sensor flags 85 % of the sections with a leak and 5 % of the sections without a leak. Every flagged section is dug up, which is expensive. In the whole network, 8 % of the sections have a leak.
Compute the positive predictive value for the whole network. The head of the utility says: “The sensor finds 85 % of the leaks, so 85 % of our digs will find a leak.” Assess this statement.
The utility only wants to use the sensor where at least 75 % of the digs find a leak. Let \(p\) be the base rate of leaks in a group of sections, and the sensor’s rates stay the same. Determine the smallest base rate \(p\) for which the positive predictive value is at least 75 %.
Hint: The denominator is positive for \(0 < p < 1\), so you can multiply both sides of the inequality by it without changing the sign.
(for verification: \(p \geq 15\,\%\))
1,000 of the sections are old cast-iron pipes, and 24 % of them have a leak. The other 4,000 sections are newer plastic pipes, and 4 % of them have a leak. Check that these values fit the 8 % of the whole network. Decide with b) for both kinds of pipes whether the sensor meets the target, and compute both positive predictive values.
The utility uses the sensor only on the cast-iron sections. Estimate the number of digs, the number of digs without a leak and the number of leaks the sensor misses on these sections. Compare the number of digs without a leak and the number of leaks found with the use of the sensor on all 5,000 sections.
a) Base rate \(P(L) = 0.08\), true positive rate \(P(+ \mid L) = 0.85\), false positive rate \(P(+ \mid \bar{L}) = 0.05\):
\[P(+) = 0.85 \cdot 0.08 + 0.05 \cdot 0.92 = 0.068 + 0.046 = 0.114\]
\[P(L \mid +) = \frac{0.068}{0.114} = \frac{34}{57} \approx 0.5965\]
The statement is wrong. 85 % is the true positive rate \(P(+ \mid L)\): of the sections with a leak, the sensor flags 85 %. The share of digs that find a leak is \(P(L \mid +)\), and it is only about 60 %. About 4 of 10 digs find no leak, because the many sections without a leak produce many false positives.
b) With base rate \(p\), the path probabilities are \(0.85p\) and \(0.05(1 - p)\):
\[P(L \mid +) = \frac{0.85p}{0.85p + 0.05(1 - p)} \geq 0.75\]
The denominator is positive for \(0 < p < 1\), so multiplying by it keeps the inequality sign:
\[0.85p \geq 0.75 \cdot (0.85p + 0.05 - 0.05p) = 0.75 \cdot (0.8p + 0.05) = 0.6p + 0.0375\]
\[0.25p \geq 0.0375 \iff p \geq \frac{0.0375}{0.25} = 0.15\]
(Dividing by the positive number 0.25 keeps the sign.) The base rate must be at least 15 %.
Check with \(p = 0.15\): \(\frac{0.1275}{0.1275 + 0.0425} = \frac{0.1275}{0.17} = 0.75\) \(\checkmark\)
c) Leaks: \(1000 \cdot 0.24 + 4000 \cdot 0.04 = 240 + 160 = 400\), and \(\frac{400}{5000} = 0.08\) \(\checkmark\)
Cast iron: \(0.24 \geq 0.15\), the target is met:
\[P(L \mid +) = \frac{0.85 \cdot 0.24}{0.85 \cdot 0.24 + 0.05 \cdot 0.76} = \frac{0.204}{0.204 + 0.038} = \frac{0.204}{0.242} = \frac{102}{121} \approx 0.8430\]
Plastic: \(0.04 < 0.15\), the target is not met:
\[P(L \mid +) = \frac{0.85 \cdot 0.04}{0.85 \cdot 0.04 + 0.05 \cdot 0.96} = \frac{0.034}{0.034 + 0.048} = \frac{0.034}{0.082} = \frac{17}{41} \approx 0.4146\]
d) Cast-iron sections only (relative frequency ≈ probability):
- digs: \(1000 \cdot 0.242 = 242\)
- digs without a leak: \(1000 \cdot 0.038 = 38\)
- leaks missed: \(240 \cdot 0.15 = 36\) (the sensor finds \(242 - 38 = 204\) leaks)
All 5,000 sections: digs \(5000 \cdot 0.114 = 570\), digs without a leak \(5000 \cdot 0.046 = 230\), leaks found \(5000 \cdot 0.068 = 340\).
With the sensor on all sections, the utility finds 136 more leaks (340 instead of 204), but it digs \(230 - 38 = 192\) more times in vain. All of these extra digs in vain are in the plastic pipes, where the base rate is low.
Typical mistake: in b), multiplying by the denominator and forgetting that \(P(\bar{L}) = 1 - p\) also depends on \(p\). The false positive path is \(0.05(1 - p)\), not \(0.05 \cdot 0.92\).
D: FSP Problem
Work on this problem as in the exam: write down every step. The points show what each part is worth.
FSP Problem: Antibiotic Residues in Milk Deliveries [22 pts. total]
A dairy buys milk from farms in its region. Before the milk of a delivery is pumped into the dairy’s tanks, a rapid test checks it for antibiotic residues (\(R\)), i.e. remains of medicine that farmers give to sick cows. Milk with residues must not be processed. From past data:
- 1.6 % of all deliveries contain residues, so the prevalence (base rate) is 0.016.
- In 96 % of the deliveries with residues, the test is positive (\(+\)), so its sensitivity (true positive rate) is 0.96.
- In 98 % of the deliveries without residues, the test is negative (\(-\)), so its specificity (true negative rate) is 0.98.
Round probabilities to four decimal places where rounding is necessary.
Part a)
The dairy receives 25,000 deliveries per year. Create a tree diagram for the screening and complete the following table. [7 pts.]
| residues (\(R\)) | no residues (\(\bar{R}\)) | sum | |
|---|---|---|---|
| test positive (\(+\)) | |||
| test negative (\(-\)) | |||
| sum | 25,000 |
Given: \(P(R) = 0.016\), \(P(+ \mid R) = 0.96\), \(P(- \mid \bar{R}) = 0.98\). Complements: \(P(\bar{R}) = 0.984\), \(P(- \mid R) = 0.04\), \(P(+ \mid \bar{R}) = 0.02\).
Tree diagram (path probability = product along the path):
- \(R\) (\(0.016\))
- \(+\) (\(0.96\)): \(0.016 \cdot 0.96 = 0.01536\)
- \(-\) (\(0.04\)): \(0.016 \cdot 0.04 = 0.00064\)
- \(\bar{R}\) (\(0.984\))
- \(+\) (\(0.02\)): \(0.984 \cdot 0.02 = 0.01968\)
- \(-\) (\(0.98\)): \(0.984 \cdot 0.98 = 0.96432\)
Table (path probability \(\cdot\) 25,000):
| \(R\) | \(\bar{R}\) | sum | |
|---|---|---|---|
| \(+\) | 384 | 492 | 876 |
| \(-\) | 16 | 24,108 | 24,124 |
| sum | 400 | 24,600 | 25,000 |
Check: \(876 + 24{,}124 = 25{,}000\) and \(400 + 24{,}600 = 25{,}000\) \(\checkmark\)
Grading: 1 Pt. complements, 2 Pts. tree diagram with branch and path probabilities, 3 Pts. inner cells, 1 Pt. sums with the check.
Part b)
Compute the probability that a delivery with a positive test result does indeed contain antibiotic residues. Interpret the result for the dairy and the farms.
(for verification: 876 of the 25,000 deliveries test positive) [3 pts.]
Bayes’ theorem (the base is all positive results, row sum 876):
\[P(R \mid +) = \frac{P(+ \mid R) \cdot P(R)}{P(+ \mid R) \cdot P(R) + P(+ \mid \bar{R}) \cdot P(\bar{R})} = \frac{0.01536}{0.01536 + 0.01968} = \frac{384}{876} = \frac{32}{73} \approx 0.4384\]
Interpretation: only about 44 % of the positive deliveries really contain residues. More than half of the positive results are false alarms, because deliveries with residues are rare and 2 % of the many clean deliveries also test positive. The dairy should not blame a farm (or refuse to pay for its milk) because of one positive rapid test, but should first confirm the result, e.g. with a lab test.
Grading: 1 Pt. Bayes’ theorem with the correct base, 1 Pt. \(P(R \mid +) \approx 0.4384\), 1 Pt. interpretation.
Part c)
Compute the probability that a delivery contains antibiotic residues but is incorrectly identified as free of residues. [2 pts.]
“Contains residues and tests negative” is one path of the tree, a joint probability with all deliveries as the base:
\[P(R \cap -) = P(R) \cdot P(- \mid R) = 0.016 \cdot 0.04 = 0.00064 = \frac{16}{25000}\]
So 0.064 % of all deliveries, about 16 per year, contain residues and still get into the dairy’s tanks.
Grading: 1 Pt. joint probability along the path \(R \to -\), 1 Pt. \(0.00064\).
Part d)
Compute the negative predictive value, i.e. the probability that a delivery with a negative test result is really free of residues. Explain what this value means for the dairy. [3 pts.]
The base is all negative results (row sum 24,124):
\[P(\bar{R} \mid -) = \frac{P(- \mid \bar{R}) \cdot P(\bar{R})}{P(-)} = \frac{0.96432}{0.96432 + 0.00064} = \frac{24108}{24124} = \frac{6027}{6031} \approx 0.9993\]
Meaning: a negative result is very reliable. 99.93 % of the deliveries with a negative test are really free of residues, only about 7 of 10,000 negative deliveries contain residues. So the dairy can pump the milk of a negative delivery into its tanks without a further test.
Grading: 1 Pt. base \(P(-)\) or row sum 24,124, 1 Pt. \(0.9993\), 1 Pt. meaning.
Part e)
In winter, more cows are treated with antibiotics, so the share of deliveries with residues changes. Let \(p\) with \(0 < p < 1\) be the base rate. The sensitivity and the specificity of the test stay the same. Show that the probability from part b) is then
\[f(p) = \frac{48p}{47p + 1}.\] [3 pts.]
Bayes’ theorem with base rate \(p\): the path \(R \to +\) has the probability \(0.96p\), the path \(\bar{R} \to +\) the probability \(0.02(1 - p)\):
\[f(p) = \frac{0.96p}{0.96p + 0.02(1 - p)} = \frac{0.96p}{0.96p + 0.02 - 0.02p} = \frac{0.96p}{0.94p + 0.02}\]
Multiply the numerator and the denominator by 50:
\[f(p) = \frac{48p}{47p + 1} \;\checkmark\]
Check with the base rate from part b): \(f(0.016) = \frac{0.768}{0.752 + 1} = \frac{0.768}{1.752} = \frac{32}{73}\) \(\checkmark\)
Grading: 1 Pt. Bayes’ theorem with \(p\) and \(1 - p\) in the paths, 1 Pt. denominator \(0.94p + 0.02\), 1 Pt. given form (factor 50).
Part f)
Show with the derivative that \(f\) is increasing for \(0 < p < 1\). In winter, 4 % of the deliveries contain residues. Compute \(f(0.04)\) and explain what the results of this part mean for the dairy. [4 pts.]
Quotient rule with \(u = 48p\), \(u' = 48\), \(v = 47p + 1\), \(v' = 47\):
\[f'(p) = \frac{u' \cdot v - u \cdot v'}{v^2} = \frac{48(47p + 1) - 48p \cdot 47}{(47p + 1)^2} = \frac{2256p + 48 - 2256p}{(47p + 1)^2} = \frac{48}{(47p + 1)^2}\]
Increasing: the numerator \(48\) is positive, and the denominator is a square of \(47p + 1 > 0\), so it is positive too. Hence \(f'(p) > 0\) for all \(0 < p < 1\), and \(f\) is increasing.
Winter:
\[f(0.04) = \frac{48 \cdot 0.04}{47 \cdot 0.04 + 1} = \frac{1.92}{2.88} = \frac{2}{3} \approx 0.6667\]
Meaning: the more deliveries contain residues, the more reliable a positive result is. In winter, 2 of 3 positive deliveries really contain residues, in summer only about 44 %. Because \(f\) is increasing, this holds for every base rate above 1.6 %, not only for 4 %. A second test before the dairy acts on a positive result is most urgent in summer, when residues are rare.
Grading: 2 Pts. \(f'(p)\) with the quotient rule, 1 Pt. \(f'(p) > 0 \Rightarrow f\) increasing, 1 Pt. \(f(0.04) \approx 0.6667\) with the meaning.