A115 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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 13. 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?

Name it

Bayes' rule

Write the multiplication rule both ways, P(A∩B)=P(B)P(A∣B)=P(A)P(B∣A), and solve:

P(B∣A)=P(A∣B)P(B)P(A)

The denominator comes from total probability. With B and its complement:

P(B∣A)=P(A∣B)P(B)P(A∣B)P(B)+P(A∣Bc)P(Bc)

The names:

TermMeaningBoard tester
P(B)prior: belief before the evidence1% of boards are bad
P(A∣B)likelihood: how well B explains the evidence99% of bad boards are flagged
P(B∣A)posterior: belief after the evidence13 of flagged boards are bad

The odds form

The odds of B are P(B)P(Bc). Bayes' rule in odds is one multiplication:

posterior odds=P(A∣B)P(A∣Bc)×prior odds

The ratio in the middle, the likelihood ratio, measures how strongly the evidence points to B. For the tester it's 0.990.02=49.5; prior odds of 1 to 99 become 49.5 to 99, or 1 to 2, a probability of 13.

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 49.5299=24.75, 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
  1. Chance of reading a 1. P(read 1)=0.3×0.9+0.7×0.05=0.27+0.035=0.305
  2. Bayes's rule. P(sent 1∣read 1)=0.270.305=0.885
  3. 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
  1. Odds per positive. Each positive multiplies the odds by 0.990.02=49.5
  2. Two positives. Starting from odds of 199: 49.5299=24.75
  3. Back to a probability. P=24.7525.75=0.961

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
  1. Bayes's rule. P(B∣bad)=P(bad∣B)P(B)P(bad)=0.03×0.40.018=0.0120.018=0.667
  2. 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 P(faulty∣flag) 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 p of boards) with probability s and false-alarms on good boards with probability f.

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°.

Explain why

Why is the posterior so low when a reliable test flags a rare fault?

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.