A nondestructive test for detecting weld defects correctly identifies a true defect 95% of the time (true positive rate) and incorrectly flags a defect-free weld 3% of the time (false positive rate). In a population of welds, 2% actually contain a defect. If a randomly selected weld tests positive, what is the probability it actually has a defect?
Show the solution
This requires Bayes' theorem: P(Defect|Positive) = P(Positive|Defect)P(Defect) / P(Positive). First find P(Positive) using the law of total probability: P(Positive) = P(Pos|Defect)P(Defect) + P(Pos|No Defect)P(No Defect). P(Positive) = 0.95(0.02) + 0.03(0.98) = 0.019 + 0.0294 = 0.0484. P(Defect|Positive) = 0.95(0.02)/0.0484 = 0.019/0.0484 = 0.3926. Sanity check: this result (only 39% chance of an actual defect, even after a positive test from a 95%-accurate test) is the well-known "base rate" effect — because defects are rare (2%) to begin with, the much larger pool of defect-free welds still produces more false positives (0.0294) in absolute terms than the true positives from the rare defective ones (0.019), pulling the final probability below 50% even though the test itself seems quite accurate.