Bayesian Statistics
Bayesian Statistics: Principles, Computation, and Applications
1. Why Bayesian Statistics Is Useful
Bayesian statistics is especially valuable when:
Data are limited, noisy, biased, or unreliable.
Researchers need estimates of uncertainty, not only single point estimates.
Important prior knowledge exists before new data are collected.
Relationships among variables are complex, nonlinear, hierarchical, or time-dependent.
The model must support decisions made by people who need interpretable conclusions.
A practical motivation for Bayesian modeling is the situation in which a researcher has poor-quality data but still needs to make a forecast or estimate. Electoral polling is a useful example: polls are noisy, response rates are declining, and the available surveys may not represent the population perfectly. However, researchers may also possess substantial knowledge about elections, demographic patterns, geography, and historical behavior. Bayesian methods provide a formal way to combine this prior information with the observed data.
Bayesian inference does not require the observed data to carry the entire burden of inference. Prior knowledge can provide structure when data are sparse or unreliable.
Bayesian methods are not restricted to one discipline. They can be applied to:
Electoral forecasting
Marketing and media-mix modeling
Agriculture
Sports analytics
Social science
Political science
Spatial modeling
Time-series analysis
Scientific and engineering problems
The central advantage is flexibility: the same inferential framework can be adapted to many types of data and scientific questions.
2. The Core Components of Bayesian Inference
Bayesian modeling combines three main components:
Prior information
A prior represents knowledge, assumptions, or beliefs about quantities before the current data are analyzed. Priors may be based on:
Previous studies
Established scientific knowledge
Physical constraints
Historical data
Domain expertise
Reasonable assumptions about plausible parameter values
For example, if a parameter represents a quantity known from physics to vary only slightly, a prior with a narrow spread can express that confidence. If little is known, a broader prior can allow more variation.
Likelihood
The likelihood describes how probable the observed data are under particular values of the model parameters. It connects the model to the evidence contained in the data.
The likelihood is not simply the data themselves. It is a mathematical description of how the data-generating process is expected to behave.
Posterior distribution
The posterior combines the prior and likelihood to describe what is believed about the parameters after observing the data.
Bayes’ theorem is commonly written as:
where:
θ represents model parameters.
y represents observed data.
p(θ) is the prior distribution.
p(y∣θ) is the likelihood.
p(θ∣y) is the posterior distribution.
p(y) is the evidence or marginal likelihood, which normalizes the posterior.
The posterior is therefore an updated state of knowledge. It incorporates both what was believed before the data and what the data contribute.
Bayesian updating
A Bayesian analysis treats learning as an ongoing process:
Begin with a prior state of knowledge.
Observe new data.
Update beliefs using Bayes’ theorem.
Use the posterior as the basis for future predictions or further updating.
This process requires that beliefs remain open to revision. A parameter assigned exactly zero or exactly one probability cannot be updated by ordinary Bayesian evidence, because multiplying by zero eliminates the possibility entirely. Consequently, even highly confident beliefs should generally leave some small probability for being wrong.
3. Bayesian and Frequentist Perspectives
Frequentist statistics
Frequentist methods generally emphasize the information contained in repeated samples and aim to avoid incorporating subjective prior beliefs into the analysis. In many educational settings, frequentist methods are presented as the standard form of statistics.
A common frequentist tool is the p-value, which evaluates how unusual the observed data would be under a specified null hypothesis. A small p-value is often interpreted as evidence against that null hypothesis.
Limitations of relying only on data
The discussion identifies several concerns with a purely data-centered approach:
Data can be noisy.
Data can be biased.
Data may be collected through an experimental design that already reflects human decisions and assumptions.
Very large data sets can produce statistically significant results for extremely small and practically unimportant effects.
A statistically significant relationship does not necessarily establish a causal relationship.
With sufficiently large samples, even a tiny deviation from a null hypothesis can produce a very small p-value. Statistical significance can therefore be separated from practical or scientific importance.
Bayesian advantages
Bayesian methods can:
Represent uncertainty directly with probability distributions.
Incorporate previous knowledge explicitly.
Provide useful estimates even when data are sparse.
Regularize unstable estimates by preventing implausible values.
Make assumptions visible rather than leaving them implicit.
Adapt naturally to complex models and hierarchical structures.
Bayesian methods do not eliminate subjectivity. Instead, they make assumptions explicit so that they can be examined, discussed, and revised.
4. Priors, Bias, and Explicit Assumptions
Priors make hidden assumptions visible
All statistical analyses contain assumptions. Even an analysis that claims to use “only the data” reflects choices about:
What data to collect
Which variables to include
How to measure those variables
Which population to study
How to define the outcome
Which model form to use
How to handle missing observations
These choices can introduce bias without the analyst recognizing it.
A Bayesian prior makes some of these assumptions explicit. Two analysts using the same data may reach different conclusions because they begin with different prior information. Rather than treating that difference as an embarrassment, Bayesian modeling provides a framework for identifying and debating the assumptions responsible for it.
Narrow and broad priors
The width of a prior distribution communicates how much variation is considered plausible.
A narrow prior expresses strong confidence that a parameter lies within a restricted range.
A broad prior expresses less certainty and allows the data to influence the parameter more substantially.
For example, if a model contains one parameter representing a well-established physical fact, that parameter can receive a narrow prior. Other parameters about which less is known can receive wider priors. The strongly constrained parameter can provide a stable reference point that helps the remaining parts of the model behave sensibly.
Priors as regularization
When data are sparse, many parameter values may appear compatible with the observations. A prior can discourage extreme or implausible values. This stabilizes inference and reduces the risk that a small amount of noise will produce an unreasonable estimate.
This is one reason Bayesian models can perform well with fewer data than some purely data-driven methods: prior structure provides information that the data alone cannot supply.
5. Causation, Correlation, and Model Construction
Statistical relationships are not automatically causal
A statistical association between two variables does not determine the direction of causation.
For example, a model may identify a relationship between education and income. A regression of income on education may estimate an effect associated with education. However, simply reversing the variables can still reveal a statistical association. This does not mean that income causes education in the same way that education may influence income.
Correlation can be symmetric, while causal relationships are directional.
Causes are not directly contained in the data
Observed data reveal patterns of association. They do not, by themselves, guarantee a causal explanation. Causal interpretation requires:
A theory about how variables influence one another
Knowledge of the data-generating process
Assumptions about confounding and measurement
A model that encodes causal direction
A statistical model is a simplification and construction of reality. Because the modeler chooses which relationships to represent and how to represent them, the model necessarily contains prior assumptions.
Making these assumptions explicit is especially important in:
Social science
Political science
Economics
Public policy
Other settings where causal mechanisms are not governed by simple physical laws
6. Epistemology and the Scientific Method
Definition of epistemology
Epistemology is the study of how knowledge is obtained, justified, evaluated, and revised.
It asks questions such as:
How does society know that Earth is spherical?
How are theories such as relativity established?
What makes evidence reliable?
How can a claim be tested?
How should beliefs change when new evidence appears?
Epistemology is closely related to philosophy and is concerned with the foundations of scientific knowledge.
Scientific knowledge is reliable but revisable
Science is often treated by the public as an infallible collection of permanent truths. A more accurate view is that science is a body of knowledge that has survived extensive testing and has proven useful, but remains open to revision.
Scientific claims are generally expected to be:
Reliable enough to support prediction and explanation
Reproducible through repeated investigation
Falsifiable, meaning that evidence could in principle show them to be wrong
A scientific model can work extremely well without being the final or perfectly complete description of reality. For example, current theories may support successful aviation and engineering while still leaving unresolved questions in physics.
Science and research
A useful distinction is:
Science: the accumulated body of knowledge that has been developed and supported over time.
Research: the ongoing process through which new knowledge is created, tested, challenged, and added to that body of knowledge.
Research is therefore “science in the making.”
Bayesian updating and intellectual humility
Bayesian reasoning formalizes the idea that knowledge should change in response to evidence. A belief assigned absolute certainty cannot be updated. A more rational position is often very high confidence rather than absolute certainty.
This does not imply that all claims are equally uncertain. Well-supported scientific knowledge may deserve extremely high confidence. However, it remains conceptually distinct from mathematical certainty.
Questioning scientific claims is not automatically anti-scientific. The important issue is whether the questions are investigated through disciplined methods, evidence, reproducibility, and falsifiable hypotheses.
7. Computational Bayesian Inference
Why computation is important
For simple models, Bayesian calculations can sometimes be performed analytically. For realistic models, the posterior often contains difficult integrals, especially in its normalizing denominator:
These integrals are often impossible to solve by hand. Historically, this computational difficulty limited the use of Bayesian statistics, despite the framework’s theoretical appeal.
The development of modern computing changed the situation. Computers can approximate complicated posterior distributions numerically, making Bayesian models practical for real applications.
Markov chain Monte Carlo
Markov chain Monte Carlo, abbreviated MCMC, is one of the main families of algorithms used to approximate posterior distributions.
MCMC generates samples that, after sufficient exploration, represent the shape of the posterior. Analysts can then use these samples to estimate:
Posterior means and medians
Credible intervals
Probabilities of hypotheses
Predictions for new observations
Relationships among parameters
MCMC methods were influenced significantly by work in physics, including statistical physics and computational research associated with the Manhattan Project.
Hamiltonian Monte Carlo
Hamiltonian Monte Carlo, or HMC, is a highly effective MCMC method for many Bayesian models. It uses ideas from physics to move efficiently through parameter space instead of making only small random steps.
HMC is widely used in modern Bayesian software because it can explore complex, high-dimensional posterior distributions more efficiently than simpler MCMC techniques.
The general computational progression is similar to developments in deep learning:
The underlying ideas existed for decades.
Greater computing power made them practical at scale.
Improved algorithms increased efficiency.
Modern software allowed researchers to apply them to complicated real-world problems.
Bayesian methods do not always require enormous data sets, unlike many deep-learning applications. Their computational requirements arise mainly from the complexity of representing and sampling the posterior distribution.
8. Probabilistic Programming Languages and Bayesian Software
Probabilistic programming languages
A probabilistic programming language, or PPL, is software that allows a user to:
Specify a probabilistic or Bayesian model.
Define its variables, distributions, and relationships.
Sample from or approximate the model’s posterior distribution.
PPLs reduce the need to implement every computational detail manually.
Choosing a framework
The most suitable framework often depends on the user’s programming background and the kind of interface that feels intuitive.
R users
Users proficient in R may begin with brms, which provides a high-level interface built on Stan.
It allows users to specify many Bayesian regression models conveniently.
It is useful for learning and for common model structures.
Users can move to Stan directly when they need more control or more complex models.
Python users
Python users may choose among:
PyMC
NumPyro
PyStan
Bambi
PyMC is a flexible Bayesian modeling library that allows users to construct models directly in Python.
NumPyro is another probabilistic programming framework designed for efficient numerical computation, particularly with JAX-based workflows.
Bambi is a higher-level Python interface intended to make Bayesian regression more accessible. It makes many choices automatically, including aspects of prior specification, and is built on top of PyMC.
A typical progression is:
Begin with Bambi for accessible model specification.
Move to PyMC when more control and flexibility are needed.
Use lower-level frameworks or custom implementations for highly specialized models.
The most important criterion is often usability. Bayesian modeling involves repeated experimentation, model checking, and revision. A framework that feels intuitive is easier to use consistently.
9. PyMC and Its Computational Backend
PyMC
PyMC is an open-source platform for constructing and fitting Bayesian models. It supports:
Regression models
Hierarchical models
Time-dependent models
Gaussian processes
Custom probability distributions
Multiple computational backends and samplers
PyMC models can be sampled using different computational engines depending on the structure of the model and the desired performance.
PyTensor
PyTensor is a computational backend used by PyMC. Its main responsibilities include:
Representing model computations as symbolic graphs
Compiling computational operations
Delegating calculations to efficient numerical backends
Supporting optimization of complex model computations
Instead of performing every operation directly in ordinary Python, PyTensor transforms the model into a graph that can be compiled and evaluated more efficiently.
Multiple backends
PyTensor allows PyMC to work with multiple computational backends and samplers. These may include:
C-based computation
Numba-based computation
Rust-based computation
NumPyro and JAX-based computation
A specialized sampler can be selected when it is better suited to the model. For example, Gaussian-process models involve large matrix operations, and some backends handle those computations more efficiently than others.
Why backend choice matters
Different models stress different parts of the computational system. A backend that performs well for an ordinary regression may not be optimal for a Gaussian process involving repeated matrix multiplications.
The ability to switch backends allows the same high-level model to use a more efficient implementation without requiring the modeler to rewrite the entire model.
10. Bayesian Consulting and Real-World Modeling
Bayesian modeling often requires more than selecting a distribution and running a sampler. Real projects can involve challenges such as:
Translating a practical question into a statistical model
Choosing appropriate priors
Handling missing or biased data
Diagnosing nonconvergence
Revising an unsuitable model
Communicating results to non-statisticians
Producing actionable predictions
A Bayesian consulting team may help clients at any stage of this workflow, from initial model design to debugging a model that fails to converge.
Common modeling workflow problems
A client may:
Have a promising question but no model.
Have data but be unsure how to represent the data-generating process.
Have tried several models without obtaining reliable convergence.
Need a Bayesian model but lack the time or resources to hire a full-time specialist.
Need help explaining model results to decision-makers.
Bayesian modeling is therefore both a technical and communication-oriented discipline.
11. Hierarchical Models for Sparse Polling Data
The estimation problem
A polling organization may collect monthly survey data about public opinion on issues such as:
National security
Military policy
Same-sex marriage
Other political or social questions
Clients may want estimates for very specific groups, such as:
Residents of a particular electoral district
Women in a specific age range
People with a particular education level
Demographic subgroups within a region
Direct polling at this level of detail is often impractical because:
It requires large sample sizes.
It is expensive.
Response rates are declining.
Small subgroups may have very few observations.
Polling data may be systematically biased.
Hierarchical modeling
A hierarchical model represents groups as related but distinct.
For example, age groups may have different attitudes, but the model does not assume that they are completely unrelated. Information from one age group can inform estimates for another.
A simplified structure might include:
A population-level effect for the overall issue.
Regional effects.
Age-group effects.
Gender effects.
Education effects.
Interactions among demographic variables.
The model estimates both:
How much groups differ from one another.
How much groups share in common.
This information sharing is called partial pooling. It prevents small groups from producing wildly unstable estimates while still allowing genuine differences between groups.
Why hierarchical models help
Suppose one age group has very little data. A separate model for that group might produce an extremely uncertain or extreme estimate. A hierarchical model can combine:
The observations from that age group
Information from related age groups
Broader population-level patterns
The resulting estimate is usually more stable.
Hierarchical models assume that groups differ, but not infinitely. Related groups share information while retaining their individual characteristics.
12. Post-Stratification
Definition
Post-stratification is a method for adjusting model-based estimates using known population information, often from census data.
After fitting a hierarchical model to survey data, the analyst uses population counts or proportions to reweight the subgroup predictions so that they better represent the actual population.
Basic procedure
Fit a hierarchical model to the available survey observations.
Estimate outcomes for detailed demographic and geographic groups.
Obtain reliable population information for those groups.
Weight each subgroup estimate according to its actual population size.
Aggregate the weighted estimates to produce population-level or region-specific predictions.
Why it is useful
Survey samples may not match the population. For example, a survey might overrepresent older respondents or underrepresent a particular region. Post-stratification adjusts for these differences when reliable population totals are available.
Combined with hierarchical modeling, post-stratification can produce estimates for groups that were not directly sampled in sufficient numbers.
This approach can produce more actionable uncertainty intervals than direct subgroup polling. Although uncertainty remains higher for small or weakly observed groups, the results need not be so broad that they cover nearly every possible opinion.
13. Bayesian Workflow and Model Communication
A Bayesian model is only one component of the full Bayesian workflow.
Before modeling
Important pre-modeling tasks include:
Defining the scientific or practical question
Understanding how the data were generated
Identifying possible sources of bias
Selecting variables and outcomes
Choosing plausible likelihoods
Specifying and evaluating priors
Determining whether the model reflects the intended causal or predictive structure
During modeling
The analyst must:
Fit the model
Monitor sampling behavior
Check convergence
Identify divergences and other warnings
Compare alternative model specifications
Test whether the model reproduces important features of the data
After modeling
Post-modeling tasks include:
Diagnosing the quality of the posterior samples
Visualizing parameter distributions
Generating posterior predictions
Quantifying uncertainty
Checking model adequacy
Interpreting practical consequences
Communicating findings to decision-makers
The final model output is usually consumed by people who do not care about the technical details of sampling. They may be:
Marketing managers
Coaches
Policymakers
Scientists
Executives
Other data scientists
A modeler must therefore translate distributions and uncertainty into explanations and visualizations that support decisions without concealing limitations.
Why visualization matters
Bayesian models produce distributions rather than only single estimates. Graphs help reveal:
The range of plausible parameter values
The degree of uncertainty
Differences between groups
Posterior correlations
Predictive intervals
Model convergence problems
Potentially misleading or unstable results
Effective communication requires explaining both what the model can say and what it cannot say.
14. ArviZ and Post-Modeling Analysis
ArviZ is an open-source library for analyzing and visualizing Bayesian models after sampling.
It supports two major purposes:
Model diagnosis
ArviZ can help identify warning signs such as:
Poor convergence
Inadequate exploration of the posterior
Divergent transitions
Unstable parameter estimates
Problems with effective sample size
Other sampling or posterior-quality issues
A model should not be interpreted simply because a sampler produced output. The quality of that output must be assessed first.
Result presentation
ArviZ also provides plots for communicating results, including visualizations of:
Posterior distributions
Credible intervals
Parameter comparisons
Posterior predictive checks
Group-level effects
Uncertainty in predictions
ArviZ is platform-agnostic. It can work with inference data generated by different probabilistic programming systems, including PyMC, Stan, and NumPyro, provided the results are represented in a compatible inference-data format.
This separation between model fitting and model analysis is useful because the same visualization and diagnostic tools can be applied regardless of which PPL produced the model.
15. Gaussian Processes
Definition and motivation
A Gaussian process, or GP, is a flexible probabilistic model for functions. Rather than specifying a fixed functional form for the relationship between predictors and outcomes, a GP places a probability distribution over possible functions.
A linear regression assumes a structure such as:
A Gaussian process instead represents the relationship more abstractly:
The model then learns a plausible form for f from the data and the prior structure placed on the function.
Parametric versus nonparametric modeling
A linear regression is parametric because it assumes a particular functional form described by a finite set of parameters.
A GP is commonly described as nonparametric because it does not restrict the relationship to a predetermined functional form such as a line or polynomial. The model can represent a broad range of smooth functions.
“Nonparametric” does not mean that the model has no parameters. Gaussian processes still require hyperparameters describing features such as:
Smoothness
Length scale
Variance
Noise
The degree of correlation between nearby inputs
These hyperparameters often require domain knowledge and carefully chosen priors.
Spatial applications
Gaussian processes are particularly useful for spatial data. For example, agricultural yields may vary across a field because of:
Soil composition
Local weather
Moisture
Terrain
Crop interactions
Unmeasured spatial effects
The exact functional relationship between location and crop performance may be unknown. A GP can model spatial correlation and infer how outcomes vary across the field.
A spatial GP can estimate relationships in two dimensions and produce a smooth probabilistic surface rather than requiring the analyst to specify the surface in advance.
Temporal applications
Time is another natural input for a GP. Many time-dependent relationships are nonlinear.
For example, the performance of a baseball player may:
Improve during part of a season
Decline because of fatigue
Fluctuate because of injury
Change in response to competition
Vary according to conditions
A simple linear time trend assumes that the change from time 1 to time 2 is the same as the change from time 9 to time 10. This is often unrealistic. A GP can learn a changing, nonlinear trend without requiring the analyst to specify its exact form.
Spatiotemporal models
Gaussian processes can also model both space and time simultaneously. Such spatiotemporal GPs can represent outcomes that vary across locations and evolve over time.
These models are powerful but computationally demanding because they often involve large covariance matrices and repeated matrix operations.
Relationship to other models
Several familiar models can be understood as special cases or related constructions within the broader mathematical framework of Gaussian processes. The discussion identifies:
Gaussian random walks
Certain neural-network limits or constructions
This makes GPs conceptually important as well as practically useful.
Advantages
Gaussian processes offer:
Flexible nonlinear relationships
Direct representation of uncertainty
Natural treatment of correlation across nearby points
Applications in spatial, temporal, and spatiotemporal settings
A way to learn functional structure rather than impose it
Limitations
Their power creates important responsibilities:
They can be computationally slow.
They involve large covariance matrices.
Their behavior depends strongly on kernel and hyperparameter choices.
They may be difficult for beginners to specify and interpret.
They cannot automatically discover every structure without informative modeling choices.
Domain knowledge is still necessary, particularly for setting priors and selecting suitable covariance structures.
A GP is not a replacement for thinking about the data-generating process. It is a flexible tool whose results still depend on modeling assumptions.
16. Hilbert Space Gaussian Process Approximations
The computational problem
Exact Gaussian-process inference can become slow as the number of observations increases because covariance calculations involve large matrices. Matrix multiplication and factorization can dominate the computational cost.
HSGP approximation
A Hilbert space Gaussian process approximation, abbreviated HSGP, represents a GP using a basis-function decomposition. In simplified terms, the GP is approximated through a finite collection of basis functions and coefficients.
This converts the GP into a form resembling a structured dot product or an expanded regression model while preserving important GP behavior.
The approximation can be represented conceptually as:
where:
ϕj(x) are basis functions.
βj are coefficients.
m is the number of basis functions.
The exact details depend on the chosen domain and approximation, but the main purpose is computational efficiency.
Benefits
HSGP methods can:
Make GP models substantially faster.
Reduce the cost of repeated matrix operations.
Make more complex GP applications practical.
Provide a bridge between Gaussian processes and regression-style computation.
Caveats
HSGP approximations cannot be used blindly. The analyst must consider:
The domain over which the approximation is valid
The number of basis functions
Approximation accuracy
Boundary effects
Kernel properties
Whether the data structure satisfies the method’s assumptions
The method is therefore an approximation rather than an exact replacement for every GP formulation.
17. Key Principles and Applications
The central lessons are:
Bayesian inference combines prior knowledge with observed data.
Uncertainty should be represented directly, rather than reduced immediately to a single estimate.
Priors make assumptions explicit, including assumptions that might otherwise remain hidden.
Sparse or unreliable data do not make inference impossible when meaningful prior structure is available.
Hierarchical models share information across related groups, stabilizing estimates for small subpopulations.
Post-stratification adjusts subgroup predictions using known population information.
Causal direction requires modeling assumptions and cannot be inferred from statistical association alone.
Epistemology examines how scientific knowledge is formed and revised.
Scientific knowledge can be highly reliable without being absolutely infallible.
MCMC and HMC make complex Bayesian models computationally practical.
Probabilistic programming languages simplify model construction and posterior sampling.
PyTensor and specialized backends improve computational efficiency.
ArviZ supports diagnosis and communication after model fitting.
Gaussian processes model complex nonlinear relationships in spatial, temporal, and spatiotemporal data.
HSGP approximations improve the scalability of Gaussian processes, although they require careful use.
The Bayesian workflow extends beyond model fitting to include data understanding, prior specification, diagnostics, prediction, visualization, and communication.
A good Bayesian does not merely produce an estimate. A good Bayesian updates beliefs with new information, represents uncertainty honestly, makes assumptions visible, checks the quality of the model, and communicates conclusions in a form that others can use.

Ask anything
We've read this whole study set, so questions about it get the best answers.