STAT 200 · Statistics for Economics
Conditional Probability and Bayes' Rule
Learn how new evidence changes the odds, why rare events fool good tests, and how to update a probability with Bayes' rule.
Key takeaways
- A conditional probability is the chance of one event given that you already know another event happened.
- The probability of A given B is usually very different from the probability of B given A, so the order matters.
- Two events are independent when learning that one happened does not change the chance of the other.
- Bayes' rule starts with a base rate and updates it with evidence to give a new, better probability.
- When the thing you are looking for is rare, even a fairly accurate test produces many false alarms.
Picture Priya, who sells hand-printed posters online. Her payment software has a fraud alarm. The company that makes it says the alarm catches 90% of fraudulent orders. This morning it went off on a $240 order from a new customer.
Priya's first thought is that the order is 90% likely to be fake. She hovers over the cancel button. Should she press it?
In her shop, the right answer is that the order is only about 15% likely to be fraudulent. Most flagged orders are perfectly honest people who wanted posters. By the end of this lesson you will be able to get that number yourself, and you will see why so many smart people guess wrong.
"Given that" changes the question
In the lesson on probability basics, you met probability as a number from 0 to 1 that measures how likely an event is. A conditional probability is the probability of an event when you already know something else is true. We write it P(A | B) and read it "the probability of A given B." The vertical bar means "given."
The trick is simple. Knowing B throws away every case where B did not happen. You then ask how often A shows up among the cases that remain. Your world has shrunk.
Suppose Priya looks at her last 200 orders. She sorts them two ways: phone or computer, and whether the buyer added express shipping.
| Express | Standard | Total | |
|---|---|---|---|
| Phone | 30 | 90 | 120 |
| Computer | 10 | 70 | 80 |
| Total | 40 | 160 | 200 |
What is the chance a random order used express shipping? That is 40 out of 200, or 0.20.
Now suppose you know the order came from a phone. Ignore the computer row entirely. Among 120 phone orders, 30 used express, so P(Express | Phone) = 30 ÷ 120 = 0.25. Knowing about the phone raised the chance from 20% to 25%.
The general formula says the same thing with symbols:
P(A | B) = P(A and B) ÷ P(B)
P(Express | Phone) = (30/200) ÷ (120/200) = 0.15 ÷ 0.60 = 0.25 Conditioning on the device shrinks the group you are counting inside. Hypothetical example: the numbers are made up to show the method, not a quote or an average.
The order of the words matters
Flip the question. Among express orders, what share came from phones? Now you stay inside the express column: 30 out of 40, or 0.75.
So P(Express | Phone) is 25%, while P(Phone | Express) is 75%. Both numbers use the same 30 orders on top. They divide by different groups on the bottom.
Here is an everyday version. Almost every professional basketball player is taller than average. But almost no taller-than-average person is a professional basketball player. Anyone who swaps those two sentences will have a strange talk with a tall dentist.
The formula can also be turned around to find the chance that two things both happen. Multiply the chance of the first by the chance of the second given the first:
P(A and B) = P(B) × P(A | B)
P(Phone and Express) = 0.60 × 0.25 = 0.15 That is 15% of all orders, which matches 30 out of 200.
Independence: when news changes nothing
Two events are independent if knowing one happened leaves the chance of the other unchanged. In symbols, P(A | B) = P(A). For independent events, the multiplication rule gets shorter: P(A and B) = P(A) × P(B).
In Priya's table, express shipping and phone ordering are not independent, because 25% differs from 20%. If phone buyers had chosen express exactly 20% of the time, there would have been 24 such orders, and the device would tell you nothing about shipping.
Be careful before assuming independence. Suppose a lender thinks each of two borrowers has a 5% chance of missing payments. If their troubles were independent, the chance both miss would be 0.05 × 0.05 = 0.0025. But if both work at the same factory and it closes, they may struggle together. The real chance of a double miss could be far higher. Shared causes link events.
Dependence also does not tell you what causes what. Phone buyers may pick express more often because of their age, their hurry, or the layout of the checkout page. Correlation and its limits raise the same warning for numbers.
The alarm problem, solved by counting
Back to the fraud alarm. Priya needs three facts. These are made-up rates for her invented shop:
- 1% of orders are fraudulent. This starting share is called the base rate.
- If an order is fraudulent, the alarm sounds 90% of the time.
- If an order is honest, the alarm still sounds 5% of the time. This is a false positive, an alarm with nothing behind it.
The friendliest method is to imagine a big, round number of orders and count. Take 10,000.
- Fraudulent orders: 1% of 10,000 = 100.
- Honest orders: 10,000 − 100 = 9,900.
- Fraud that gets flagged: 90% of 100 = 90.
- Honest orders that get flagged: 5% of 9,900 = 495.
- All flagged orders: 90 + 495 = 585.
- Share of flagged orders that are fraud: 90 ÷ 585 ≈ 0.154.
Of 585 flagged orders, only 90 are fraud: about 15.4%.
The alarm is useful. It moved the chance of fraud from 1% to about 15%, more than fifteen times higher. But 15% is not 90%. The reason is that honest orders vastly outnumber fraudulent ones. A small slice of a huge group (495) swamps a large slice of a tiny group (90).
A sensible Priya does not cancel automatically. She might send a quick confirmation email. A check that costs two minutes fits a 15% worry.
Bayes' rule: the same count, written once
Bayes' rule is a formula for reversing a conditional probability. You know P(evidence | cause) and want P(cause | evidence). It is named for Thomas Bayes, an English minister and mathematician of the 1700s.
The bottom of the fraction counts every route to an alarm: fraud that trips it, plus honest orders that trip it.
P(A) = P(A | F) × P(F) + P(A | not F) × P(not F)
= 0.90 × 0.01 + 0.05 × 0.99
= 0.009 + 0.0495
= 0.0585
P(F | A) = (0.90 × 0.01) ÷ 0.0585
= 0.009 ÷ 0.0585
≈ 0.154 Notice that 0.0585 of 10,000 orders is 585 alarms, exactly what you counted. Bayes' rule is just the tree written in one line.
The prior is your probability before the new evidence. The posterior is your probability after it. Learning means moving from one to the other by an amount that depends on how strong the evidence is.
A second clue: updating again
Priya now checks something else. The billing address does not match the card's records. Suppose that mismatch happens in 80% of fraudulent orders and 10% of honest ones. Also suppose it works independently of the alarm among fraudulent orders and among honest orders.
Yesterday's posterior becomes today's prior. Of the 585 flagged orders, 90 were fraud and 495 were honest.
Fraud with mismatch: 90 × 0.80 = 72
Honest with mismatch: 495 × 0.10 = 49.5
P(fraud | alarm and mismatch) = 72 ÷ (72 + 49.5)
= 72 ÷ 121.5
≈ 0.593 (The 49.5 is an average across many such batches, so half an order is fine.)
Yesterday's posterior becomes today's prior.
At 59%, holding the order until the buyer confirms looks reasonable. Be careful with the independence assumption, though. If the alarm already looked at the address, counting the mismatch again would be counting one clue twice.
Same alarm, different shop
Here is something that surprises people. The alarm's two rates can stay exactly the same while the meaning of a flag changes a lot.
Imagine Priya's cousin Arun, who sells resellable gift cards. Thieves love gift cards, so suppose 10% of his orders are fraudulent. He uses the same software: it catches 90% of fraud and flags 5% of honest orders.
Out of 10,000 orders, 1,000 are fraud and 900 of them get flagged. The other 9,000 are honest, and 450 of them get flagged. So a flagged order is fraud with probability 900 ÷ 1,350, or about 67%.
| Priya | Arun | |
|---|---|---|
| Base rate of fraud | 1% | 10% |
| True alarms per 10,000 orders | 90 | 900 |
| False alarms per 10,000 orders | 495 | 450 |
| Chance a flag is real | about 15% | about 67% |
One alarm, two very different decisions. Arun might reasonably hold every flagged order, while Priya would annoy many good customers by doing that. When you borrow an accuracy claim from somewhere else, check whether the base rate there looks like yours.
The best rule for action also depends on costs. A lost $240 sale and a $240 shipment to a thief do not hurt equally. Probability tells you how likely each case is. Weighing the money is the job of expected value.
The classic mistake: forgetting the base rate
The most common error is to treat P(alarm | fraud) as if it were P(fraud | alarm). Ignoring how rare the event was to begin with is called base rate neglect.
It appears all over. A medical screening test for a rare condition can be quite accurate and still produce mostly false positives among healthy crowds, which is why doctors often order a follow-up test. In a courtroom, "an innocent person would rarely match this evidence" is not the same statement as "a person who matches is rarely innocent." The mix-up there is often called the prosecutor's fallacy.
Economists meet it when a warning signal, such as a drop in some index, "preceded most recessions." The useful question runs the other way: when the signal flashes, how often does a recession follow? A signal can show up before every downturn and also cry wolf many times in between.
Try three questions whenever someone quotes an accuracy figure:
- How common is the thing before any test?
- How often does the test fire when the thing is there?
- How often does it fire when the thing is not there?
With all three, you can do the count. With only one, you cannot.
Words to know
Conditional probability the chance of an event given that another event is known to have happened.
Independent events events where knowing that one happened does not change the probability of the other.
Base rate the share of cases that have a trait before you look at any new evidence.
False positive a test or alarm that signals something is there when it is not.
Prior the probability you assign before seeing a new piece of evidence.
Posterior the updated probability after taking the evidence into account.
Bayes' rule a formula that turns P(evidence given cause) into P(cause given evidence) using the base rate.
Check yourself
- In words, what does P(A | B) mean?
- Using Priya's table of 200 orders, what is P(Computer | Standard)?
- Events A and B are independent, with P(A) = 0.4 and P(B) = 0.5. What is the probability that both happen?
- Suppose 2% of orders are fraud, the alarm catches 95% of fraud, and it flags 4% of honest orders. What share of flagged orders is fraud?
- Explain why a fairly accurate alarm can be wrong most of the time when it sounds.
Show the answers
- It is the probability that A happens when you already know B has happened, counted only among cases where B is true.
- Stay in the Standard column: 70 computer orders out of 160 standard orders, so 70 ÷ 160 = 0.4375, or about 44%.
- For independent events you multiply: 0.4 × 0.5 = 0.20.
- Per 10,000 orders, 200 are fraud and 190 are flagged, while 4% of 9,800 honest orders is 392, so 190 ÷ 582 ≈ 0.326, about 33%.
- When the event is rare, the honest group is so large that even a small false alarm rate creates more false alarms than true ones.