Bayesian linear regression explained

Bayesian linear regression is a type of conditional modeling in which the mean of one variable is described by a linear combination of other variables, with the goal of obtaining the posterior probability of the regression coefficients (as well as other parameters describing the distribution of the regressand) and ultimately allowing the out-of-sample prediction of the regressand (often labelled

y

) conditional on observed values of the regressors (usually

X

). The simplest and most widely used version of this model is the normal linear model, in which

y

given

X

is distributed Gaussian. In this model, and under a particular choice of prior probabilities for the parameters—so-called conjugate priors—the posterior can be found analytically. With more arbitrarily chosen priors, the posteriors generally have to be approximated.

Model setup

Consider a standard linear regression problem, in which for

i=1,\ldots,n

we specify the mean of the conditional distribution of

yi

given a

k x 1

predictor vector

xi

:y_ = \mathbf_i^\mathsf \boldsymbol\beta + \varepsilon_i,

where

\boldsymbol\beta

is a

k x 1

vector, and the

\varepsiloni

are independent and identically normally distributed random variables:\varepsilon_ \sim N(0, \sigma^2).

This corresponds to the following likelihood function:

\rho(\mathbf\mid\mathbf,\boldsymbol\beta,\sigma^) \propto (\sigma^2)^ \exp\left(-\frac (\mathbf- \mathbf \boldsymbol\beta)^\mathsf(\mathbf- \mathbf \boldsymbol\beta)\right).

The ordinary least squares solution is used to estimate the coefficient vector using the Moore–Penrose pseudoinverse: \hat = (\mathbf^\mathsf\mathbf)^\mathbf^\mathsf\mathbf

where

X

is the

n x k

design matrix, each row of which is a predictor vector
T
x
i
; and

y

is the column

n

-vector

[y1

T
y
n]
.

This is a frequentist approach, and it assumes that there are enough measurements to say something meaningful about

\boldsymbol\beta

. In the Bayesian approach, the data are supplemented with additional information in the form of a prior probability distribution. The prior belief about the parameters is combined with the data's likelihood function according to Bayes theorem to yield the posterior belief about the parameters

\boldsymbol\beta

and

\sigma

. The prior can take different functional forms depending on the domain and the information that is available a priori.

Since the data comprise both

y

and

X

, the focus only on the distribution of

y

conditional on

X

needs justification. In fact, a "full" Bayesian analysis would require a joint likelihood

\rho(y,X\mid\boldsymbol\beta,\sigma2,\gamma)

along with a prior

\rho(\beta,\sigma2,\gamma)

, where

\gamma

symbolizes the parameters of the distribution for

X

. Only under the assumption of (weak) exogeneity can the joint likelihood be factored into

\rho(y\mid\boldsymbolX,\beta,\sigma2)\rho(X\mid\gamma)

.[1] The latter part is usually ignored under the assumption of disjoint parameter sets. More so, under classic assumptions

X

are considered chosen (for example, in a designed experiment) and therefore has a known probability without parameters.[2]

With conjugate priors

Conjugate prior distribution

For an arbitrary prior distribution, there may be no analytical solution for the posterior distribution. In this section, we will consider a so-called conjugate prior for which the posterior distribution can be derived analytically.

A prior

\rho(\boldsymbol\beta,\sigma2)

is conjugate to this likelihood function if it has the same functional form with respect to

\boldsymbol\beta

and

\sigma

. Since the log-likelihood is quadratic in

\boldsymbol\beta

, the log-likelihood is re-written such that the likelihood becomes normal in

(\boldsymbol\beta-\hat{\boldsymbol\beta})

. Write

\begin(\mathbf- \mathbf \boldsymbol\beta)^\mathsf(\mathbf- \mathbf \boldsymbol\beta) &= [(\mathbf{y}- \mathbf{X} \hat{\boldsymbol\beta}) + (\mathbf{X} \hat{\boldsymbol\beta} - \mathbf{X} \boldsymbol\beta)]^\mathsf [(\mathbf{y}- \mathbf{X} \hat{\boldsymbol\beta}) + (\mathbf{X} \hat{\boldsymbol\beta} - \mathbf{X} \boldsymbol\beta)] \\&= (\mathbf- \mathbf \hat)^\mathsf(\mathbf- \mathbf \hat) + (\boldsymbol\beta - \hat)^\mathsf(\mathbf^\mathsf\mathbf)(\boldsymbol\beta - \hat)+ \underbrace_\\&= (\mathbf- \mathbf \hat)^\mathsf(\mathbf- \mathbf \hat) + (\boldsymbol\beta - \hat)^\mathsf(\mathbf^\mathsf\mathbf)(\boldsymbol\beta - \hat)\,.\end

The likelihood is now re-written as\rho(\mathbf|\mathbf,\boldsymbol\beta,\sigma^) \propto (\sigma^2)^ \exp\left(-\frac\right)(\sigma^2)^ \exp\left(-\frac(\boldsymbol\beta - \hat)^\mathsf(\mathbf^\mathsf\mathbf)(\boldsymbol\beta - \hat)\right),wherevs^2 =(\mathbf- \mathbf \hat)^\mathsf(\mathbf- \mathbf \hat) \quad \text \quad v = n-k,where

k

is the number of regression coefficients.

This suggests a form for the prior:\rho(\boldsymbol\beta,\sigma^2) = \rho(\sigma^2)\rho(\boldsymbol\beta\mid\sigma^2),where

\rho(\sigma2)

is an inverse-gamma distribution \rho(\sigma^2) \propto (\sigma^2)^ \exp\left(-\frac\right).

In the notation introduced in the inverse-gamma distribution article, this is the density of an

Inv-Gamma(a0,b0)

distribution with

a0=\tfrac{v0}{2}

and

b0=\tfrac{1}{2}v0s

2
0
with

v0

and
2
s
0
as the prior values of

v

and

s2

, respectively. Equivalently, it can also be described as a scaled inverse chi-squared distribution,
2(v
Scale-inv-\chi
0,
2).
s
0

Further the conditional prior density

\rho(\boldsymbol\beta|\sigma2)

is a normal distribution,

\rho(\boldsymbol\beta\mid\sigma^2) \propto (\sigma^2)^ \exp\left(-\frac(\boldsymbol\beta - \boldsymbol\mu_0)^\mathsf \mathbf_0 (\boldsymbol\beta - \boldsymbol\mu_0)\right).

In the notation of the normal distribution, the conditional prior distribution is

l{N}\left(\boldsymbol\mu0,\sigma2

-1
\boldsymbolΛ
0

\right).

Posterior distribution

With the prior now specified, the posterior distribution can be expressed as

\begin\rho(\boldsymbol\beta,\sigma^2\mid\mathbf,\mathbf) &\propto \rho(\mathbf\mid\mathbf,\boldsymbol\beta,\sigma^2)\rho(\boldsymbol\beta\mid\sigma^2)\rho(\sigma^2) \\& \propto (\sigma^2)^ \exp\left(-\frac(\mathbf- \mathbf \boldsymbol\beta)^\mathsf(\mathbf- \mathbf \boldsymbol\beta)\right) (\sigma^2)^ \exp\left(-\frac(\boldsymbol\beta -\boldsymbol\mu_0)^\mathsf \boldsymbol\Lambda_0 (\boldsymbol\beta - \boldsymbol\mu_0)\right) (\sigma^2)^ \exp\left(-\frac\right)\end

With some re-arrangement,[3] the posterior can be re-written so that the posterior mean

\boldsymbol\mun

of the parameter vector

\boldsymbol\beta

can be expressed in terms of the least squares estimator

\hat{\boldsymbol\beta}

and the prior mean

\boldsymbol\mu0

, with the strength of the prior indicated by the prior precision matrix

\boldsymbolΛ0

\boldsymbol\mu_n = (\mathbf^\mathsf\mathbf+\boldsymbol\Lambda_0)^(\mathbf^\mathsf \mathbf\hat+\boldsymbol\Lambda_0\boldsymbol\mu_0) .

To justify that

\boldsymbol\mun

is indeed the posterior mean, the quadratic terms in the exponential can be re-arranged as a quadratic form in

\boldsymbol\beta-\boldsymbol\mun

.[4]

(\mathbf- \mathbf \boldsymbol\beta)^\mathsf(\mathbf- \mathbf \boldsymbol\beta) + (\boldsymbol\beta - \boldsymbol\mu_0)^\mathsf\boldsymbol\Lambda_0(\boldsymbol\beta - \boldsymbol\mu_0) =(\boldsymbol\beta-\boldsymbol\mu_n)^\mathsf(\mathbf^\mathsf\mathbf+\boldsymbol\Lambda_0)(\boldsymbol\beta-\boldsymbol\mu_n)+\mathbf^\mathsf\mathbf-\boldsymbol\mu_n^\mathsf(\mathbf^\mathsf\mathbf+\boldsymbol\Lambda_0)\boldsymbol\mu_n+\boldsymbol\mu_0^\mathsf \boldsymbol\Lambda_0\boldsymbol\mu_0 .

Now the posterior can be expressed as a normal distribution times an inverse-gamma distribution:

\rho(\boldsymbol\beta,\sigma^2\mid\mathbf,\mathbf) \propto (\sigma^2)^ \exp\left(-\frac(\boldsymbol\beta - \boldsymbol\mu_n)^\mathsf(\mathbf^\mathsf \mathbf+\mathbf_0)(\boldsymbol\beta - \boldsymbol\mu_n)\right) (\sigma^2)^ \exp\left(-\frac\right) .

Therefore, the posterior distribution can be parametrized as follows.\rho(\boldsymbol\beta,\sigma^2\mid\mathbf,\mathbf) \propto \rho(\boldsymbol\beta \mid \sigma^2,\mathbf,\mathbf) \rho(\sigma^2\mid\mathbf,\mathbf), where the two factors correspond to the densities of

l{N}\left(\boldsymbol\mun,

-1
\sigma
n

\right)

and

Inv-Gamma\left(an,bn\right)

distributions, with the parameters of these given by

\boldsymbol\Lambda_n=(\mathbf^\mathsf\mathbf+\mathbf_0), \quad \boldsymbol\mu_n = (\boldsymbol\Lambda_n)^(\mathbf^\mathsf \mathbf \hat + \boldsymbol\Lambda_0 \boldsymbol\mu_0),a_n= a_0 + \frac, \qquad b_n=b_0+\frac(\mathbf^\mathsf \mathbf + \boldsymbol\mu_0^\mathsf \boldsymbol\Lambda_0\boldsymbol\mu_0-\boldsymbol\mu_n^\mathsf \boldsymbol\Lambda_n \boldsymbol\mu_n) .

which illustrates Bayesian inference being a compromise between the information contained in the prior and the information contained in the sample.

Model evidence

p(y\midm)

is the probability of the data given the model

m

. It is also known as the marginal likelihood, and as the prior predictive density. Here, the model is defined by the likelihood function

p(y\midX,\boldsymbol\beta,\sigma)

and the prior distribution on the parameters, i.e.

p(\boldsymbol\beta,\sigma)

. The model evidence captures in a single number how well such a model explains the observations. The model evidence of the Bayesian linear regression model presented in this section can be used to compare competing linear models by Bayesian model comparison. These models may differ in the number and values of the predictor variables as well as in their priors on the model parameters. Model complexity is already taken into account by the model evidence, because it marginalizes out the parameters by integrating

p(y,\boldsymbol\beta,\sigma\midX)

over all possible values of

\boldsymbol\beta

and

\sigma

.p(\mathbf|m)=\int p(\mathbf\mid\mathbf,\boldsymbol\beta,\sigma)\, p(\boldsymbol\beta,\sigma)\, d\boldsymbol\beta\, d\sigmaThis integral can be computed analytically and the solution is given in the following equation.[5] p(\mathbf\mid m)=\frac\sqrt \cdot \frac \cdot \frac

Here

\Gamma

denotes the gamma function. Because we have chosen a conjugate prior, the marginal likelihood can also be easily computed by evaluating the following equality for arbitrary values of

\boldsymbol\beta

and

\sigma

.p(\mathbf\mid m)=\fracNote that this equation is nothing but a re-arrangement of Bayes theorem. Inserting the formulas for the prior, the likelihood, and the posterior and simplifying the resulting expression leads to the analytic expression given above.

Other cases

In general, it may be impossible or impractical to derive the posterior distribution analytically. However, it is possible to approximate the posterior by an approximate Bayesian inference method such as Monte Carlo sampling,[6] INLA or variational Bayes.

The special case

\boldsymbol\mu0=0,Λ0=cI

is called ridge regression.

A similar analysis can be performed for the general case of the multivariate regression and part of this provides for Bayesian estimation of covariance matrices: see Bayesian multivariate linear regression.

See also

References

External links

Notes and References

  1. See Jackman (2009), p. 101.
  2. See Gelman et al. (2013), p. 354.
  3. The intermediate steps of this computation can be found in O'Hagan (1994) at the beginning of the chapter on Linear models.
  4. The intermediate steps are in Fahrmeir et al. (2009) on page 188.
  5. The intermediate steps of this computation can be found in O'Hagan (1994) on page 257.
  6. Carlin and Louis (2008) and Gelman, et al. (2003) explain how to use sampling methods for Bayesian linear regression.