Bayesian Statistics
Bayesian Statistics: Reasoning with Uncertainty, Prior Knowledge, and Limited Data
Bayesian statistics is a framework for learning from data while explicitly representing uncertainty and incorporating relevant prior knowledge. It is especially useful when data are limited, noisy, biased, or unreliable—situations that occur frequently in scientific research, social science, forecasting, marketing, agriculture, sports, and many other fields.
Rather than producing only a single estimate, Bayesian methods describe a range of plausible values and assign probabilities to those possibilities. This makes the results more informative when the available evidence is incomplete.
Why Bayesian Statistics Matters
Many statistical problems begin with an imperfect evidence base. A researcher may have:
- Very few observations
- Measurements containing substantial noise
- Data that do not accurately represent the broader population
- Prior scientific or domain knowledge
- Uncertainty about how variables are related
- A need to make decisions despite incomplete information
Traditional methods often emphasize letting the observed data speak for themselves. That approach can be useful, but it becomes difficult when the data are sparse or systematically biased. Bayesian statistics provides a way to combine the observed evidence with previously available knowledge.
For example, electoral polls are noisy measurements of public opinion. Poll respondents may not represent the entire population, people may answer inaccurately, and only a limited number of polls may be available. At the same time, researchers may know something about historical voting patterns, demographic behavior, or the reliability of different polling organizations. Bayesian modeling allows all of these sources of information to be represented in one framework.
Bayesian statistics combines data with prior information to produce updated probability distributions describing what is plausible after seeing the evidence.
The central advantage is not that Bayesian methods magically eliminate uncertainty. Instead, they represent uncertainty directly and make the assumptions behind the analysis visible.
The Three Main Ingredients of Bayesian Inference
A Bayesian model generally connects three ideas:
- Priors describe what was believed or considered plausible before observing the current data.
- The likelihood describes how probable the observed data are under different possible parameter values.
- The posterior describes what is believed after combining the prior information with the observed data.
This relationship is expressed by Bayes’ theorem:
p(θ∣y)=p(y)p(y∣θ)p(θ)Here:
- θ represents unknown quantities or model parameters.
- y represents the observed data.
- p(θ) is the prior distribution.
- p(y∣θ) is the likelihood.
- p(θ∣y) is the posterior distribution.
- p(y) is the marginal probability of the data and serves as a normalizing quantity.
In words, the posterior combines the prior information with the evidence provided by the data.
Priors
A prior distribution represents assumptions or knowledge available before analyzing the current observations. A prior may be based on:
- Previous studies
- Physical laws
- Historical patterns
- Expert knowledge
- Constraints implied by the problem
- A reasonable assumption that extreme values are unlikely
A prior does not necessarily need to be highly informative. It can be broad when little is known, or narrow when there is strong confidence about a quantity.
For instance, if a parameter represents a physical quantity known with great precision, a narrow prior can prevent the model from wandering toward implausible values. If a relationship is less certain, a wider prior allows the data to exert more influence.
The important point is that the prior is an assumption, and Bayesian modeling encourages that assumption to be stated explicitly.
Likelihood
The likelihood describes how compatible the observed data are with different parameter values. It answers a question such as:
If the parameter had a particular value, how plausible would the observed data be?
The likelihood is not itself a probability distribution over the parameter. Instead, it evaluates how well different parameter values explain the data.
Posterior
The posterior distribution combines the prior and likelihood. It represents the model’s updated uncertainty after observing the data.
If the data are abundant and highly reliable, the likelihood may dominate the posterior. If the data are sparse or noisy, the prior can play a larger role. This is one reason Bayesian methods can perform well with limited data: prior information supplies structure that the data alone may not provide.
Bayesian and Frequentist Perspectives
Bayesian and frequentist statistics answer related but different questions.
A frequentist analysis typically treats parameters as fixed but unknown quantities and evaluates how data would behave under repeated sampling. A Bayesian analysis treats uncertainty about parameters probabilistically and updates that uncertainty using data.
One frequently discussed frequentist quantity is the p-value. A p-value measures how unusual the observed data would be under a specified null hypothesis, or under repeated samples generated according to that hypothesis. It does not directly give the probability that the hypothesis is true.
Bayesian analysis instead produces a posterior distribution. This allows statements such as:
- Which parameter values are most plausible
- How much uncertainty remains
- The probability that a parameter lies within a particular range
- Predictions for future observations
- The probability of a decision-relevant outcome
The difference becomes especially important with very large data sets. With enough observations, even a tiny and practically unimportant effect can produce a statistically significant p-value. Statistical significance alone does not establish that an effect is meaningful or useful.
Bayesian results can also be influenced by the choice of prior. This is not a flaw unique to Bayesian statistics. Every analysis involves assumptions, including assumptions about which variables to measure, how to define them, how to collect data, and which model to use. Bayesian methods make many of those assumptions explicit rather than leaving them hidden.
Prior Information as a Focal Point
Suppose a model includes one parameter whose value is known with high confidence and another parameter about which little is known. A narrow prior on the first parameter can stabilize the model, while a wider prior on the second allows greater flexibility.
This creates a structure in which the uncertain parts of the model are interpreted relative to the better-understood parts. The prior does not simply “override” the data. Instead, it helps define the space of reasonable explanations.
Why Explicit Assumptions Are Valuable
Two researchers can analyze the same data and reach different conclusions because they have different assumptions about the problem. In a Bayesian model, those assumptions can be expressed through different priors.
This makes disagreement more productive. Rather than arguing vaguely about who is biased, researchers can examine:
- Which priors were used
- Why those priors were chosen
- How sensitive the conclusions are to alternative priors
- Whether the data are strong enough to overcome prior differences
This is particularly important in social and political models, where assumptions about causality and group behavior are rarely purely objective.
A major strength of Bayesian modeling is that it turns hidden assumptions into explicit, inspectable parts of the analysis.
Epistemology and Scientific Knowledge
Epistemology is the study of how knowledge is obtained and justified. In scientific contexts, it asks questions such as:
- How can a claim be supported by evidence?
- What makes a method reliable?
- How should beliefs change when new information appears?
- What makes a hypothesis scientific?
- How can knowledge be reproducible and falsifiable?
Scientific knowledge is not necessarily a collection of permanently infallible truths. It is better understood as the best-supported understanding available at a particular time, based on current evidence and methods.
A scientific claim should remain open to revision if new evidence appears. This does not mean that every claim is equally uncertain. Some conclusions are supported by overwhelming evidence, while others are tentative. Bayesian reasoning provides a mathematical language for representing these different levels of confidence.
For example, assigning a prior probability of exactly 0 or exactly 1 to a possibility prevents ordinary Bayesian updating from changing that belief. If a hypothesis has prior probability 0, then multiplying by the likelihood still produces probability 0. If it has prior probability 1, competing possibilities remain excluded.
Therefore, absolute certainty can prevent learning. A belief assigned probability 0.999 can still be revised; a belief assigned probability 1 cannot be updated through ordinary Bayesian inference.
This illustrates a broader principle:
Scientific reasoning requires confidence proportional to the evidence, while still leaving room for revision when genuinely new evidence appears.
Models, Data, and Causality
A statistical relationship does not automatically reveal a causal relationship.
Suppose a data set shows an association between education and income. A statistical model may find that the two variables are related. However, the causal interpretation requires additional reasoning about how the variables influence one another.
A statistical association may be examined in either direction, but causality is directional. The fact that two variables are related does not by itself establish whether:
- Education causes changes in income
- Income influences educational opportunities
- A third factor influences both
- The relationship results from selection or bias
Causal relationships are not simply visible in a table of data. They depend on assumptions about the underlying process that generated the data.
A model is therefore more than a mechanical summary of observations. It is a simplified construction of reality. Choosing variables, specifying relationships, and deciding which direction an influence operates all involve assumptions.
Bayesian modeling is useful here because it provides a formal way to state and examine those assumptions. However, Bayesian computation alone cannot guarantee that a causal interpretation is correct. The causal structure must still be justified using subject-matter knowledge and research design.
Think About It
If two researchers use the same data but specify different causal assumptions, should their models necessarily produce the same conclusions? What assumptions would need to be made explicit before the results could be compared fairly?
Bayesian Computation
Why Computation Is Necessary
Bayesian inference often requires calculating a posterior distribution. In simple models, this can sometimes be done analytically. In realistic models, however, the normalizing quantity in Bayes’ theorem involves a difficult integral:
p(y)=∫p(y∣θ)p(θ)dθFor complex models, this integral may not have a closed-form solution. As a result, the posterior cannot be calculated directly with ordinary algebra.
Modern Bayesian statistics became much more practical because computers can approximate posterior distributions numerically. Instead of calculating every quantity exactly, algorithms generate representative samples from the posterior.
These samples can then be used to estimate:
- Posterior means and medians
- Credible intervals
- Probabilities of events
- Predictions
- Relationships among parameters
- Uncertainty in model outputs
Markov Chain Monte Carlo
Markov chain Monte Carlo, or MCMC, is a family of algorithms used to approximate complicated probability distributions.
The basic idea is to construct a sequence of parameter values—a chain—that spends more time in regions where the posterior probability is high. After the algorithm has explored the parameter space, the sampled values approximate the posterior distribution.
MCMC became an important computational tool partly through developments connected to physics and wartime scientific research. It has since become one of the standard approaches for fitting Bayesian models.
Hamiltonian Monte Carlo
Hamiltonian Monte Carlo, or HMC, is a more efficient MCMC method for many continuous Bayesian models. It uses information about the geometry of the posterior distribution to make longer, more purposeful movements through parameter space.
This is more efficient than moving through the space using only small random steps. HMC is used by major Bayesian tools such as PyMC and Stan, and related implementations are available through other computational backends.
The broader lesson is that Bayesian modeling depends not only on the statistical model but also on the algorithms used to explore its posterior distribution.
Probabilistic Programming
A probabilistic programming language, or PPL, is software that allows a modeler to write a probability model and obtain samples from its posterior distribution.
A PPL typically helps with several tasks:
- Defining random variables and their probability distributions
- Expressing relationships among variables
- Specifying priors and likelihoods
- Running posterior sampling algorithms
- Organizing the resulting draws
- Supporting model diagnostics and visualization
Different tools are suited to different programming backgrounds and modeling goals.
Common Entry Points
For users working in R, a high-level interface such as brms provides access to Bayesian modeling through Stan. It allows users to specify many models without writing every computational detail directly.
For users working in Python, Bambi offers a similarly accessible high-level interface. It makes many default decisions automatically, including some choices involving priors, which can make the first steps less intimidating.
As models become more specialized or complex, users may move to lower-level frameworks:
- Stan provides a powerful general-purpose Bayesian modeling system.
- PyStan allows Python users to access Stan.
- PyMC provides a flexible Python framework for writing and sampling Bayesian models.
- NumPyro is another Python-based probabilistic programming tool.
The practical recommendation is to begin with the framework that matches the user’s programming environment and feels most intuitive. Bayesian modeling involves repeated model development, debugging, checking, and revision, so comfort with the framework matters.
A high-level tool can be useful at the beginning because it reduces the number of decisions the learner must make. A lower-level tool becomes valuable when greater control is needed.
PyMC and Its Computational Backends
PyMC is an open-source Python framework for Bayesian statistical modeling. It allows a modeler to define a probabilistic model and draw samples from the posterior distribution.
PyTensor
PyMC uses PyTensor as a computational backend. PyTensor represents a model as a symbolic computational graph. Rather than performing every calculation directly in ordinary Python, it can compile and optimize the mathematical operations required by the model.
This separation helps PyMC:
- Represent complex models efficiently
- Optimize repeated calculations
- Delegate operations to specialized computational systems
- Support multiple sampling backends
- Improve performance for demanding models
The modeler usually interacts with PyMC rather than writing PyTensor operations directly. PyTensor performs much of the computational work underneath the visible modeling interface.
Multiple Backends
PyMC can work with different computational backends and samplers. These may use technologies such as:
- C
- Numba
- Rust
- JAX
- NumPyro
The purpose of multiple backends is to make computation faster and more scalable for different kinds of models.
For example, some models involve large matrix operations. Gaussian processes are a particularly important case because they often require matrix multiplication and matrix-related calculations. A backend that handles these operations efficiently can substantially improve sampling speed.
The best backend may depend on the model’s structure. One backend may perform especially well for ordinary models, while another may be more efficient for Gaussian-process models.
The Bayesian Workflow
A Bayesian analysis is not finished when the model has been specified or when posterior samples have been generated. Modeling is only one part of a larger Bayesian workflow.
The workflow includes activities before, during, and after sampling:
- Understanding the data
- Choosing variables and transformations
- Specifying a model
- Selecting priors
- Fitting the model
- Diagnosing sampling
- Checking whether the model represents the data adequately
- Summarizing uncertainty
- Communicating results
- Making predictions or decisions
Post-modeling work is especially important because the model’s results are usually consumed by people who are not statisticians. A client may care about a business decision, a policy question, a marketing outcome, or a sports prediction—not about the technical details of the sampler.
Model Diagnostics
A fitted model must be checked for warning signs. Diagnostics can reveal problems such as:
- Poor convergence
- Inadequate exploration of the posterior
- Sampling irregularities
- Implausible parameter behavior
- A model that does not represent the observed data well
A model that produces numerical output is not automatically a trustworthy model. Sampling must be inspected before the results are interpreted.
Communicating Posterior Distributions
Bayesian models produce distributions rather than only single estimates. This means that a result should communicate both:
- The central tendency or most plausible region
- The remaining uncertainty
Plots are particularly helpful because distributions, intervals, and predictive outcomes are easier to understand visually than through long tables of numbers.
A useful graph can help a decision-maker understand:
- Which values are plausible
- How uncertain the result is
- Whether two groups differ meaningfully
- How predictions change across conditions
- Whether the model contains diagnostic warnings
ArviZ
ArviZ is a library for Bayesian post-modeling analysis and visualization. It supports tasks such as:
- Inspecting posterior distributions
- Diagnosing convergence
- Plotting parameter uncertainty
- Comparing model results
- Communicating model outputs
ArviZ is designed to work across different probabilistic programming frameworks. If model output is converted into a common inference-data format, ArviZ can analyze it regardless of whether the model was fitted with PyMC, Stan, or another compatible tool.
This makes ArviZ useful as a separate layer in the workflow. The modeling framework handles model construction and sampling, while ArviZ helps examine and communicate the results.
A Bayesian model is only as useful as the reasoning, diagnostics, and communication that surround it.
Think About It
Why might a technically correct posterior distribution still lead to poor decisions if it is presented without diagnostics or an understandable visualization?
Hierarchical Models
A hierarchical model represents groups that are distinct but related. It allows information to be shared across groups without assuming that all groups are identical.
Consider demographic groups divided by age. A model could estimate opinions separately for ages 16–24, 25–34, and other age ranges. A completely separate model for each group might be unstable when the sample sizes are small. A model that forces all groups to be identical would ignore genuine differences.
A hierarchical model takes a middle position:
- Each group has its own parameters.
- The group parameters are related through a higher-level distribution.
- The degree of similarity among groups is estimated by the model.
In effect, information from one group can help inform another group, while the groups are still permitted to differ.
This is particularly valuable when some subgroups contain little data. The model can partially pool information across related groups, producing more stable estimates than either complete separation or complete pooling.
Case Study: Estimating Public Opinion in Estonia
An NGO in Estonia collected monthly polling data about public and political questions. The questions could concern issues such as:
- Whether the country should increase the number of soldiers near its border
- Whether same-sex marriage should be legal
- Other current social and political topics
The organization’s clients wanted more detailed estimates than the surveys could directly provide. They wanted to know how opinions differed across:
- Geographical or electoral districts
- Age groups
- Sex or gender groups
- Education groups
- Combinations of these characteristics
Directly polling every demographic combination in every district would require a very large and expensive sample. Many of the resulting subgroups would have very little data.
Step 1: Build a Hierarchical Population Model
The hierarchical model represents demographic groups as related. For example, the opinions of people aged 16–24 and people aged 25–34 are not assumed to be identical, but they are also not assumed to be completely unrelated.
The model estimates how much these groups resemble one another. If the data suggest that age groups behave similarly, information is shared more strongly. If the data support larger differences, the groups are allowed to diverge more.
Step 2: Use Post-Stratification
After estimating opinions for demographic groups, the analysis applies post-stratification. This process adjusts model estimates using known population information, often from census data.
The purpose is to make the model’s estimates better reflect the actual composition of the population. For example, if a survey contains too many people from one demographic group and too few from another, census information can be used to reweight the estimates.
Conceptually, the process is:
- Estimate outcomes for demographic cells.
- Determine how common each cell is in the real population.
- Weight the cell-specific estimates according to those population proportions.
- Aggregate the weighted estimates for a district or target population.
The combination of hierarchical modeling and post-stratification allows estimation for detailed groups that were not directly surveyed in large numbers.
Why the Method Is Useful
The resulting estimates are uncertain, but they can be more actionable than extremely wide ranges that cover nearly every possibility. The method does not pretend that sparse data are perfectly precise. Instead, it uses:
- Information shared across related groups
- Population information from census data
- Explicit uncertainty estimates
- A model that accounts for demographic structure
This approach is an example of how Bayesian methods can extract useful information from limited polling data without treating small subgroup samples as if they were highly reliable on their own.
Gaussian Processes
A Gaussian process, or GP, is a flexible probabilistic model for functions. It is particularly useful when the relationship between inputs and outcomes is expected to be complex or nonlinear, but the precise functional form is unknown.
Parametric Versus Nonparametric Modeling
A linear regression assumes a particular relationship, such as:
y=a+bxHere, a is an intercept and b is a slope. The model assumes that the effect of x on y follows a straight-line form.
A Gaussian process instead represents the relationship more generally:
y=f(x)The function f is not fixed in advance as linear, quadratic, or another specific form. The Gaussian process places a probability distribution over possible functions and uses the data to determine which functions are plausible.
This is why Gaussian processes are often described as nonparametric. They do not require the modeler to specify a fixed finite-dimensional functional form in advance.
Nonparametric does not mean “assumption-free.” Gaussian processes still require important choices about how nearby observations relate to one another and about the scale and smoothness of the function. Domain knowledge remains valuable.
Spatial Data
Gaussian processes are useful for spatial data because the relationship between location and outcome may not follow a simple known formula.
For example, crop performance across a field may depend on:
- Location
- Soil conditions
- Weather
- Unobserved interactions among environmental factors
A linear model may be too rigid if nearby locations influence one another in a complicated way. A spatial Gaussian process can model how outcomes vary across a two-dimensional field while learning the structure of that variation from the data.
The model can represent correlations between locations and infer a smooth or structured spatial surface, depending on its assumptions.
Time-Dependent Data
Gaussian processes can also model changes over time. Time is often treated as one-dimensional, but temporal patterns are frequently nonlinear.
For example, a baseball player’s performance may fluctuate throughout a season. A simple linear trend assumes that the change from time 1 to time 2 is equivalent to the change from time 9 to time 10. Real performance may instead rise, fall, stabilize, or fluctuate in a much more complicated way.
A Gaussian process can infer a flexible time-dependent function without requiring the modeler to specify its exact shape in advance.
Gaussian processes can also be extended to multiple dimensions, including spatiotemporal models that represent variation across both location and time.
Relationships to Other Models
Several familiar models can be understood as special cases or related forms of Gaussian-process models. Examples include:
- Gaussian random walks
- Certain neural-network limits or formulations
- Other models representing smooth functions over inputs
This makes Gaussian processes mathematically broad and conceptually powerful. They provide a common framework for describing uncertain functions.
Strengths and Limitations
Gaussian processes offer:
- Flexible nonlinear relationships
- Natural uncertainty estimates
- Spatial and temporal modeling
- A way to learn functional structure from data
- A principled framework for correlations among observations
However, they also involve challenges:
- They can be computationally expensive.
- They often require large matrix operations.
- Their parameters can be difficult to choose and interpret.
- They require domain knowledge about smoothness, scale, and correlation.
- They are not appropriate for every problem.
A flexible model is not automatically a better model. Gaussian processes should be used when their assumptions and computational demands match the problem.
Hilbert Space Gaussian Process Approximations
A major computational difficulty with Gaussian processes is that they often require expensive matrix calculations. As the number of observations grows, these calculations can become slow.
A Hilbert space Gaussian process approximation, or HSGP, represents a Gaussian process through a finite basis expansion. In simplified terms, it turns the process into a set of basis functions and coefficients whose combination approximates the original GP.
This can make the computations resemble a structured linear model while preserving important properties of a Gaussian process. The resulting representation can be much faster to sample than a direct implementation involving very large covariance matrices.
The approximation is useful because it can:
- Reduce computational cost
- Improve sampling speed
- Make some Gaussian-process models more practical
- Provide a bridge between flexible function modeling and efficient linear algebra
HSGP methods are not universally applicable. They involve approximation choices and have caveats concerning the domain, boundary behavior, and the adequacy of the chosen basis. Their use requires checking whether the approximation is accurate for the specific problem.
The general computational lesson is that an elegant statistical model may need a carefully chosen approximation before it becomes practical at scale.
Think About It
A linear model is easier to compute but may be too rigid. A full Gaussian process is more flexible but can be expensive. What kinds of evidence would justify accepting the additional complexity of a GP or an HSGP approximation?
Applications Across Fields
Bayesian methods are not restricted to one discipline. The same general framework can be adapted to many settings:
- Electoral forecasting: Combining noisy polls with historical and demographic information
- Marketing: Estimating the effects of advertising and other media
- Agriculture: Modeling spatial variation in fields and crop outcomes
- Sports: Estimating player performance and nonlinear seasonal changes
- Social science: Modeling differences among demographic or geographical groups
- Political science: Representing uncertain relationships and changing public opinion
- Scientific research: Incorporating prior knowledge and quantifying uncertainty
- Business decision-making: Producing probabilistic predictions rather than single-point forecasts
The flexibility comes from the fact that Bayesian statistics is a framework rather than a single model. The likelihood, priors, hierarchical structure, and computational methods can all be adapted to the problem.
A Practical Learning Path
A learner beginning Bayesian statistics benefits from progressing from simpler models to more flexible ones.
A practical sequence is:
- Review basic regression concepts.
- Learn the roles of priors, likelihoods, and posteriors.
- Fit simple Bayesian regression models.
- Practice interpreting posterior distributions and credible intervals.
- Learn model diagnostics and posterior predictive checking.
- Explore hierarchical models and partial pooling.
- Study specialized models such as Gaussian processes.
- Learn how computational backends and approximations affect performance.
- Practice communicating results to nontechnical audiences.
High-level tools such as Bambi or brms can reduce the initial programming burden. More flexible systems such as PyMC or Stan become useful when the model requires custom structure or more direct control.
The framework matters, but the deeper skill is learning to think probabilistically: identifying uncertainty, stating assumptions, updating beliefs, checking models, and communicating what the model can and cannot establish.
Comprehensive Review
Bayesian statistics is a method for updating uncertainty in light of evidence. It combines prior information with a likelihood for the observed data and produces a posterior distribution.
Its advantages are especially clear when data are sparse, noisy, biased, or unreliable. Instead of relying only on imperfect observations, Bayesian models allow relevant prior knowledge to provide structure. At the same time, priors make assumptions explicit, which supports more honest discussion and sensitivity analysis.
Bayesian reasoning also clarifies the difference between statistical association and causation. Data can reveal patterns, but causal direction requires assumptions about how the world works. A model is therefore a purposeful simplification of reality, not a complete replacement for scientific reasoning.
Modern computation makes complex Bayesian models practical. MCMC methods, especially Hamiltonian Monte Carlo, approximate posterior distributions that cannot be calculated analytically. Probabilistic programming languages such as PyMC and Stan allow modelers to express these models in code, while computational backends such as PyTensor, NumPyro, JAX, Numba, and Rust can improve efficiency.
A complete Bayesian workflow extends beyond fitting a model. It includes data preparation, prior selection, model construction, sampling, diagnostics, posterior checking, visualization, and communication. Tools such as ArviZ help reveal convergence problems and present uncertainty clearly.
Hierarchical models allow related groups to share information while remaining distinct. Combined with post-stratification and census data, they can turn limited survey observations into useful estimates for detailed demographic and geographical groups.
Gaussian processes extend Bayesian modeling to unknown nonlinear functions. They are valuable for spatial, temporal, and spatiotemporal data, although their computational demands require care. HSGP approximations can make some Gaussian-process models faster by representing them through finite basis expansions.
The central principle is simple but powerful: Bayesian analysis does not require certainty before learning. It begins with uncertain beliefs, combines them with evidence, checks the resulting model, and produces updated predictions that remain honest about what is still unknown.

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