01 / 21

Bayesian Inference
Basics

Learn how to update beliefs with evidence using Bayes' rule: from prior probability through likelihood to the posterior distribution.

Statistics

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

Prior
Your belief about a parameter before seeing data: \( P(\theta) \)
Likelihood
How probable the observed data is given a parameter value: \( P(D \mid \theta) \)
Posterior
Your updated belief after combining prior and data: \( P(\theta \mid D) \)

Why Use Bayesian Methods?

1
Incorporates prior knowledge. You can encode domain expertise, previous studies, or expert opinion directly into the analysis.
2
Natural interpretation. The posterior gives direct probability statements: "There is a 95% probability the parameter lies in this interval."
3
Works with small samples. When data is scarce, the prior stabilizes estimates and prevents overfitting.
4
Sequential updating. As new data arrives, today's posterior becomes tomorrow's prior: learning is incremental.

Bayes' Rule: The Core Theorem

\( P(\theta \mid D) \)
Posterior: updated belief about \(\theta\) after observing data \(D\)
\( P(D \mid \theta) \)
Likelihood: probability of data given the parameter
\( P(\theta) \)
Prior: initial belief about the parameter
\( P(D) \)
Evidence: marginal probability of data (normalizing constant)

How Bayes' Rule Flows

Prior
\(P(\theta)\)
Likelihood
\(P(D \mid \theta)\)
× Joint
\(P(D \mid \theta) \cdot P(\theta)\)
÷ Evidence
\(P(D)\)
Posterior
\(P(\theta \mid D)\)

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

1
Define the parameter \(\theta\). What unknown quantity are you trying to learn about?
2
Specify the prior \( P(\theta) \). Encode your initial belief: uniform if ignorant, informative if you have expertise.
3
Write the likelihood \( P(D \mid \theta) \). Choose a statistical model for how data is generated given \(\theta\).
4
Compute the posterior. Multiply prior by likelihood, then normalize (or use MCMC sampling).
5
Summarize and interpret. Report the posterior mean, median, mode, and credible intervals.

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

Population: 10,000 people 100 9,900 healthy 90 True + 495 False + 9,405 True − 585 test + 90 true + 495 false
\( P(\text{disease} \mid +) = \frac{90}{585} \approx 15.4\% \)

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

Prior: \(\text{Beta}(1,1)\)
Flat line at \(y = 1\). Represents total uncertainty about \(\theta\).
Posterior: \(\text{Beta}(8,4)\)
Peak near \(\theta \approx 0.67\). Data has informed our belief substantially.

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:

1
New prior: \( \text{Beta}(8, 4) \) (yesterday's posterior)
2
New data: 6 heads, 4 tails out of 10 flips
3
New posterior: \( \text{Beta}(8 + 6, \; 4 + 4) = \text{Beta}(14, 8) \)
4
New posterior mean: \( \frac{14}{14+8} = \frac{14}{22} \approx 0.636 \)

Common Mistakes

✕ Ignoring the Base Rate
Forgetting \( P(\theta) \) and relying only on the likelihood. This leads to vastly overestimating probabilities (as in the medical test example).
✕ Confusing Prior and Posterior
Using the posterior when you should be stating the prior, or vice versa. Always track which distribution you are referring to.
✕ Forgetting to Normalize
Computing \( P(D \mid \theta) \cdot P(\theta) \) but forgetting to divide by \( P(D) \). The result must integrate/sum to 1.

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?