Bayesian linear regression

From HandWiki
Short description: Method of statistical analysis

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 [math]\displaystyle{ y }[/math]) conditional on observed values of the regressors (usually [math]\displaystyle{ X }[/math]). The simplest and most widely used version of this model is the normal linear model, in which [math]\displaystyle{ y }[/math] given [math]\displaystyle{ X }[/math] 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 [math]\displaystyle{ i = 1, \ldots, n }[/math] we specify the mean of the conditional distribution of [math]\displaystyle{ y_i }[/math] given a [math]\displaystyle{ k \times 1 }[/math] predictor vector [math]\displaystyle{ \mathbf{x}_i }[/math]: [math]\displaystyle{ y_{i} = \mathbf{x}_i^\mathsf{T} \boldsymbol\beta + \varepsilon_i, }[/math]

where [math]\displaystyle{ \boldsymbol\beta }[/math] is a [math]\displaystyle{ k \times 1 }[/math] vector, and the [math]\displaystyle{ \varepsilon_i }[/math] are independent and identically normally distributed random variables: [math]\displaystyle{ \varepsilon_{i} \sim N(0, \sigma^2). }[/math]

This corresponds to the following likelihood function:

[math]\displaystyle{ \rho(\mathbf{y}\mid\mathbf{X},\boldsymbol\beta,\sigma^{2}) \propto (\sigma^2)^{-n/2} \exp\left(-\frac{1}{2\sigma^2} (\mathbf{y}- \mathbf{X} \boldsymbol\beta)^\mathsf{T}(\mathbf{y}- \mathbf{X} \boldsymbol\beta)\right). }[/math]

The ordinary least squares solution is used to estimate the coefficient vector using the Moore–Penrose pseudoinverse: [math]\displaystyle{ \hat{\boldsymbol\beta} = (\mathbf{X}^\mathsf{T}\mathbf{X})^{-1}\mathbf{X}^\mathsf{T}\mathbf{y} }[/math]

where [math]\displaystyle{ \mathbf{X} }[/math] is the [math]\displaystyle{ n \times k }[/math] design matrix, each row of which is a predictor vector [math]\displaystyle{ \mathbf{x}_i^\mathsf{T} }[/math]; and [math]\displaystyle{ \mathbf{y} }[/math] is the column [math]\displaystyle{ n }[/math]-vector [math]\displaystyle{ [y_1 \; \cdots \; y_n]^\mathsf{T} }[/math].

This is a frequentist approach, and it assumes that there are enough measurements to say something meaningful about [math]\displaystyle{ \boldsymbol\beta }[/math]. 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 [math]\displaystyle{ \boldsymbol\beta }[/math] and [math]\displaystyle{ \sigma }[/math]. The prior can take different functional forms depending on the domain and the information that is available a priori.

Since the data comprise both [math]\displaystyle{ \mathbf{y} }[/math] and [math]\displaystyle{ \mathbf{X} }[/math], the focus only on the distribution of [math]\displaystyle{ \mathbf{y} }[/math] conditional on [math]\displaystyle{ \mathbf{X} }[/math] needs justification. In fact, a "full" Bayesian analysis would require a joint likelihood [math]\displaystyle{ \rho(\mathbf{y},\mathbf{X}\mid\boldsymbol\beta,\sigma^{2},\gamma) }[/math] along with a prior [math]\displaystyle{ \rho(\beta,\sigma^{2},\gamma) }[/math], where [math]\displaystyle{ \gamma }[/math] symbolizes the parameters of the distribution for [math]\displaystyle{ \mathbf{X} }[/math]. Only under the assumption of (weak) exogeneity can the joint likelihood be factored into [math]\displaystyle{ \rho(\mathbf{y}\mid\boldsymbol\mathbf{X},\beta,\sigma^{2})\rho(\mathbf{X}\mid\gamma) }[/math].[1] The latter part is usually ignored under the assumption of disjoint parameter sets. More so, under classic assumptions [math]\displaystyle{ \mathbf{X} }[/math] 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 [math]\displaystyle{ \rho(\boldsymbol\beta,\sigma^{2}) }[/math] is conjugate to this likelihood function if it has the same functional form with respect to [math]\displaystyle{ \boldsymbol\beta }[/math] and [math]\displaystyle{ \sigma }[/math]. Since the log-likelihood is quadratic in [math]\displaystyle{ \boldsymbol\beta }[/math], the log-likelihood is re-written such that the likelihood becomes normal in [math]\displaystyle{ (\boldsymbol\beta-\hat{\boldsymbol\beta}) }[/math]. Write

[math]\displaystyle{ \begin{align} (\mathbf{y}- \mathbf{X} \boldsymbol\beta)^\mathsf{T}(\mathbf{y}- \mathbf{X} \boldsymbol\beta) &= [(\mathbf{y}- \mathbf{X} \hat{\boldsymbol\beta}) + (\mathbf{X} \hat{\boldsymbol\beta} - \mathbf{X} \boldsymbol\beta)]^\mathsf{T} [(\mathbf{y}- \mathbf{X} \hat{\boldsymbol\beta}) + (\mathbf{X} \hat{\boldsymbol\beta} - \mathbf{X} \boldsymbol\beta)] \\ &= (\mathbf{y}- \mathbf{X} \hat{\boldsymbol\beta})^\mathsf{T}(\mathbf{y}- \mathbf{X} \hat{\boldsymbol\beta}) + (\boldsymbol\beta - \hat{\boldsymbol\beta})^\mathsf{T}(\mathbf{X}^\mathsf{T}\mathbf{X})(\boldsymbol\beta - \hat{\boldsymbol\beta}) + \underbrace{2(\mathbf{X} \hat{\boldsymbol\beta} - \mathbf{X} \boldsymbol\beta)^\mathsf{T} (\mathbf{y}- \mathbf{X} \hat{\boldsymbol\beta})}_{= \ 0}\\ &= (\mathbf{y}- \mathbf{X} \hat{\boldsymbol\beta})^\mathsf{T}(\mathbf{y}- \mathbf{X} \hat{\boldsymbol\beta}) + (\boldsymbol\beta - \hat{\boldsymbol\beta})^\mathsf{T}(\mathbf{X}^\mathsf{T}\mathbf{X})(\boldsymbol\beta - \hat{\boldsymbol\beta})\,. \end{align} }[/math]

The likelihood is now re-written as [math]\displaystyle{ \rho(\mathbf{y}|\mathbf{X},\boldsymbol\beta,\sigma^{2}) \propto (\sigma^2)^{-\frac{v}{2}} \exp\left(-\frac{vs^{2}}{2{\sigma}^{2}}\right)(\sigma^2)^{-\frac{n-v}{2}} \exp\left(-\frac{1}{2{\sigma}^{2}}(\boldsymbol\beta - \hat{\boldsymbol\beta})^\mathsf{T}(\mathbf{X}^\mathsf{T}\mathbf{X})(\boldsymbol\beta - \hat{\boldsymbol\beta})\right), }[/math] where [math]\displaystyle{ vs^2 =(\mathbf{y}- \mathbf{X} \hat{\boldsymbol\beta})^\mathsf{T}(\mathbf{y}- \mathbf{X} \hat{\boldsymbol\beta}) \quad \text{ and } \quad v = n-k, }[/math] where [math]\displaystyle{ k }[/math] is the number of regression coefficients.

This suggests a form for the prior: [math]\displaystyle{ \rho(\boldsymbol\beta,\sigma^2) = \rho(\sigma^2)\rho(\boldsymbol\beta\mid\sigma^2), }[/math] where [math]\displaystyle{ \rho(\sigma^2) }[/math] is an inverse-gamma distribution [math]\displaystyle{ \rho(\sigma^2) \propto (\sigma^2)^{-\frac{v_0}{2}-1} \exp\left(-\frac{v_0 s_0^2}{2\sigma^2}\right). }[/math]

In the notation introduced in the inverse-gamma distribution article, this is the density of an [math]\displaystyle{ \text{Inv-Gamma}( a_0, b_0) }[/math] distribution with [math]\displaystyle{ a_0=\tfrac{v_0}{2} }[/math] and [math]\displaystyle{ b_0=\tfrac{1}{2} v_0s_0^2 }[/math] with [math]\displaystyle{ v_0 }[/math] and [math]\displaystyle{ s_0^2 }[/math] as the prior values of [math]\displaystyle{ v }[/math] and [math]\displaystyle{ s^{2} }[/math], respectively. Equivalently, it can also be described as a scaled inverse chi-squared distribution, [math]\displaystyle{ \text{Scale-inv-}\chi^2(v_0, s_0^2). }[/math]

Further the conditional prior density [math]\displaystyle{ \rho(\boldsymbol\beta|\sigma^{2}) }[/math] is a normal distribution,

[math]\displaystyle{ \rho(\boldsymbol\beta\mid\sigma^2) \propto (\sigma^2)^{-k/2} \exp\left(-\frac{1}{2\sigma^2}(\boldsymbol\beta - \boldsymbol\mu_0)^\mathsf{T} \mathbf{\Lambda}_0 (\boldsymbol\beta - \boldsymbol\mu_0)\right). }[/math]

In the notation of the normal distribution, the conditional prior distribution is [math]\displaystyle{ \mathcal{N}\left(\boldsymbol\mu_0, \sigma^2 \boldsymbol\Lambda_0^{-1}\right). }[/math]

Posterior distribution

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

[math]\displaystyle{ \begin{align} \rho(\boldsymbol\beta,\sigma^2\mid\mathbf{y},\mathbf{X}) &\propto \rho(\mathbf{y}\mid\mathbf{X},\boldsymbol\beta,\sigma^2)\rho(\boldsymbol\beta\mid\sigma^2)\rho(\sigma^2) \\ & \propto (\sigma^2)^{-n/2} \exp\left(-\frac{1}{2{\sigma}^2}(\mathbf{y}- \mathbf{X} \boldsymbol\beta)^\mathsf{T}(\mathbf{y}- \mathbf{X} \boldsymbol\beta)\right) (\sigma^2)^{-k/2} \exp\left(-\frac{1}{2\sigma^2}(\boldsymbol\beta -\boldsymbol\mu_0)^\mathsf{T} \boldsymbol\Lambda_0 (\boldsymbol\beta - \boldsymbol\mu_0)\right) (\sigma^2)^{-(a_0+1)} \exp\left(-\frac{b_0}{\sigma^2}\right) \end{align} }[/math]

With some re-arrangement,[3] the posterior can be re-written so that the posterior mean [math]\displaystyle{ \boldsymbol\mu_n }[/math] of the parameter vector [math]\displaystyle{ \boldsymbol\beta }[/math] can be expressed in terms of the least squares estimator [math]\displaystyle{ \hat{\boldsymbol\beta} }[/math] and the prior mean [math]\displaystyle{ \boldsymbol\mu_0 }[/math], with the strength of the prior indicated by the prior precision matrix [math]\displaystyle{ \boldsymbol\Lambda_0 }[/math]

[math]\displaystyle{ \boldsymbol\mu_n = (\mathbf{X}^\mathsf{T}\mathbf{X}+\boldsymbol\Lambda_0)^{-1}(\mathbf{X}^\mathsf{T} \mathbf{X}\hat{\boldsymbol\beta}+\boldsymbol\Lambda_0\boldsymbol\mu_0) . }[/math]

To justify that [math]\displaystyle{ \boldsymbol\mu_n }[/math] is indeed the posterior mean, the quadratic terms in the exponential can be re-arranged as a quadratic form in [math]\displaystyle{ \boldsymbol\beta - \boldsymbol\mu_n }[/math].[4]

[math]\displaystyle{ (\mathbf{y}- \mathbf{X} \boldsymbol\beta)^\mathsf{T}(\mathbf{y}- \mathbf{X} \boldsymbol\beta) + (\boldsymbol\beta - \boldsymbol\mu_0)^\mathsf{T}\boldsymbol\Lambda_0(\boldsymbol\beta - \boldsymbol\mu_0) =(\boldsymbol\beta-\boldsymbol\mu_n)^\mathsf{T}(\mathbf{X}^\mathsf{T}\mathbf{X}+\boldsymbol\Lambda_0)(\boldsymbol\beta-\boldsymbol\mu_n)+\mathbf{y}^\mathsf{T}\mathbf{y}-\boldsymbol\mu_n^\mathsf{T}(\mathbf{X}^\mathsf{T}\mathbf{X}+\boldsymbol\Lambda_0)\boldsymbol\mu_n+\boldsymbol\mu_0^\mathsf{T} \boldsymbol\Lambda_0\boldsymbol\mu_0 . }[/math]

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

[math]\displaystyle{ \rho(\boldsymbol\beta,\sigma^2\mid\mathbf{y},\mathbf{X}) \propto (\sigma^2)^{-k/2} \exp\left(-\frac{1}{2{\sigma}^{2}}(\boldsymbol\beta - \boldsymbol\mu_n)^\mathsf{T}(\mathbf{X}^\mathsf{T} \mathbf{X}+\mathbf{\Lambda}_0)(\boldsymbol\beta - \boldsymbol\mu_n)\right) (\sigma^2)^{-\frac{n+2a_0}{2}-1} \exp\left(-\frac{2 b_0+\mathbf{y}^\mathsf{T}\mathbf{y}-\boldsymbol\mu_n^\mathsf{T}(\mathbf{X}^\mathsf{T} \mathbf{X}+\boldsymbol\Lambda_0)\boldsymbol\mu_n+\boldsymbol\mu_0^\mathsf{T} \boldsymbol\Lambda_0 \boldsymbol\mu_0}{2\sigma^2}\right) . }[/math]

Therefore, the posterior distribution can be parametrized as follows. [math]\displaystyle{ \rho(\boldsymbol\beta,\sigma^2\mid\mathbf{y},\mathbf{X}) \propto \rho(\boldsymbol\beta \mid \sigma^2,\mathbf{y},\mathbf{X}) \rho(\sigma^2\mid\mathbf{y},\mathbf{X}), }[/math] where the two factors correspond to the densities of [math]\displaystyle{ \mathcal{N}\left( \boldsymbol\mu_n, \sigma^2\boldsymbol\Lambda_n^{-1} \right)\, }[/math] and [math]\displaystyle{ \text{Inv-Gamma}\left(a_n,b_n \right) }[/math] distributions, with the parameters of these given by

[math]\displaystyle{ \boldsymbol\Lambda_n=(\mathbf{X}^\mathsf{T}\mathbf{X}+\mathbf{\Lambda}_0), \quad \boldsymbol\mu_n = (\boldsymbol\Lambda_n)^{-1}(\mathbf{X}^\mathsf{T} \mathbf{X} \hat{\boldsymbol\beta} + \boldsymbol\Lambda_0 \boldsymbol\mu_0) , }[/math] [math]\displaystyle{ a_n= a_0 + \frac{n}{2}, \qquad b_n=b_0+\frac{1}{2}(\mathbf{y}^\mathsf{T} \mathbf{y} + \boldsymbol\mu_0^\mathsf{T} \boldsymbol\Lambda_0\boldsymbol\mu_0-\boldsymbol\mu_n^\mathsf{T} \boldsymbol\Lambda_n \boldsymbol\mu_n) . }[/math]

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

Model evidence

The model evidence [math]\displaystyle{ p(\mathbf{y}\mid m) }[/math] is the probability of the data given the model [math]\displaystyle{ m }[/math]. It is also known as the marginal likelihood, and as the prior predictive density. Here, the model is defined by the likelihood function [math]\displaystyle{ p(\mathbf{y}\mid\mathbf{X},\boldsymbol\beta,\sigma) }[/math] and the prior distribution on the parameters, i.e. [math]\displaystyle{ p(\boldsymbol\beta,\sigma) }[/math]. 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 [math]\displaystyle{ p(\mathbf{y},\boldsymbol\beta,\sigma\mid\mathbf{X}) }[/math] over all possible values of [math]\displaystyle{ \boldsymbol\beta }[/math] and [math]\displaystyle{ \sigma }[/math]. [math]\displaystyle{ p(\mathbf{y}|m)=\int p(\mathbf{y}\mid\mathbf{X},\boldsymbol\beta,\sigma)\, p(\boldsymbol\beta,\sigma)\, d\boldsymbol\beta\, d\sigma }[/math] This integral can be computed analytically and the solution is given in the following equation.[5] [math]\displaystyle{ p(\mathbf{y}\mid m)=\frac{1}{(2\pi)^{n/2}}\sqrt{\frac{\det(\boldsymbol\Lambda_0)}{\det(\boldsymbol\Lambda_n)}} \cdot \frac{b_0^{a_0}}{b_n^{a_n}} \cdot \frac{\Gamma(a_n)}{\Gamma(a_0)} }[/math]

Here [math]\displaystyle{ \Gamma }[/math] 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 [math]\displaystyle{ \boldsymbol\beta }[/math] and [math]\displaystyle{ \sigma }[/math]. [math]\displaystyle{ p(\mathbf{y}\mid m)=\frac{p(\boldsymbol\beta,\sigma|m)\, p(\mathbf{y} \mid \mathbf{X}, \boldsymbol\beta,\sigma,m)}{p(\boldsymbol\beta, \sigma \mid \mathbf{y},\mathbf{X},m)} }[/math] Note 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] or variational Bayes.

The special case [math]\displaystyle{ \boldsymbol\mu_0=0, \mathbf{\Lambda}_0 = c\mathbf{I} }[/math] 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


Notes

  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.

References

  • Box, G. E. P.; Tiao, G. C. (1973). Bayesian Inference in Statistical Analysis. Wiley. ISBN 0-471-57428-7. 
  • Carlin, Bradley P.; Louis, Thomas A. (2008). Bayesian Methods for Data Analysis (Third ed.). Boca Raton, FL: Chapman and Hall/CRC. ISBN 1-58488-697-8. 
  • Fahrmeir, L.; Kneib, T.; Lang, S. (2009). Regression. Modelle, Methoden und Anwendungen (Second ed.). Heidelberg: Springer. doi:10.1007/978-3-642-01837-4. ISBN 978-3-642-01836-7. 
  • Gelman, Andrew et al. (2013). "Introduction to regression models". Bayesian Data Analysis (Third ed.). Boca Raton, FL: Chapman and Hall/CRC. pp. 353–380. ISBN 978-1-4398-4095-5. 
  • Jackman, Simon (2009). "Regression models". Bayesian Analysis for the Social Sciences. Wiley. pp. 99–124. ISBN 978-0-470-01154-6. 
  • Rossi, Peter E.; Allenby, Greg M.; McCulloch, Robert (2006). Bayesian Statistics and Marketing. John Wiley & Sons. ISBN 0470863676. 
  • O'Hagan, Anthony (1994). Bayesian Inference. Kendall's Advanced Theory of Statistics. 2B (First ed.). Halsted. ISBN 0-340-52922-9. 

External links

  • Bayesian estimation of linear models (R programming wikibook). Bayesian linear regression as implemented in R.