Bayesian Inference
Basics
Learn how to update beliefs with evidence using Bayes' rule: from prior probability through likelihood to the posterior distribution.
What Is Bayesian Inference?
Bayesian inference is a method of statistical reasoning where you start with an initial belief about a parameter, observe data, and then update your belief accordingly. Unlike frequentist methods that treat parameters as fixed unknowns, Bayesian methods treat parameters as random variables with probability distributions.
The Three Key Ingredients
Why Use Bayesian Methods?
Bayes' Rule: The Core Theorem
How Bayes' Rule Flows
The Proportionality Shortcut
Because \( P(D) \) is a constant (it doesn't depend on \(\theta\)), we often write Bayes' rule in its proportional form:
In words: Posterior is proportional to Likelihood times Prior. The normalizing constant \( P(D) \) ensures the posterior integrates (or sums) to 1, but we can often find it afterwards or avoid it entirely using sampling methods like MCMC.
Frequentist vs Bayesian
| Frequentist | Bayesian | |
|---|---|---|
| Parameter | Fixed but unknown constant | Random variable with a distribution |
| Probability | Long-run frequency | Degree of belief |
| Prior information | Not formally used | Encoded as \( P(\theta) \) |
| Interval estimate | Confidence interval | Credible interval |
| Interpretation | "95% of such intervals contain \(\theta\)" | "95% probability \(\theta\) is in this interval" |
How to Apply Bayes' Rule
Example 1: Medical Diagnosis
A disease affects 1% of the population. A test has a sensitivity (true positive rate) of 90% and a false positive rate of 5%. If a patient tests positive, what is the probability they have the disease?
Example 1: Solution
Example 1: Visual Breakdown
Example 2: Coin Fairness
You suspect a coin might be biased. You start with a uniform prior on the probability of heads: \(\theta \sim \text{Uniform}(0, 1)\). You flip the coin 10 times and observe 7 heads. What is the posterior distribution of \(\theta\)?
Example 2: Prior to Posterior
Example 3: Sequential Updating
Continuing from Example 2: your posterior was \(\text{Beta}(8, 4)\). Now you flip 10 more times and observe 6 heads. The old posterior becomes the new prior:
Common Mistakes
Question 1 of 5
In Bayes' rule, what does the term \( P(D \mid \theta) \) represent?
Question 2 of 5
A disease has a 2% prevalence. A test has 95% sensitivity and a 10% false positive rate. A patient tests positive. Which value is closest to \( P(\text{disease} \mid +) \)?
Question 3 of 5
If the prior is \( \text{Beta}(2, 2) \) and you observe 5 heads and 3 tails, what is the posterior distribution?
Question 4 of 5
In the proportional form \( P(\theta \mid D) \propto P(D \mid \theta) \cdot P(\theta) \), what role does \( P(D) \) play?
Question 5 of 5
As the amount of observed data increases, what generally happens to the influence of the prior on the posterior?