Bayesian Statistics: An Introduction to Bayes Theorem, Priors, and Posteriors
Learn Bayesian statistics from first principles — Bayes Theorem, priors, likelihood, posteriors, credible intervals, and when to choose Bayesian vs Frequentist approaches.
Bayesian Statistics: An Introduction to Bayes Theorem, Priors, and Posteriors
Bayesian statistics is a paradigm that treats probability as a measure of belief or uncertainty, rather than long-run frequency. It allows you to update your beliefs in light of new data using Bayes Theorem. This guide covers the core concepts, practical examples, and when to use Bayesian vs Frequentist methods.
---
What Is Bayesian Statistics?
In Bayesian thinking, you start with a prior belief about a parameter (e.g., the probability of a disease, the conversion rate of a webpage). You collect data, and then use Bayes Theorem to update your belief into a posterior — your revised belief after seeing the evidence.
| Aspect | Bayesian | Frequentist |
|---|---|---|
| Probability | Degree of belief in a hypothesis | Long-run frequency of outcomes |
| Parameters | Unknown but have probability distributions | Fixed; we estimate them with confidence |
| Inference | Posterior distribution (e.g., "95% credible interval") | Point estimate + confidence interval |
| Prior info | Explicitly incorporated via priors | Usually ignored or informal |
| Interpretation of interval | "95% probability the parameter is in this interval" | "95% of such intervals would contain the true value" |
Bayesian vs Frequentist: A Comparison
| Question | Frequentist Answer | Bayesian Answer |
|---|---|---|
| "What is the probability the treatment works?" | "We cannot assign probability to parameters. We can say: if the null were true, we'd see such data with probability p." | "Given our prior and this data, the probability the treatment works is 87%." |
| "How do we handle prior knowledge?" | Often ignored or informally used | Built into the prior distribution |
| "How do we interpret a 95% interval?" | 95% of repeated intervals would contain the true value | 95% probability the parameter lies in this interval |
| "How do we update with new data?" | Re-run the analysis from scratch | Use the old posterior as the new prior |
Bayes Theorem
The Formula
P(A|B) = P(B|A) × P(A) / P(B)
In the context of parameters and data:
- P(θ | data) = Posterior (belief about parameter θ after seeing data)
- P(data | θ) = Likelihood (probability of data given θ)
- P(θ) = Prior (belief about θ before seeing data)
- P(data) = Marginal likelihood (normalizing constant; ensures probabilities sum to 1)
Plain English
"The probability of our hypothesis given the data is proportional to how likely the data is under that hypothesis, times our prior belief in the hypothesis."
Posterior ∝ Likelihood × Prior
You often work with proportions: the posterior is proportional to (likelihood × prior). The denominator P(data) is a constant that makes the posterior integrate to 1.
---
Prior: What It Is and Types
The prior encodes what you believe about a parameter before observing the data.
Types of Priors
| Type | Definition | Example |
|---|---|---|
| Uninformative (flat) | Very weak belief; lets data dominate | Uniform prior: all values equally likely |
| Informative | Strong belief from domain knowledge | "Conversion rate is usually 2–5% based on industry benchmarks" |
| Conjugate | Mathematically chosen so posterior has same family as prior | Beta prior for binomial likelihood → Beta posterior |
Why Priors Matter
- Uninformative priors produce results closer to Frequentist estimates, but still allow direct probabilistic interpretation.
- Informative priors shrink estimates toward your prior when data is sparse; they become less influential as data grows.
- Conjugate priors make math tractable; modern software (Stan, PyMC) handles non-conjugate priors via MCMC.
Likelihood
The likelihood P(data | θ) is the probability of observing your data given a specific parameter value. It is not a probability distribution over θ; it's a function of θ for fixed data.
- For a coin flip: P(3 heads in 5 flips | p=0.5) = binomial likelihood.
- For continuous data: often Normal, Poisson, or other distributions depending on the problem.
Posterior: Updating Beliefs with Data
The posterior P(θ | data) is your updated belief after observing the data. It combines prior and likelihood:
Posterior ∝ Likelihood × Prior
- With lots of data, the likelihood dominates and the prior has less influence.
- With little data, the prior has more influence — this is both a feature (you can incorporate expert knowledge) and a critique (choices can be subjective).
Practical Examples
Example 1: Medical Testing
Scenario: A disease has prevalence 1%. A test has 95% sensitivity (P(positive | disease)) and 90% specificity (P(negative | no disease)). A patient tests positive. What is P(disease | positive)?
- Prior: P(disease) = 0.01
- Likelihood: P(positive | disease) = 0.95
- Posterior: Use Bayes to get P(disease | positive) ≈ 8.8%
Example 2: Spam Filtering
- Prior: P(spam) for a given sender (e.g., 0.3 from historical data)
- Likelihood: P(words in email | spam) — from word frequencies in spam vs non-spam
- Posterior: P(spam | words) — update as each email arrives
Example 3: A/B Testing
- Prior: Both variants have similar conversion rates (e.g., Beta(1,1) or Beta(priorsuccesses, priorfailures))
- Likelihood: Binomial for clicks given impressions
- Posterior: Distribution of conversion rate for A and B
---
Advantages and Disadvantages
Advantages
| Advantage | Description |
|---|---|
| Natural interpretation | "95% probability the parameter is in this interval" vs Frequentist "95% of intervals would contain it" |
| Incorporates prior knowledge | Use expert opinion, historical data, or regularization |
| Handles small samples | Priors provide structure when data is sparse |
| Sequential updating | New posterior = posterior from previous batch as new prior |
| Flexible models | Hierarchical models, latent variables, complex dependencies |
Disadvantages
| Disadvantage | Description |
|---|---|
| Prior subjectivity | Different priors → different posteriors; sensitivity analysis helps |
| Computational cost | MCMC and variational inference can be slow for big models |
| Communication | Some audiences prefer Frequentist framing |
| Convergence | MCMC can fail to converge; diagnostics (R-hat, n_eff) required |
When to Use Bayesian vs Frequentist
| Situation | Recommendation |
|---|---|
| Small sample, strong prior knowledge | Bayesian |
| Large sample, little prior | Either; results often similar |
| Need "probability of hypothesis" | Bayesian (credible intervals) |
| Regulatory/compliance expects p-values | Frequentist |
| Complex hierarchical structure | Bayesian (random effects, multilevel) |
| Quick, standard analyses | Frequentist (simpler software, faster) |
Credible Intervals vs Confidence Intervals
| Concept | Credible Interval (Bayesian) | Confidence Interval (Frequentist) |
|---|---|---|
| Interpretation | "95% probability the parameter lies in [a, b]" | "95% of such intervals would contain the true parameter" |
| What varies | The parameter (random) | The interval (random across repeated samples) |
| Depends on prior? | Yes | No |
| Computation | From posterior distribution (e.g., 2.5th and 97.5th percentiles) | From sampling distribution of estimator |
Bayesian Inference Workflow
- Define the model — What parameters? What likelihood?
- Choose priors — Uninformative, informative, or conjugate; justify or perform sensitivity analysis.
- Observe data — Collect or load your dataset.
- Compute posterior — Analytical (if conjugate) or MCMC/variational (Stan, PyMC, etc.).
- Check convergence — R-hat, effective sample size, trace plots.
- Summarize — Mean, median, credible intervals, P(θ > threshold).
- Interpret — Report and communicate results.
Quick Reference
| Term | Meaning | |
|---|---|---|
| Prior | Belief about parameter before data | |
| Likelihood | P(data | θ) |
| Posterior | Belief after data; ∝ Likelihood × Prior | |
| Credible interval | Bayesian interval: "X% probability parameter is inside" | |
| Conjugate prior | Prior that yields same-family posterior | |
| MCMC | Method to sample from posterior when analytical solution is intractable |
What's Next?
- [Probability Distributions](probability-distributions) — Understanding the shapes behind likelihoods and priors
- [Inferential Statistics](inferential-statistics) — Frequentist confidence intervals and hypothesis testing
- [Statistical Tests Guide](statistical-tests-guide) — Choosing and running the right test
- [Statistics Overview](statistics-overview) — The statistics workspace and workflow
Related Articles
Probability Distributions: Understanding How Data Is Shaped
Learn about the most important probability distributions — Normal, Binomial, Poisson, Uniform, and Exponential — and how they help you understand and model real-world data.
Inferential Statistics: Confidence Intervals, Hypothesis Testing, and P-Values
Learn how inferential statistics lets you draw conclusions about populations from samples — confidence intervals, hypothesis testing, p-values, Type I and II errors, and common misconceptions.
Statistical Tests
A complete guide to all 14+ hypothesis tests -- when to use each one, how to run them, and how to interpret results.
Statistics Overview: What Are Statistics and How to Use Them
A beginner-friendly introduction to statistics, descriptive vs inferential analysis, the Statistics workspace layout, and running your first analysis.
Was this helpful?