Discord

INAIO Guide Stage 1 8Probability

8.4 Total probability and Bayes

Split an event into cases with total probability, then reverse the condition using Bayes' theorem.

In Module 8.3, we asked: among the flagged items, how many are faulty? The table already told us how many items were flagged, so we could divide directly. Often a question gives different information: how common faults are, how often a faulty item is flagged, and how often a sound item is falsely flagged. It does not tell us the total number of flags. We must find that total before we can ask the same “among the flagged” question.

That is the purpose of total probability and Bayes' theorem. First account for every way a flag can occur. Then use the flagged group as the new denominator and ask what share came from the cause we care about. The direction reverses: a flag rate given a faulty item helps us find the fault rate given a flag.

This is intermediate probability. Review conditional probability first; Penn State's STAT 414 Bayes lesson develops the same two-step calculation.

A basic idea: find the flagged group, then look inside it

Imagine 10,00010{,}000 items. Only 1%1\% are faulty, so 100100 are faulty and 9,9009{,}900 are sound. A sensor flags 90%90\% of the faulty items and 5%5\% of the sound ones. We can now build the missing flagged group:

  1. Of the 100100 faulty items, 100(0.90)=90100(0.90)=90 are flagged. These are true positives.
  2. Of the 9,9009{,}900 sound items, 9,900(0.05)=4959{,}900(0.05)=495 are flagged. These are false positives.
  3. There are 90+495=58590+495=585 flagged items altogether. Among those 585, only 9090 are faulty, so the chance of a fault given a flag is 90/585=2/13≈15.4%90/585=2/13\approx15.4\%.

This is the same conditional-probability question as in Module 8.3; we just had to construct its denominator first. The 90%90\% detection rate describes flags among faulty items. The 15.4%15.4\% answer describes faults among flagged items. The result is much smaller because sound items are far more common, so even a 5%5\% false-flag rate produces many flags.

The starting 1%1\% fault rate is called a prior: what we knew before seeing the sensor result. The 15.4%15.4\% fault chance after seeing a flag is the posterior. Use Next in the animation to follow the two source groups into one flagged pool, then measure the faulty share of that pool.

Follow two routes to a positive flag, combine them into the flagged pool, then measure the faulty share of that pool.

A quick tour of formulas

Let FF mean “faulty” and ++ mean “flagged.” From Module 8.3, the reversed question is P(F∣+)=P(F∩+)/P(+)P(F\mid +)=P(F\cap +)/P(+). We know neither count directly, but the multiplication rule from Module 8.2 gives P(F∩+)=P(F)P(+∣F)P(F\cap +)=P(F)P(+\mid F). To find the denominator, total probability adds the two separate ways to get a flag:

P(+)=P(F)P(+∣F)+P(Fc)P(+∣Fc).P(+)=P(F)P(+\mid F)+P(F^c)P(+\mid F^c).

Substituting these pieces gives Bayes' theorem: the faulty-and-flagged route is the numerator, and all flagged routes form the denominator.

P(F∣+)=P(F)P(+∣F)P(F)P(+∣F)+P(Fc)P(+∣Fc).P(F\mid +)= \frac{P(F)P(+\mid F)} {P(F)P(+\mid F)+P(F^c)P(+\mid F^c)}.

More generally, suppose B1,…,BmB_1,\ldots,B_m are non-overlapping cases that cover every possibility. Such cases form a partition. For an observed event AA with P(A)>0P(A)>0, the same two steps are

P(A)=∑i=1mP(Bi)P(A∣Bi),P(Bk∣A)=P(Bk)P(A∣Bk)∑iP(Bi)P(A∣Bi).P(A)=\sum_{i=1}^{m}P(B_i)P(A\mid B_i), \qquad P(B_k\mid A)= \frac{P(B_k)P(A\mid B_k)} {\sum_i P(B_i)P(A\mid B_i)}.

Check that the cases cover every possibility without overlap. If the denominator P(A)P(A) is zero, the conditional probability is undefined. The detection rate P(+∣F)P(+\mid F) asks about flags among faulty items; the posterior P(F∣+)P(F\mid +) asks about faults among flagged items.

Application 1: a rare-condition sensor

One in 100 items is faulty. A sensor flags 90% of faulty items and 5% of sound items. What fraction of flagged items are actually faulty? (Compare Module 8.3.)

  1. P(F)=0.01P(F)=0.01, P(+∣F)=0.90P(+\mid F)=0.90, and P(+∣Fc)=0.05P(+\mid F^c)=0.05.
  2. Total probability gives P(+)=0.01(0.90)+0.99(0.05)=0.0585P(+)=0.01(0.90)+0.99(0.05)=0.0585.
  3. Bayes gives P(F∣+)=0.009/0.0585=2/13≈15.4%P(F\mid +)=0.009/0.0585=2/13\approx15.4\%.

The 90% detection rate is not the answer. The low fault rate produces many more sound items that can be falsely flagged.

As a count check, among 10,00010{,}000 items the animation finds 9090 flagged faulty items and 495495 flagged sound items. Thus 90/(90+495)=90/585=2/1390/(90+495)=90/585=2/13, the same posterior.

Application 2: two factories

Factory A supplies 60% of lamps and has a 2% defect rate. Factory B supplies 40% and has a 5% defect rate. A lamp is defective. What is the chance it came from B?

  1. P(D)=0.60(0.02)+0.40(0.05)=0.032P(D)=0.60(0.02)+0.40(0.05)=0.032.
  2. The B-and-defective route is 0.40(0.05)=0.0200.40(0.05)=0.020.
  3. P(B∣D)=0.020/0.032=0.625P(B\mid D)=0.020/0.032=0.625.

Although B supplies fewer lamps, it accounts for 62.5% of defective lamps in this model.

Resources

SourceTitleWhy read it
Penn State STAT 414Bayes' TheoremLearn partitions, total probability, and posterior probabilities.

Finished this module? Mark it done.

Comments

Stuck on something, spotted a mistake, or found a resource that helped you? Tell us below.

Loading comments