Bayes' Theorem
Bayes' Theorem
Definition
Core Statement
Bayes' Theorem is a fundamental result in probability theory that describes how to update beliefs in light of new evidence. It provides the mathematical foundation for Bayesian Statistics and probabilistic reasoning.
Purpose
- Calculate conditional probabilities (reverse probabilities).
- Update prior beliefs with new data to obtain posterior beliefs.
- Foundation for diagnostic tests, spam filters, and Bayesian inference.
When to Use
Use Bayes' Theorem When...
- You need to reverse a conditional probability (e.g.,
from ). - Integrating prior knowledge with observed data.
- Medical diagnosis (disease given test result).
- Bayesian inference in statistics.
Theoretical Background
The Formula
| Term | Name | Meaning |
|---|---|---|
| Posterior | Probability of |
|
| Likelihood | Probability of observing |
|
| Prior | Probability of |
|
| Evidence | Total probability of |
Extended Form (Law of Total Probability)
Classic Example: Medical Diagnosis
Disease Testing
- Disease prevalence:
(1%). - Test sensitivity:
(95% true positive rate). - Test specificity:
(90% true negative rate). - Question: If someone tests positive, what is
?
Solution:
Result: Only 8.7% chance of actually having the disease, despite a positive test. (Due to low base rate).
Example 2: Spam Filter
"Free Money" Filter
A spam filter looks for the word "Free".
- Prior: 40% of all emails are Spam (
), 60% are Ham ( ). - Likelihood (Spam): 80% of Spam emails contain "Free" (
). - Likelihood (Ham): 10% of Ham emails contain "Free" (
).
Question: If an email contains "Free", what is the probability it is Spam?
Solution:
Conclusion: The presence of the word "Free" increases the probability of being spam from 40% (Prior) to 84.2% (Posterior).
Assumptions
Limitations
Pitfalls
- Base Rate Neglect: People often ignore
and focus only on . A rare disease with a 99% accurate test often yields more false positives than true positives. - The Prosecutor's Fallacy: Confusing
with . Just because it's unlikely an innocent person would match the DNA (low likelihood), doesn't mean the probability they are innocent is low (posterior), if the prior probability of guilt is tiny. - Zero Priors (Dogmatism): If you assign
, no amount of evidence can ever change your mind. Bayesian updating requires non-zero priors for possibility.
Python Implementation
# Medical Test Example
P_disease = 0.01
P_pos_given_disease = 0.95
P_pos_given_no_disease = 0.10
# Bayes' Theorem
numerator = P_pos_given_disease * P_disease
denominator = (P_pos_given_disease * P_disease +
P_pos_given_no_disease * (1 - P_disease))
P_disease_given_pos = numerator / denominator
print(f"P(Disease | Positive Test): {P_disease_given_pos:.3f}")
R Implementation
# Medical Test Example
P_disease <- 0.01
P_pos_given_disease <- 0.95
P_pos_given_no_disease <- 0.10
# Bayes' Theorem
numerator <- P_pos_given_disease * P_disease
denominator <- (P_pos_given_disease * P_disease +
P_pos_given_no_disease * (1 - P_disease))
P_disease_given_pos <- numerator / denominator
cat("P(Disease | Positive Test):", round(P_disease_given_pos, 3), "\n")
Interpretation Guide
| Result | Interpretation |
|---|---|
| Result | Interpretation |
| -------- | ---------------- |
| Posterior > Prior | Evidence supports the hypothesis (Bayes Factor > 1). |
| Posterior < Prior | Evidence contradicts the hypothesis (Bayes Factor < 1). |
| Prior = 0 | Dogmatism: Belief cannot be updated, regardless of evidence. |
| Posterior |
Certainty: Evidence is so strong it overwhelms the prior (or prior was already high). |
Related Concepts
- Bayesian Statistics - Statistical framework built on Bayes' Theorem.
- Conditional Probability
- Law of Total Probability
- Sensitivity and Specificity