Discrete MathematicsProbability, Conditioning and Expectation5 of 9
Probability, Conditioning and Expectation · 5
Bayes' Theorem
When we see a test result or a piece of evidence, we often need to work backward from that evidence to find the probability of the hidden cause that produced it.
1
Going Backward from Evidence to Cause
Given the evidence we observe, we want to find the probability of the underlying cause. From conditional probability, conditioning on an event B means erasing everything outside B and taking the ratio of the overlap to what is left, using the multiplication rule to find the overlap:
P(A∣B)P(A and B)=P(B)P(A and B),=P(A)⋅P(B∣A)
Suppose 1% of a population has a silent virus and 99% are healthy. A lab test catches the virus 90% of the time in sick people, but also gives a false alarm 10% of the time in healthy people. If you test positive, what is the probability that you actually have the virus?
Going Backward from Evidence to Cause
Text solution
Split 1,000 people by causeBefore anyone takes the test, divide a square of 1,000 people into a sick column (1%) and a healthy column (99%).
SickHealthy=1,000×0.01=10,=1,000×0.99=990
Shade the positive tests in each columnTake 90% of the sick group for the true positives and 10% of the healthy group for the false alarms.
Sick andPositiveHealthy and Positive=10×0.90=9,=990×0.10=99
Divide true positives by all positivesThrow away everyone who tested negative, and find the fraction of the remaining positive results that came from the sick column.
P(Sick∣Positive)=9+999=1089=121≈8.3%
So a positive result only gives an 8.3% chance of having the virus, because the massive healthy column produces eleven times as many positive tests as the tiny sick column.
When the sick column is very thin, the short, wide false-alarm strip in the healthy column has much more area than the tall, skinny true-positive strip; the true positives only overtake the false alarms once the sick column starts out wide enough.
Even with the same test, the chance that a person who tests positive is actually sick depends on how common the sickness is to begin with.
2
Bayes' Formula: Long and Short Forms
Instead of imagining 1,000 people every time, we want to compute this backward probability directly from decimals, whether a problem gives us separate rates inside each group or the overall rate of the evidence across everyone.
Suppose 20% of all emails in your inbox are spam, 15% of spam emails contain the word "Winner", and 5% of all emails overall contain the word "Winner". If a new email contains the word "Winner", what is the probability that it is spam?
Bayes' Formula: Long and Short Forms
Writing H for the hypothesis (the cause) and E for the evidence gives both forms of Bayes' Theorem. The long form adds the shaded boxes from each column in the denominator, while the short form writes their sum as a single number P(E):
P(H∣E)=Left shaded boxP(H)⋅P(E∣H)+Right shaded boxP(¬H)⋅P(E∣¬H)P(H)Prior (width)⋅P(E∣H)Likelihood (height)=Total probability of EP(E)P(H)⋅P(E∣H)
Text solution
Find the spam emails with "Winner"Multiply the starting share of spam (width) by the rate of "Winner" inside spam (height).
P(Spam and Winner)=P(Spam)⋅P(Winner∣Spam)=0.20×0.15=0.03
Divide by all emails with "Winner"Because the problem already gives the total shaded area P(Winner)=0.05 across the whole inbox, divide by it directly with the short form.
P(Spam∣Winner)=0.050.03=0.60=60%
So 60% of the emails containing the word "Winner" are spam.
3
Three or More Causes
Now suppose the evidence can come from three or more mutually exclusive causes that partition the sample space, and we want the probability that one specific cause produced it.
A company makes microchips at three factories: Factory A makes 50% of the chips (with a 2% defect rate), Factory B makes 30% (with a 4% defect rate), and Factory C makes 20% (with a 5% defect rate). If a randomly selected chip is defective, what is the probability that it came from Factory C?
Three or More Causes
Text solution
Find the defective share from each factoryMultiply each factory's share of total production (width) by its defect rate (height).
P(A and Defective)=0.50×0.02=0.010P(B and Defective)=0.30×0.04=0.012P(C and Defective)=0.20×0.05=0.010
Divide Factory C's defective share by all defective chipsPut Piece C on top and the sum of all three defective pieces on the bottom.
Even though Factory C has the highest defect rate, it only accounts for 31.25% of all defective chips because it makes the smallest share of the company's chips. Multiplying the decimals by 1,000 to think in whole chips (10,12, and 10) is a great way to avoid decimal-place slips; just write the probability steps alongside it.
4
Repeated Evidence and Bayesian Updating
When a second or third piece of evidence comes in on the same case, we want to find the updated probability of the cause without starting over from scratch.
In our virus test from earlier (1% of people are sick, 90% true-positive rate, 10% false-alarm rate), a single positive test left 9 sick people and 99 healthy people out of 1,000, or an 8.3% chance of being sick. If the same person takes the test a second time and tests positive again, with the two results independent within the sick group and within the healthy group, what is the probability that they are sick?
Repeated Evidence and Bayesian Updating
Text solution
Use the people who tested positive the first time as the new priorStart with the 9 sick and 99 healthy people who tested positive the first time, since everyone who tested negative is already ruled out.
Shade the second positive test inside each groupBecause the tests are independent within each group, multiply the remaining sick group by 0.90 and the remaining healthy group by 0.10.
Sick with2 PositivesHealthy with 2 Positives=9×0.90=8.1,=99×0.10=9.9
Divide the remaining sick group by everyone with two positivesTake the ratio of the twice-shaded pieces, which is the same as squaring each test rate from the original 1,000 people.
So a second positive test raises the probability of having the virus from 8.3% to 45%, and a third positive test pushes it to 8.1×0.90+9.9×0.108.1×0.90≈88%.
Across the three repeated tests below, the shaded pieces from each test expand to become the starting columns for the next test; when the false-alarm rate is small, each positive result cuts away most of the remaining healthy column so the sick column rapidly dominates.
Each positive test's shaded pieces become the next test's starting columns, so a low false-alarm rate quickly clears out the Healthy column across repeated tests.
Key concepts
Before reaching for Bayes' Theorem, check the direction of the question. If a problem gives you the cause and asks for the evidence, such as "if a person is sick, what is the chance they test positive?", that is a forward probability P(E∣H)=0.90 that you read directly from the problem. You only use Bayes' Theorem when the problem hands you the evidence E and asks you to go backward to the cause H.
Once you know you are going backward, check how the denominator is given:
Overall rate of evidence P(E) given (Short form)
When the problem states the rate of the evidence across the entire population at once, divide the overlap by P(E) directly without building other columns:
P(H∣E)=P(E)P(H)⋅P(E∣H)(Spam given Winner: 0.050.20×0.15=60%)
Separate rates given for each group (Long form)
When the problem splits the sample space into mutually exclusive causes (H1,H2,…) and gives a separate rate inside each one, multiply Width×Height in every column and divide the piece you want by the sum of all shaded pieces:
P(H1∣E)=P(H1)⋅P(E∣H1)+P(H2)⋅P(E∣H2)+⋯P(H1)⋅P(E∣H1)(Sick given Positive: 0.01×0.90+0.99×0.100.01×0.90=121)
Repeated evidence (Bayesian updating)
When multiple trials or tests happen in a row, the updated probability from the first test becomes the starting prior for the next test. Multiply the new likelihood inside each group rather than multiplying overall probabilities outside the columns:
At an airport, 15% of all flights are delayed, 4% of all flights are international, and 30% of international flights are delayed. If a randomly chosen flight is delayed, what is the probability that it is an international flight?
Watch out: don't treat 0.15 as the delay rate for domestic flights and build a second column 0.012+0.96×0.15=0.156, which gives the wrong answer 131≈7.7%.
Look at the 15% delay rate: is that for one group of flights, or across the entire airport?
Find the share of flights that are both international and delayed:
P(International and Delayed)=P(International)⋅P(Delayed∣International)=0.04×0.30=0.012
Because 15% is already the overall delay rate P(Delayed)=0.15 across all flights, divide by 0.15 directly using the short form. (Watch out: don't treat 0.15 as the delay rate for domestic flights and build a second column 0.012+0.96×0.15=0.156, which gives the wrong answer 131≈7.7%.)
A company gives a lie detector test to job applicants, 5% of whom are lying about their background. If an applicant is lying, the test flags them 80% of the time. If an applicant is telling the truth, the test gives a false alarm 10% of the time. If an applicant is flagged by the test, what is the probability that they are actually lying?
Watch out: ignoring the 5% and 95% base-rate widths and just dividing the test heights 0.80+0.100.80 gives the wrong answer 98≈88.9%.
Split the applicants into two columns, Lying (5%) and Truthful (95%), and find the flagged share inside each column.
Multiply width times height in each column to find the true positives and the false alarms:
P(Lying and Flagged)=0.05×0.80=0.040,P(Truthful and Flagged)=0.95×0.10=0.095
Divide the lying-and-flagged piece by the sum of both flagged pieces. (Watch out: ignoring the 5% and 95% base-rate widths and just dividing the test heights 0.80+0.100.80 gives the wrong answer 98≈88.9%.)
In a storage bin, 10% of the batteries are weak and 90% are good. A voltage tester catches and rejects a weak battery 95% of the time, but also falsely rejects 5% of good batteries. If a battery passes the test, what is the probability that it is actually weak?
Watch out: plugging the rejection rates 0.95 and 0.05 straight in finds P(Weak∣Rejected) instead of P(Weak∣Pass), giving the wrong answer 2819≈67.9%.
Look carefully at the evidence we saw: the battery passed the test, so what height should you shade in each column instead of the rejection rates?
Subtract each rejection rate from 1 to get the pass rate inside each group: P(Pass∣Weak)=1−0.95=0.05 and P(Pass∣Good)=1−0.05=0.95. (Watch out: plugging the rejection rates 0.95 and 0.05 straight in finds P(Weak∣Rejected) instead of P(Weak∣Pass), giving the wrong answer 2819≈67.9%.)
P(Weak and Pass)=0.10×0.05=0.005,P(Good and Pass)=0.90×0.95=0.855
Divide the weak batteries that pass by all batteries that pass:
An online store ships orders using three couriers: FastShip handles 50% of orders, QuickPost handles 30%, and ValueMail handles 20%. Packages arrive late 2% of the time with FastShip, 5% of the time with QuickPost, and 10% of the time with ValueMail. If an order arrives late, what is the probability it was shipped via ValueMail?
Watch out: make sure ValueMail's 0.020 is on top rather than the first courier listed, and include all three couriers in the denominator. Dividing by only the other two couriers 0.010+0.015=0.025 gives the wrong answer 54=80%.
Set up three columns for the three couriers and find the share of late orders coming from each one.
Multiply each courier's share of orders by its late rate:
P(FastShip and Late)=0.50×0.02=0.010P(QuickPost and Late)=0.30×0.05=0.015P(ValueMail and Late)=0.20×0.10=0.020
Put ValueMail's piece on top and the sum of all three pieces on the bottom. (Watch out: make sure ValueMail's 0.020 is on top rather than the first courier listed, and include all three couriers in the denominator. Dividing by only the other two couriers 0.010+0.015=0.025 gives the wrong answer 54=80%.)
A bag contains 9 fair coins and 1 double-headed coin (which lands on Heads every time). You reach in, pull out one coin at random, and flip it 4 times, getting Heads all 4 times. What is the probability that you pulled out the double-headed coin?
Watch out: forgetting to raise 21 to the 4th power treats the evidence as a single flip and gives the wrong answer 112≈18.2%.
Once you pick a coin, the 4 flips are independent. What is the probability of getting 4 Heads in a row inside the double-headed column versus inside the fair-coin column?
The prior widths are P(Double-headed)=101 and P(Fair)=109. Inside each column, raise the single-flip Heads probability to the 4th power: 14=1 for the double-headed coin and (21)4=161 for a fair coin. (Watch out: forgetting to raise 21 to the 4th power treats the evidence as a single flip and gives the wrong answer 112≈18.2%, while raising the entire product (109×21)4 to the 4th power acts as if you drew a new coin on every flip.)
P(Double-headed and 4 Heads)=101×14=101,P(Fair and 4 Heads)=109×(21)4=1609
Divide the double-headed piece by the total probability of getting 4 Heads:
A rare condition affects 1% of a population. An initial screening test catches the condition 90% of the time and has a 10% false-alarm rate. Anyone who tests positive on the screening test takes an independent follow-up test that catches the condition 80% of the time and has a 4% false-alarm rate. If a person tests positive on both tests, what is the probability that they actually have the condition?
Watch out: don't go back to the original 10 and 990 people for the second test without keeping the first test's rates, which ignores the screening test and gives the wrong answer 11920≈16.8%.
Start from the 9 sick and 99 healthy people out of 1,000 who test positive on the first screening test, and apply the follow-up test's rates to those two groups.
Out of 1,000 people, the first screening test leaves 10×0.90=9 people with the condition and 990×0.10=99 healthy people. Use these two groups as the prior for the follow-up test, multiplying by 0.80 and 0.04. (Watch out: don't go back to the original 10 and 990 people for the second test without keeping the first test's rates, which ignores the screening test and gives the wrong answer 11920≈16.8%.)
Condition andBoth PositiveHealthy and Both Positive=9×0.80=7.2,=99×0.04=3.96
Divide the remaining people with the condition by everyone who tested positive on both tests: