Bayes’ Theorem: Formula, Evidence, and Worked Examples
Use Bayes’ theorem to calculate a posterior from a prior and evidence. Follow six examples on base rates, repeated tests and total probability.
TL;DR
Bayes' theorem updates the probability of a hypothesis after evidence arrives. Multiply the prior by the likelihood, then divide by the overall probability of the evidence.
Key Points
- The prior is the starting probability before considering the evidence.
- The likelihood asks how often the evidence occurs when the hypothesis holds.
- The posterior asks how likely the hypothesis is after observing that evidence.
- The denominator includes every way the same evidence can occur.
- Conditional probabilities depend on which event appears after the bar.
What is Bayes' theorem?
Let be a hypothesis or event, and let be the evidence. When and the indicated conditional probabilities are defined, use
| Part | Name | Question |
|---|---|---|
| Prior | How likely was before observing ? | |
| Likelihood | If holds, how likely is the evidence? | |
| Overall evidence probability | How likely is the evidence across the full population? | |
| Posterior | After the evidence, how likely is ? |
The direction matters. If a machine flags 80% of defective parts, that number is . The probability that a flagged part is defective answers the reverse question.
Why does the formula work?
If and , write the probability of both events in two ways:
Divide by to get Bayes' formula. MIT OpenCourseWare and the OpenStax probability text derive it from conditional probability. If an event has probability zero, a conditional probability given that event is undefined in the elementary ratio formula.
How do you find the denominator?
Split the sample space into disjoint cases covering all possibilities. If you split into and its complement , the law of total probability gives
With a larger partition the denominator is , summed over the cases with positive prior probability. Draw a tree, multiply along each path to the same evidence, and add across those paths. The De Morgan's laws guide reviews the complement notation.
Expected counts often make the calculation easier. Start with a convenient total and apply the prior fractions. Split each group by the evidence rate. Divide the target group within the evidence by the count of all items showing the evidence. The statistics practice guide shows why the subgroup denominator matters.
Worked Bayes' Theorem Examples
Example 1
Five percent of parts are defective. A tester flags 80% of defective parts and 10% of good parts. What proportion of flagged parts are defective under this model?
- In a group of 200, the model gives 10 defective and 190 good parts.
- It flags defective parts and good parts.
- Of flagged parts, 8 are defective. The probability is .
Example 2
Line A makes 60% of parts and has a 2% defect rate. Line B makes 40% and has a 5% defect rate. A randomly selected part is defective. What is the probability it came from line B?
- Line B contributes to the overall defect probability.
- Line A contributes , so the total is .
- Divide to get .
Example 3
In Example 1, what is the probability that a part is defective if it was not flagged?
- Of 10 defective parts, are not flagged.
- Of 190 good parts, are not flagged.
- There are 173 unflagged parts and 2 defects among them. The probability is .
Example 4
Use the same tester for two readings. Assume the readings are independent given a part's defect status. What is the probability of a defect after two flags?
- For defective parts, the chance of two flags is . For good parts, it is .
- The two joint contributions are and .
- The posterior is . If the same error influences both readings, the independence assumption needs reconsideration.
Example 5
Choose one of three boxes with equal probability. They contain respectively 2, 5 and 8 green tiles out of 10. A tile drawn from the chosen box is green. What is the probability you chose the third box?
- The joint probability of the third box and a green tile is .
- Across the boxes, the probability of green is .
- The posterior is , approximately 53.33%.
Example 6
The same tester's defect prior changes from 5% to 1%, with the two flag rates unchanged. What is the new defective share of flags?
- The defect-and-flag probability is .
- The good-and-flag probability is .
- The defective share is . The same likelihoods yield a different posterior because the prior changed.
Mistakes That Change the Posterior
Mistake 1: Switching the two events around the conditional bar
The event after the bar sets the group being considered. Make sure the result answers the requested direction, such as defect given flag.
Mistake 2: Counting only one path in the denominator
The evidence can occur even when the hypothesis fails. Add all disjoint paths to the same evidence, including false alarms in the tester example.
Mistake 3: Multiplying likelihoods without an independence assumption
For repeated evidence, use the joint likelihood or conditional probabilities that reflect the relationship between observations. The product of two identical likelihoods applies only when the readings are conditionally independent and have those likelihoods.
Try It Yourself
- Forty percent of items come from line B. Both lines have the same positive probability of producing the observed sticker. What is ?
- A prior is , the likelihood is , and the overall evidence probability is . Find the posterior.
- What is in the ratio formula if ?
Answers and Reasoning
- Multiply both lines' priors by the same likelihood. The common term cancels, so the posterior remains 40%.
- Use .
- The ratio is undefined because its denominator is zero.
Questions About Bayes' Theorem
Can the evidence lower the probability of a hypothesis?
Yes. If is smaller than , the update multiplies the prior by a factor below 1. Evidence less common when holds reduces its probability.
Can today's posterior become tomorrow's prior?
Yes, when updating for additional evidence. The next likelihood must condition on what was already observed when that information affects the new evidence. The Stanford Encyclopedia explains this sequential interpretation and its assumptions.
Conclusion
- Identify the hypothesis, evidence, and direction of conditioning.
- Multiply the hypothesis prior by its evidence likelihood and add all evidence paths for the denominator.
- Check that the final probability belongs to the evidence group you actually observed.
Read More
Research Behind This Article
- MIT OpenCourseWare, Introduction to Statistical Methods in Economics — Lecture 4. MIT
- OpenStax, Principles of Data Science — Probability Theory. OpenStax
- Stanford Encyclopedia of Philosophy, Bayes' Theorem. Stanford
- University of Toronto, Mike Evans and Jeffrey Rosenthal, Probability and Statistics: The Science of Uncertainty. University of Toronto