Conditional probability and Bayes’ theorem
Information changes the odds. Once you know that B happened, the space of possibilities shrinks to B alone — and every probability has to be recomputed inside it. This lesson shows how, how to reverse the condition with Bayes’ theorem, and why a positive screening result almost never means what it looks like.
Before you start
This topic builds on earlier ideas. Before you start, it's worth working through the lessons below — they'll make everything click:
- Classical probabilityWhen every outcome of an experiment is equally possible, the probability of an event is an ordinary ratio: how many outcomes favour it, over how many there are. Everything else is being able to count both numbers — and knowing when the opposite event is easier to count.
- FractionsA fraction writes part of a whole as a numerator and a denominator. Learn equivalent fractions, all four operations on fractions, mixed numbers, comparing fractions and reducing to lowest terms.
Where this is used
Real situations where you count exactly the way this lesson teaches:
- Reading a screening resultA test detects the disease in 99 of every 100 patients who have it and misfires on 2 of every 100 who do not, while 1 person in 100 is actually ill. A positive result reaches 0.01 · 0.99 = 0.0099 of the ill and 0.99 · 0.02 = 0.0198 of the healthy, so 2.97 per cent of everyone tested. The probability of being ill after a positive result is 0.0099 / 0.0297 — exactly one third, not 99 per cent. That is why a positive screening result is always repeated with a confirmatory test.
- A spam filterA filter learns how often a word appears in spam and how often in ordinary mail. If the word “invoice” shows up in 40 per cent of spam and 2 per cent of legitimate messages, and 30 per cent of all mail is spam, then seeing that word puts the probability of spam at 0.3 · 0.4 / (0.3 · 0.4 + 0.7 · 0.02) = 0.12 / 0.134, about 90 per cent. A naive Bayes classifier is this same computation repeated for every word in the message.
- Quality control across two linesA plant makes 70 per cent of its units on line A, where 1 in 100 is faulty, and 30 per cent on line B, where 4 in 100 are. The overall defect rate is 0.7 · 0.01 + 0.3 · 0.04 = 0.019, that is 1.9 per cent. When a complaint concerns a faulty unit, the probability that it came off line B is 0.012 / 0.019, about 63 per cent — and that is the number an audit starts from.
- Tomorrow’s weather forecastA service forecasts rain on 30 per cent of days. When it does, rain follows 80 per cent of the time; when it does not, rain still falls 10 per cent of the time. Rain on a randomly chosen day therefore has probability 0.3 · 0.8 + 0.7 · 0.1 = 0.31. If it rained and you cannot recall the forecast, the chance that rain had been predicted is 0.24 / 0.31, about 77 per cent.
All formulas
Conditional probability
defined only for P(B) > 0
Multiplication rule
the definition times P(B)
Counting form
when the outcomes are equally likely
Law of total probability
A₁, …, Aₙ split Ω into disjoint cases
Bayes’ theorem
reverses the condition: P(B|A) into P(A|B)
Independence
the condition changes nothing about A
The classical probability lesson said that drawing without replacement is not independent, because the first draw changes what is left in the urn. We wrote that down as and left it without a computation. This lesson supplies it.
The starting point is simple: information changes the odds. Once you know that has happened, outcomes outside are no longer possible — the sample space has shrunk from all of to alone, and everything has to be recomputed inside it.
The definition
The conditional probability of given is the number
The numerator holds what favours and lies in the new space; the denominator holds the whole new space. It is exactly the construction of the classical formula, with taking over the role of .
The proviso is not a formality: conditioning on an impossible event makes no sense, because there is nothing to divide by.
When all outcomes are equally likely, cancels out of numerator and denominator and you can work with counts directly:
The two-way table
The handiest tool for conditional probabilities is the two-way table: one criterion down the rows, the other across the columns, counts in the cells.
A hundred students before an exam — half of them studied, half did not:
| passed | failed | total | |
|---|---|---|---|
| studied | 45 | 5 | 50 |
| did not study | 15 | 35 | 50 |
| total | 60 | 40 | 100 |
Every conditional probability is read off this table as a cell divided by a row or a column total — without a single formula.
is not
The example above was not a curiosity but the single most important warning of this lesson. Both quotients divide the same , but by different things, so they agree only in the special case .
The everyday versions of this mistake sound entirely innocent:
- “Most people with flu run a fever” does not mean “most people with a fever have flu”.
- “Nearly every crash involves excessive speed” does not mean “nearly every instance of speeding ends in a crash”.
Both sentences swap the condition for the conclusion. The tool that performs that swap correctly comes two sections below.
The multiplication rule
It is worth clearing the denominator once, because that is the form the definition is used in most often:
It reads as a recipe for a two-stage experiment: first happened, then, in the narrowed world, happened.
The law of total probability
Often it is the other way round: we do not know , but we do know it separately in each case. Then split into disjoint events covering everything, and add:
Each summand is one application of the multiplication rule. On the drawing each corresponds to one path: probabilities multiply along it, and finished paths are added.
Bayes’ theorem
Now the reversal. Since can be written two ways,
This is Bayes’ theorem, and the denominator is precisely the total probability of the previous section. On a tree it has a short description: one path divided by the sum of every path ending in the same result.
Why so low? Because there are times more healthy people than ill ones, so even a two-per-cent error rate produces twice as many false alarms as there are true detections in total. You can see it on the tree: the thin branch against the thick one.
Base rates and the prosecutor’s fallacy
The number in the example has a name of its own: the base rate — the probability of the hypothesis before any evidence is seen. It enters both the numerator and the denominator of Bayes’ formula, so it governs the answer.
Here is what happens when only the base rate moves and the test stays the same:
| base rate | probability of illness after a positive result |
|---|---|
The same test, the same sensitivity, four completely different answers. Base-rate neglect — reading the sensitivity of a test as though it answered the question about the patient — is exactly the error this table puts into numbers.
Its courtroom version is called the prosecutor’s fallacy. It goes: the trace matches one person in a thousand, therefore the accused is guilty with probability . That is false, because the condition has been swapped with the conclusion.
Independence as a special case
Since conditioning is supposed to change the odds, it is worth naming the situation where it changes nothing:
Substituting that into the definition immediately gives the formula you know from the classical-probability lesson:
Independence is therefore not a separate idea but a special case of conditional probability — the one where knowing about turns out to be useless. The student table is not independent: while , so studying does help after all.
Exercises
The set asks three things, in the order of the lesson. The prompt gives the probabilities and — not counts — and asks for the quotient. The prompt gives a split into cases: pairs and from which the total probability has to be assembled. The prompt gives the same data and asks for the reversal, that is for Bayes’ theorem.
In all three cases the answer is a fraction in lowest terms — the convention from the classical-probability lesson still holds.
Practice
Work through a set of exercises — they get harder as you go. At the end you'll see your score and the mistakes worth reviewing.
The generator does not ask about interpretation — about whether, at a given base rate, a positive result is already cause for concern. That is a piece of reasoning rather than a number, so it is laid out in the worked examples above.
Common mistakes
- Confusing with — same numerator, different denominators. Always check which event is the condition: it is the one under the fraction bar.
- Neglecting the base rate — the sensitivity of a test is not an answer to the question about the patient. For a rare disease most alarms are false even when the test is good.
- Dividing by instead of — the denominator holds the probability of the condition, the event already known to have occurred.
- A split that does not cover — the law of total probability needs cases that are disjoint and exhaustive; if the do not add up to , the computation is meaningless.
- Assuming independence without checking — multiplying is legitimate only when the condition really changes nothing. Drawing without replacement never qualifies.
- Conditioning on an event of probability zero — there is nothing to divide by, so is simply undefined.
Formula card
Topic: Conditional probability
Conditional probability
defined only for P(B) > 0
Multiplication rule
the definition times P(B)
Counting form
when the outcomes are equally likely
Law of total probability
A₁, …, Aₙ split Ω into disjoint cases
Bayes’ theorem
reverses the condition: P(B|A) into P(A|B)
Independence
the condition changes nothing about A
