Modelcore
Bayesian linear regression
Also called conjugate normal linear model.
Linear regression with a normal or normal-inverse-gamma prior on the coefficients and variance. The posterior and predictive laws are in closed form.
Bayesian linear regression is the linear model with normal errors, together with a prior on the coefficients and, if it is unknown, on the error variance . With a normal prior on and known , or a normal-inverse-gamma prior on , the prior is conjugate: the posterior is in the same family, and the posterior predictive distribution of a new response is normal or Student t, all in closed form. With the prior and known the posterior mean is the ridge regression estimate with , and with the prior proportional to the credible intervals have the numbers of the least squares t intervals.
The machine
The data are responses and an design matrix of fixed covariates, with rank unless the prior is proper. Given the parameters,
So . The model is the same as for ordinary least squares; what is new is a prior, and three standard choices give closed forms.
- Known variance, normal prior. is known and with positive definite.
- Normal-inverse-gamma prior. and inverse gamma with shape and scale , so the prior density of is proportional to . The prior variance of scales with , which is what makes it conjugate.
- The reference prior. on , an improper prior. The posterior is proper when has rank , and the residuals are not all 0.
The conditions are those of the linear model: the mean is linear in , the errors are independent with equal variance and normal, and is treated as fixed (or the analysis is conditional on it). A new response at covariate row is with independent of given the parameters.
What it counts
The parameters are and . The model gives, in closed form:
- the posterior law , its mean, covariance and marginals, and so credible intervals for each coefficient and for each mean response ;
- the posterior predictive law of a new response at , which adds the noise to the uncertainty in ;
- the marginal likelihood , used to compare designs, to choose prior scales and to compare models.
The arithmetic cost is that of least squares: forming and takes operations, one Cholesky factorization of the posterior precision matrix takes , and each predictive mean and variance then takes . No step needs an explicit matrix inverse.
Relation to other models
Ridge regression and Tikhonov regularization. Under prior 1 with and , the posterior mean and mode are
the ridge estimate, which is Tikhonov regularization with an identity operator. The penalty is times the log prior, up to a constant. The Bayesian model adds a covariance to the point estimate. A prior with shrinks the intercept as well; to leave it unshrunk, give it a flat prior or center and the columns of .
Gaussian processes. If , the function of a feature vector is a Gaussian process with covariance . The predictive law of this model is the Gaussian process regression predictive law with that kernel, by the Woodbury identity. The first form costs and the second , so the form with the smaller of and is cheaper.
The Kalman filter. Under prior 1 the posterior after is the prior for , and the update for one row is a rank-one correction of and . This is the Kalman filter for a state that does not change in time, observed through ; it is also recursive least squares.
Hierarchical and mixed models. Lindley and Smith (1972) put normal priors on in stages, so that the prior mean of has its own normal prior. A linear mixed model has the same structure for a subset of the coefficients, the random effects, whose prior variance is estimated. Choosing and by maximizing is empirical Bayes, called the evidence approximation in machine learning.
Generalized linear models. For a binary or count response the normal likelihood is replaced and conjugacy is lost; the posterior then needs a Laplace approximation, Markov chain Monte Carlo or variational methods.
Known results in the model
Known variance and normal prior
Under prior 1, completing the square in in gives the posterior
Precisions add, and the posterior mean is a precision-weighted combination of the prior mean and, when has rank , the least squares estimate , since . The predictive law of at is
where is the noise and is the uncertainty about the mean. The marginal law of the data is , and its density at the observed is the marginal likelihood.
A hand example. Take , , the model with , and the prior , so . Here and . The least squares estimate is . The posterior mean is , equal to ; both coefficients move a little toward 0. The posterior standard deviations are 0.37947 and 0.15572, with correlation . At the predictive law has mean 5.99668 and standard deviation 0.72197, so the 95% predictive interval is . A one-coefficient version, with the same data, and prior , has posterior mean 1.3338877 and variance 0.0083160 in closed form; a direct numerical integration of the unnormalized posterior on 200000 equal steps of gives the same values to 7 digits.
Unknown variance and normal-inverse-gamma prior
Under prior 2 the posterior is again normal-inverse-gamma:
Integrating out gives the marginal posterior of as a multivariate Student t with degrees of freedom, location and scale matrix . The predictive law of is Student t with degrees of freedom, location and squared scale . Its tails are heavier than those of the normal predictive law because is uncertain. The posterior mean of is when . The marginal likelihood is
The same example. With , , : , , and . The least squares residual variance is only with degrees of freedom; the prior with carries the weight of about observations with squared error 1, and it pulls up. The 95% interval for the slope from the marginal is , and the 95% predictive interval at , from with location 6.00893 and scale 0.87236, is . For a one-coefficient check, with and inverse gamma, the t density of agrees with a numerical integration of the joint posterior (2001 points in by 1801 points in ) to about 1 part in at 5 points.
The prior proportional to 1/sigma^2
Prior 3 is the limit of prior 2 as , and . With ,
and given is chi-square with degrees of freedom. The posterior mean of is the least squares estimate, and the equal-tailed 95% credible interval for is . In the example it is for the slope, with , and .
Frequentist properties of the same numbers
The statements above are posterior probabilities given . Statements about repeated samples at a fixed are different and are listed separately.
- Under prior 3 the credible intervals for and the predictive intervals have the same numbers as the classical t confidence and prediction intervals, so their coverage at every fixed is exactly 95% when the model holds. This is an exact agreement for this prior and model only.
- Under prior 1 with and , the posterior mean has expectation , so it is biased toward 0 for every , and covariance , which is smaller than the least squares covariance . Least squares is the best linear unbiased estimator by the Gauss-Markov theorem; the posterior mean is not unbiased, so the theorem does not rank them.
- The credible intervals under a proper prior have no exact coverage guarantee at a fixed . As with fixed and converging to a positive definite matrix, the prior's effect vanishes and they become asymptotic confidence intervals by the Bernstein-von Mises theorem.
Computation and checks
- Compute by solving with the Cholesky factor of the left matrix, and get as the squared norm of the solution of one triangular system. When is ill conditioned, the QR decomposition of stacked on a square root of is more accurate than forming .
- The posterior under prior 3 exists only if has full column rank and ; with a proper prior on is required, as for ridge regression.
- The marginal likelihood under an improper prior is defined only up to a constant, so it cannot compare models; the Bayesian information criterion is its large-sample approximation for proper priors.
References
- D. V. Lindley and A. F. M. Smith, Bayes estimates for the linear model, Journal of the Royal Statistical Society B 34(1), 1972, pages 1 to 41, with discussion (the normal linear model with normal priors in stages, and the posterior mean as a weighted combination of least squares and prior means)
- Andrew Gelman, John B. Carlin, Hal S. Stern, David B. Dunson, Aki Vehtari and Donald B. Rubin, Bayesian Data Analysis, 3rd edition, CRC Press, 2013, Chapters 2 and 3 (conjugate normal models, the normal-inverse-chi-square prior and the t marginal) and Chapter 14 (the regression model under the prior proportional to 1/sigma^2, with its t posterior and predictive laws)
- Christopher M. Bishop, Pattern Recognition and Machine Learning, Springer, 2006, Section 3.3 (Bayesian linear regression with known noise, the parameter posterior and the predictive distribution) and Section 3.5 (the evidence approximation)
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag PQS5CE Edit this page History Report an error Markdown