A11 · Lesson 5 · Bayes' rule
Reasoning backward from what you observed
A board tester catches 99% of bad boards and wrongly flags only 2% of good ones. One percent of boards are bad. The tester flags a board: what's the chance it's really bad? Most people say about 99%. The answer is one in three. Bayes' rule is the calculation that gets it right, and it's how every receiver decides which symbol was sent, every spam filter scores a message, and every fault detector weighs an alarm.
- The curve is the chance that a flagged board is really bad, for each possible share of bad boards (the horizontal axis, on a log scale).
- Start with 1% bad boards: about . Make the defects rarer and watch the answer collapse.
- Which helps more when defects are rare: catching more of them (sensitivity) or flagging fewer good boards (false alarms)?
Predict
With 1% of boards bad, 99% detection and 2% false alarms, what fraction of flagged boards are bad?
About 33%. Out of 10,000 boards, 100 are bad and the tester flags 99 of them. Of the 9,900 good boards it flags 2%, which is 198. So 297 boards are flagged and only 99 of those are bad: one in three. When the thing you're looking for is rare, false alarms from the large majority swamp the true detections.
Name it
Bayes' rule
Write the multiplication rule both ways, , and solve:
The denominator comes from total probability. With and its complement:
The names:
| Term | Meaning | Board tester |
|---|---|---|
| prior: belief before the evidence | 1% of boards are bad | |
| likelihood: how well explains the evidence | 99% of bad boards are flagged | |
| posterior: belief after the evidence | of flagged boards are bad |
The odds form
The odds of are . Bayes' rule in odds is one multiplication:
The ratio in the middle, the likelihood ratio, measures how strongly the evidence points to . For the tester it's ; prior odds of 1 to 99 become 49.5 to 99, or 1 to 2, a probability of .
Repeated evidence
If two tests are independent given the board's true state, apply the rule twice: each positive result multiplies the odds by 49.5. Two positives give odds of , a probability of 0.96. Retesting flagged boards is how real production lines cope with low base rates.
Receivers
A receiver sees a noisy symbol and must guess what was sent. The priors are how often each symbol is sent, the likelihoods come from the channel's error rates, and the best guess is the symbol with the largest posterior (lesson 42 develops this).
Worked example
A binary channel sends 1 with probability 0.3. A sent 1 is read as 1 with probability 0.9; a sent 0 is read as 1 with probability 0.05. A 1 is received. What is the chance a 1 was sent?
Show the solution
- Chance of reading a 1.
- Bayes's rule.
- Why it's below 0.9. Even though the channel reads a 1 correctly 90% of the time, the rarity of sent 1s pulls the posterior down a little, and the 0s misread as 1s account for the rest.
Answer given a received 1, the chance a 1 was sent is 0.885.
Worked example
A flagged board is retested on an independent tester with the same rates and flagged again. What is the chance now that it's bad?
Show the solution
- Odds per positive. Each positive multiplies the odds by
- Two positives. Starting from odds of :
- Back to a probability.
Answer after two flags, the board is bad with chance 0.961.
Worked example
Using the suppliers above, a part is found defective. What is the chance it came from B?
Show the solution
- Bayes's rule.
- What it means. B supplies 40% of the parts but two thirds of the defects. Bayes's rule weighs each supplier's share by how strongly a defect points to it.
Answer a defective part came from B with chance 0.667, two thirds.
Check
A fraction 0.01 of parts are faulty. A test flags faulty parts with probability 0.95 and good parts with probability 0.05. Given a flag, what is the chance the part is faulty?
Check
Same test: faulty fraction 0.01, detection 0.95, false alarms 0.05. What fraction of all parts gets flagged?
Check
A link sends 1 with probability 0.3. A sent 1 is misread as 0 with probability 0.1; a sent 0 is misread as 1 with probability 0.03. A 1 is received. What is the chance a 1 was sent?
Check
An event has prior probability 0.01. Evidence arrives with likelihood ratio 50. What is the posterior probability?
Check
Two independent tests, each with detection 0.99 and false alarm rate 0.05, both flag a part. A fraction 0.01 of parts are faulty. What is the chance this one is faulty?
Check
Faults are rare (0.1%). Which change raises the most?
Check
A fraction 0.6 of parts come from A (defect rate 0.01), the rest from B (defect rate 0.05). A part is defective.
(a)
What is the chance it came from B?
Check
A test detects a fault (present in a fraction of boards) with probability and false-alarms on good boards with probability .
Step 1
What fraction of boards are flagged?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
What fraction of flagged boards are really faulty?
Explain why
Why is the posterior so low when a reliable test flags a rare fault?
The posterior compares two ways of getting a flag: a faulty part being caught, and a good part being falsely flagged. Even a small false alarm rate applies to the vast number of good parts, so it can produce many more flags than the few faulty parts do. The flag then most likely came from a good part. The prior sets how big each pool is; the likelihoods set what fraction of each pool raises a flag.
Practice
Keep practicing
9 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.