Probability and statistics · Part 2 of 5
Conditional probability and Bayes' theorem
Learn how to update probabilities when new information arrives, using conditional probability, the law of total probability, and Bayes' theorem.
Probability and statistics16 min read
You hear that it is cloudy outside. Suddenly rain feels more likely than it did this morning. Your belief about rain changed because you gained information — and probability has a precise way to measure exactly how much information changes a belief. That measurement is called conditional probability.
This idea matters everywhere: a doctor interpreting a positive test result, a spam filter deciding if an email is junk, a factory tracing a defective part back to a machine. In all of these, you know something new (a test came back positive, an email contains certain words) and you want the probability of something you cannot directly observe. Bayes' theorem is the tool that reverses the direction of a probability, and it is one of the most used formulas in all of applied statistics.
What conditional probability means
The conditional probability of given , written , answers: "if I know that happened, what is the chance that also happened?" Knowing shrinks the universe of possible outcomes down to only those where occurred, so we measure inside that smaller universe.
The definition is:
The numerator counts outcomes where both and happen; the denominator restricts attention to outcomes where happens. Rearranging gives the multiplication rule:
This says: the chance that both events happen equals the chance the first one happens, times the chance the second happens given the first. Note that and are generally different numbers — reversing the condition changes the question.
Example 1. A condition on two dice Two fair dice are rolled. Given that the sum is , what is the probability that the first die shows an even number?
List the outcomes with sum :
There are equally likely outcomes in the reduced universe. The first die is even in , , and — that is of them.
As a check with the formula: and , so the ratio is .
Chaining conditions: the multiplication rule in action
The multiplication rule extends to any number of events. For three events , , :
This is the natural way to handle draws without replacement: after each draw, the probabilities for the next draw change because the composition of the pool changed. If the events do not influence each other — that is, — we call them independent, and the multiplication rule collapses to . Conditional probability is the general concept; independence is the special case.
Example 2. Drawing without replacement A bag contains red and blue marbles. Two marbles are drawn without replacement. What is the probability that both are red?
Probability the first is red:
Given the first was red, red marbles remain among total:
Multiply:
Check by counting: the number of ways to choose of the red marbles divided by ways to choose any of is . It agrees.
Splitting the problem: the law of total probability
Often you cannot compute directly, but you can compute it along each of several distinct scenarios. If are mutually exclusive and cover everything (a partition), then:
Intuitively: whatever happens to must happen inside one of the scenarios, so you add up the scenario-by-scenario contributions, each weighted by how likely that scenario is. This "weighted average of conditional probabilities" is the setup for Bayes' theorem, because it supplies the denominator.
Example 3. Defects from two machines Machine A produces of a factory's output with a defect rate; machine B produces the remaining with a defect rate. What is the probability that a randomly chosen item is defective?
Let be "defective", "made by A", "made by B". The machines form a partition.
Contribution from A:
Contribution from B:
Add them:
So of all items are defective. As a sanity check, this lies between the two defect rates ( and ), closer to because A makes more items — exactly what a weighted average should do.
Bayes' theorem: reversing the condition
Suppose you know — how likely the evidence is under a hypothesis — but you want : how likely the hypothesis is given the evidence. Bayes' theorem flips the condition:
Each piece has a name worth knowing:
- is the prior: how likely the hypothesis was before seeing the evidence.
- is the likelihood: how strongly the hypothesis predicts the evidence.
- is the evidence: the overall chance of seeing the evidence, computed by the law of total probability.
- is the posterior: the updated probability after the evidence.
With two competing hypotheses and , the denominator expands:
The key insight: a hypothesis that explains the evidence well can still be improbable if it started out improbable. The prior matters.
Example 4. A positive medical test A disease affects of a population. A test detects the disease of the time when it is present (sensitivity), and gives a false positive of the time when it is absent. A random person tests positive. What is the probability they actually have the disease?
Let = has the disease, = tests positive. Given:
Denominator by total probability:
Bayes' theorem:
Only about a chance! This surprises almost everyone. The reason: the disease is rare, so among people about true positives appear alongside about false positives — false positives dominate. The check: , confirming the arithmetic.
A reliable workflow for Bayes problems
Bayes word problems become mechanical if you follow the same steps every time:
- Name the events. Identify the hypothesis you care about and the evidence you observed.
- List the givens. Write down the prior and the likelihoods , (or for every partition member).
- Compute the denominator with the law of total probability.
- Apply Bayes' theorem and simplify.
- Sanity-check. The posterior must lie between and , and if the evidence is genuinely informative it should differ from the prior. If your answer is more extreme than the evidence justifies, re-check the base rates.
A useful shortcut for two hypotheses: the posterior odds are — likelihood ratio times prior odds. In the medical example, the likelihood ratio is , but the prior odds are , so the posterior odds are about — matching .
Example 5. Tracing a defect back to its machine Using the factory from before (machine A: of output, defective; machine B: of output, defective), an item is found defective. What is the probability it came from machine A?
We already computed the denominator in the total-probability example:
The numerator is the A-branch:
Bayes' theorem:
Check by substitution: , and indeed , since a defective item must come from one of the two machines. Even though A makes more items, its low defect rate means a defective item is more likely from B.
Common mistakes
- Confusing with — the probability a test is positive given disease is not the probability of disease given a positive test; Bayes' theorem is exactly what converts one to the other.
- Ignoring the base rate and reporting the sensitivity as the answer — a sensitive test for a -prevalence disease still yields only about a chance of disease after a positive result.
- Forgetting to shrink the denominator when conditioning — computing as without dividing by .
- Assuming — the correct identity is ; the two conditional probabilities with different conditions need not sum to .
- Using replacement probabilities for without-replacement draws — after removing a red marble from 4 red and 6 blue, the next-draw probability of red is , not .
Practice
- Given and , find .
- A fair six-sided die is rolled once. Given that the result is even, what is the probability that the result is greater than 3?
- Two cards are drawn from a standard 52-card deck without replacement. Using the multiplication rule, find the probability that both cards are aces.
- Machine A produces 60% of a factory's items with a 2% defect rate, and machine B produces the other 40% with a 5% defect rate. Using the law of total probability, what is the probability that a randomly chosen item is defective?
- A disease affects 2% of a population. A test has sensitivity 90% (positive with probability 0.9 when the disease is present) and false positive rate 10% (positive with probability 0.1 when the disease is absent). A person tests positive. Using Bayes' theorem, what is the probability that the person has the disease?
Answers
- , by the definition of conditional probability.
- , because among the even outcomes , two of them ( and ) exceed .
- , since after one ace is drawn, 3 aces remain among 51 cards.
- , the weighted average of the two defect rates.
- , since the many false positives from the large healthy population swamp the true positives.
Next, random variables and distributions give us a way to package all these probabilities about an uncertain quantity into a single object.