Bayesian Linear Regression

Statistics
Introduced by
Thomas Bayes / Pierre-Simon Laplace (foundations); modern workflow codified by Gelman et al.
Year
2013 (modern reference); foundations 18th–19th century
Type
Bayesian linear model

What does it do?

Bayesian linear regression models a continuous outcome as a linear function of predictors with normally distributed errors, as in ordinary least squares, but treats the coefficients and the error variance as random quantities with prior distributions.

Bayes' rule combines these priors with the likelihood of the observed data to give a joint posterior distribution, from which credible intervals and posterior predictive distributions are obtained. The foundations go back to Bayes and Laplace, and the applied workflow is presented in Gelman et al. (2013).

The intuition behind the method

Before any data are seen, each coefficient has a prior distribution describing which values are plausible. Bayes' rule updates this prior into a posterior distribution once the data are observed. Coefficients that the data constrain strongly end up with narrow posteriors, while coefficients the data say little about stay close to their priors. Predictions inherit this uncertainty: the posterior predictive distribution reflects both the uncertainty in the coefficients and the residual noise.

History

The theoretical basis goes back to Thomas Bayes's posthumous essay (1763) and to Pierre-Simon Laplace's development of inverse probability in the early nineteenth century. The applied workflow used here, which covers specifying priors, sampling the posterior by Markov chain Monte Carlo, checking convergence, and running prior-sensitivity and posterior predictive checks, is presented in Gelman, Carlin, Stern, Dunson, Vehtari and Rubin's Bayesian Data Analysis (3rd ed., CRC Press, 2013).

When to use it

Choose this method when the sample is small or sparse and a justified prior can stabilise coefficient estimates, when prior information from earlier work should be included formally, or when the full posterior distribution of coefficients and predictions is needed rather than a point estimate with a standard error. The model assumes a continuous outcome with a linear mean and normal errors of constant variance; if these assumptions are doubtful, a model with a different likelihood is more appropriate. Avoid it when no prior knowledge exists and the sample is large, since ordinary least squares then typically gives very similar answers with less computation. It also requires time to specify priors, verify MCMC convergence and run prior-sensitivity analysis, so it should not be used when those steps cannot be carried out.

Limitations and considerations

  • In small samples, particularly when the number of observations is not large relative to the number of coefficients plus σ², the posterior can be dominated by the prior and the data contribute little information.
  • Results depend on the prior choice; if the posterior shifts noticeably under reasonable alternative priors, the conclusions are not robust.
  • Outside conjugate prior choices the posterior has no closed form, so fitting requires MCMC or variational approximation. This is slower than the ordinary least-squares solution and adds convergence diagnostics to the workflow.
  • The normal likelihood with constant error variance is inherited from the linear model, and the Bayesian framework does not relax this assumption by itself.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Gives a full posterior distribution for each coefficient, so a 95% credible interval can be read as a direct probability statement about the parameter, given the prior and the data.
  • Prior information from earlier studies enters the analysis explicitly, which can stabilise coefficient estimates when the data alone are limited.
  • Produces posterior predictive distributions for new observations that combine coefficient uncertainty with residual error variance σ².
  • Estimates the error variance σ² jointly with the coefficients, so its uncertainty propagates into both coefficient intervals and prediction intervals.

Applications

  • Modelling a continuous outcome from a small or sparse sample, where a justified prior can stabilise the coefficient estimates.
  • Analyses that formally incorporate effect sizes or prior estimates from earlier studies.
  • Prediction problems where a distribution over new outcomes is required rather than a single predicted value.
  • Reporting coefficient effects as credible intervals alongside, or in place of, frequentist confidence intervals.
  • Sensitivity studies that compare how conclusions change across alternative priors on the coefficients and the error variance.

How it works

How it works

1

The core relation is Bayes' rule. The posterior distribution of the parameters given the data is proportional to the likelihood, which measures how well a parameter setting explains the observed outcomes, multiplied by the prior, which encodes beliefs about the parameters before the data are seen. The normalising constant is needed for a proper probability distribution, and it is generally intractable for this model except in special conjugate cases.

Formula
p(\boldsymbol{\theta}\mid\mathbf{y}) \propto p(\mathbf{y}\mid\boldsymbol{\theta})\,p(\boldsymbol{\theta})
2

The likelihood assumes each outcome is normally distributed around the linear predictor Xβ with constant error variance σ², the same mean structure used in ordinary least-squares regression. Predictors enter through the design matrix X. Categorical variables are represented by dummy (indicator) columns, each with its own coefficient, and binary predictors are coded in the same way. Because the normal error distribution is built into this likelihood, departures from it are not handled by the Bayesian framework itself and would require a different model. The coefficients are treated as random variables with a prior; the library treatment of Bayesian linear regression places a Gaussian prior, p(θ) = N(m0, S0), on the parameter vector (Deisenroth, Faisal and Ong, 2020), and a Normal prior on β is the common choice. Priors on continuous predictors are usually set on standardised variables, with the prior scale stated explicitly, because a coefficient's scale depends on the units of its predictor. Giving dummy-coded and continuous coefficients priors on comparable scales keeps the prior assumptions consistent across the model. For the error variance, use a Half-Normal prior on the standard deviation σ, or an Inverse-Gamma prior on σ².

Formula
\mathbf{y} \sim \mathcal{N}(\mathbf{X}\boldsymbol{\beta},\,\sigma^2\mathbf{I})
3

Multiplying the likelihood by the priors gives the joint posterior over β and σ². When the coefficients and the error variance are given independent priors, p(β)p(σ²), the joint posterior generally has no closed form. It is then typically explored by sampling with Markov chain Monte Carlo, such as NUTS or Hamiltonian Monte Carlo, or approximated with variational inference. A closed form is available only under conjugate choices, such as a Normal-Inverse-Gamma prior, in which the prior on β is conditional on σ² (β | σ² ~ Normal, σ² ~ Inverse-Gamma). That is a hierarchical specification rather than an independent-prior one. Chains must be checked for convergence using R-hat, where values close to 1 indicate agreement among chains, and effective sample size before posterior means, medians and 95% credible intervals are reported.

Formula
p(\boldsymbol{\beta}, \sigma^2 \mid \mathbf{y}) \propto p(\mathbf{y} \mid \boldsymbol{\beta}, \sigma^2)\, p(\boldsymbol{\beta})\, p(\sigma^2)

Common pitfalls

  • Reporting posterior summaries before checking MCMC convergence through R-hat, effective sample size and trace plots.
  • Using a strong or poorly calibrated prior that overrides the data, especially when the sample is small.
  • Skipping prior-sensitivity analysis and posterior predictive checks, which are needed to judge whether the chosen priors and the normal-error likelihood are adequate.
  • Reading a 95% credible interval as a frequentist confidence interval; the two answer different questions.
  • Applying the method when the sample is small relative to the number of parameters (the coefficients plus σ²), where the posterior is largely prior-driven and carries little empirical content.

Frequently asked questions

What is the difference between a credible interval and a confidence interval?

A 95% credible interval is a direct probability statement: given the data and the prior, there is a 95% probability that the parameter lies within that range. A frequentist 95% confidence interval is a statement about long-run procedure coverage — if the same experiment were repeated many times, 95% of such intervals would contain the true value — not a probability statement about any single interval. Reading a credible interval as a confidence interval, or vice versa, is a common and consequential error.

How should I choose a prior distribution?

Use an informative prior when you have genuine prior knowledge to encode — for example, from a previous meta-analysis or domain expertise. Use a weakly informative prior when you mostly want to let the data speak while preventing the sampler from exploring implausible regions. Whichever prior you choose must be explicitly justified in your report, and you should run a prior-sensitivity analysis: if the posterior shifts substantially with reasonable changes to the prior, the conclusion is not robust.

What are MCMC, NUTS, and R-hat, and why do they matter?

Markov chain Monte Carlo (MCMC) is a family of algorithms for drawing samples from the posterior when it cannot be computed analytically. NUTS (No-U-Turn Sampler) and Hamiltonian Monte Carlo are efficient MCMC algorithms widely used in Bayesian regression software. R-hat (also written R̂) compares the variance within chains to the variance between chains; values close to 1.0 indicate that the chains have converged to the same distribution. The report should state the convergence criterion used, together with an adequate effective sample size (ESS). Without convergence checks, the posterior summaries cannot be trusted.

When does Bayesian linear regression agree with ordinary least squares?

With a large sample and flat (non-informative) priors, the posterior mean and 95% credible interval of each coefficient typically coincide closely with the OLS point estimate and 95% confidence interval. The two methods diverge when the sample is small, when an informative prior is used, or when the analyst needs the full posterior distribution rather than a single-number summary.

Related methods

Sources

  1. Gelman, A., Carlin, J. B., Stern, H. S., Dunson, D. B., Vehtari, A. & Rubin, D. B. (2013). Bayesian Data Analysis (3rd ed.). CRC Press.

    ISBN: 978-1439840955
  2. Deisenroth, M. P., Faisal, A. A. & Ong, C. S. (2020). Mathematics for Machine Learning (library title recorded as "Mathematic for Machine Learning"), p. 304