# Bayesian multivariate linear regression

In statistics, Bayesian multivariate linear regression is a Bayesian approach to multivariate linear regression, i.e. linear regression where the predicted outcome is a vector of correlated random variables rather than a single scalar random variable. A more general treatment of this approach can be found in the article MMSE estimator.

## Details

Consider a regression problem where the dependent variable to be predicted is not a single real-valued scalar but an m-length vector of correlated real numbers. As in the standard regression setup, there are n observations, where each observation i consists of k-1 explanatory variables, grouped into a vector $\mathbf{x}_i$ of length k (where a dummy variable with a value of 1 has been added to allow for an intercept coefficient). This can be viewed as a set of m related regression problems for each observation i:

$y_{i,1} = \mathbf{x}_i^{\rm T}\boldsymbol\beta_{1} + \epsilon_{i,1}$
$\cdots$
$y_{i,m} = \mathbf{x}_i^{\rm T}\boldsymbol\beta_{m} + \epsilon_{i,m}$

where the set of errors $\{\epsilon_{i,1},\ldots,\epsilon_{i,m}\}$ are all correlated. Equivalently, it can be viewed as a single regression problem where the outcome is a row vector $\mathbf{y}_i^{\rm T}$ and the regression coefficient vectors are stacked next to each other, as follows:

$\mathbf{y}_i^{\rm T} = \mathbf{x}_i^{\rm T}\mathbf{B} + \boldsymbol\epsilon_{i}^{\rm T}.$

The coefficient matrix B is a $k \times m$ matrix where the coefficient vectors $\boldsymbol\beta_1,\ldots,\boldsymbol\beta_m$ for each regression problem are stacked horizontally:

$\mathbf{B} = \begin{bmatrix} \begin{pmatrix} \\ \boldsymbol\beta_1 \\ \\ \end{pmatrix} \cdots \begin{pmatrix} \\ \boldsymbol\beta_m \\ \\ \end{pmatrix} \end{bmatrix} = \begin{bmatrix} \begin{pmatrix} \beta_{1,1} \\ \vdots \\ \beta_{k,1} \\ \end{pmatrix} \cdots \begin{pmatrix} \beta_{1,m} \\ \vdots \\ \beta_{k,m} \\ \end{pmatrix} \end{bmatrix} .$

The noise vector $\boldsymbol\epsilon_{i}$ for each observation i is jointly normal, so that the outcomes for a given observation are correlated:

$\boldsymbol\epsilon_i \sim N(0, \boldsymbol\Sigma_{\epsilon}^2).$

We can write the entire regression problem in matrix form as:

$\mathbf{Y} =\mathbf{X}\mathbf{B} + \mathbf{E},$

where Y and E are $n \times m$ matrices. The design matrix X is an $n \times k$ matrix with the observations stacked vertically, as in the standard linear regression setup:

$\mathbf{X} = \begin{bmatrix} \mathbf{x}^{\rm T}_1 \\ \mathbf{x}^{\rm T}_2 \\ \vdots \\ \mathbf{x}^{\rm T}_n \end{bmatrix} = \begin{bmatrix} x_{1,1} & \cdots & x_{1,k} \\ x_{2,1} & \cdots & x_{2,k} \\ \vdots & \ddots & \vdots \\ x_{n,1} & \cdots & x_{n,k} \end{bmatrix}.$

The classical, frequentists linear least squares solution is to simply estimate the matrix of regression coefficients $\hat{\mathbf{B}}$ using the Moore-Penrose pseudoinverse:

$\hat{\mathbf{B}} = (\mathbf{X}^{\rm T}\mathbf{X})^{-1}\mathbf{X}^{\rm T}\mathbf{Y}$.

To obtain the Bayesian solution, we need to specify the conditional likelihood and then find the appropriate conjugate prior. As with the univariate case of linear Bayesian regression, we will find that we can specify a natural conditional conjugate prior (which is scale dependent).

Let us write our conditional likelihood as[1]

$\rho(\mathbf{E}|\boldsymbol\Sigma_{\epsilon}) \propto (\boldsymbol\Sigma_{\epsilon}^{2})^{-n/2} \exp(-\frac{1}{2} {\rm tr}(\mathbf{E}^{\rm T} \mathbf{E} \boldsymbol\Sigma_{\epsilon}^{-1}) ) ,$

writing the error $\mathbf{E}$ in terms of $\mathbf{Y},\mathbf{X},$ and $\mathbf{B}$ yields

$\rho(\mathbf{Y}|\mathbf{X},\mathbf{B},\boldsymbol\Sigma_{\epsilon}) \propto (\boldsymbol\Sigma_{\epsilon}^{2})^{-n/2} \exp(-\frac{1}{2} {\rm tr}((\mathbf{Y}-\mathbf{X}\mathbf{\mathbf{B}})^{\rm T} (\mathbf{Y}-\mathbf{X}\mathbf{\mathbf{B}}) \boldsymbol\Sigma_{\epsilon}^{-1} ) ) ,$

We seek a natural conjugate prior—a joint density $\rho(\mathbf{B},\Sigma_{\epsilon})$ which is of the same functional form as the likelihood. Since the likelihood is quadratic in $\mathbf{B}$, we re-write the likelihood so it is normal in $(\mathbf{B}-\hat{\mathbf{B}})$ (the deviation from classical sample estimate)

Using the same technique as with Bayesian linear regression, we decompose the exponential term using a matrix-form of the sum-of-squares technique. Here, however, we will also need to use the Matrix Differential Calculus (Kronecker product and vectorization transformations).

First, let us apply sum-of-squares to obtain new expression for the likelihood:

$\rho(\mathbf{Y}|\mathbf{X},\mathbf{B},\boldsymbol\Sigma_{\epsilon}) \propto \boldsymbol\Sigma_{\epsilon}^{-(n-k)/2} \exp(-{\rm tr}(\frac{1}{2}\mathbf{S}^{\rm T}\mathbf{S} \boldsymbol\Sigma_{\epsilon}^{-1})) (\boldsymbol\Sigma_{\epsilon}^{2})^{-k/2} \exp(-\frac{1}{2} {\rm tr}((\mathbf{B}-\hat{\mathbf{B}})^{\rm T} \mathbf{X}^{\rm T}\mathbf{X}(\mathbf{B}-\hat{\mathbf{B}}) \boldsymbol\Sigma_{\epsilon}^{-1} ) ) ,$
$\mathbf{S} = \mathbf{Y} - \hat{\mathbf{B}}\mathbf{X}$

We would like to develop a conditional form for the priors:

$\rho(\mathbf{B},\boldsymbol\Sigma_{\epsilon}) = \rho(\boldsymbol\Sigma_{\epsilon})\rho(\mathbf{B}|\boldsymbol\Sigma_{\epsilon}),$

where $\rho(\boldsymbol\Sigma_{\epsilon})$ is an inverse-Wishart distribution and $\rho(\mathbf{B}|\boldsymbol\Sigma_{\epsilon})$ is some form of normal distribution in the matrix $\mathbf{B}$. This is accomplished using the vectorization transformation, which converts the likelihood from a function of the matrices $\mathbf{B}, \hat{\mathbf{B}}$ to a function of the vectors $\boldsymbol\beta = {\rm vec}(\mathbf{B}), \hat{\boldsymbol\beta} = {\rm vec}(\hat{\mathbf{B}})$.

Write

${\rm tr}((\mathbf{B} - \hat{\mathbf{B}})^{\rm T}\mathbf{X}^{\rm T} \mathbf{X}(\mathbf{B} - \hat{\mathbf{B}}) \boldsymbol\Sigma_{\epsilon}^{-1}) = {\rm vec}(\mathbf{B} - \hat{\mathbf{B}})^{\rm T}{\rm vec}(\mathbf{X}^{\rm T} \mathbf{X}(\mathbf{B} - \hat{\mathbf{B}}) \boldsymbol\Sigma_{\epsilon}^{-1} )$

Let

${\rm vec}(\mathbf{X}^{\rm T} \mathbf{X}(\mathbf{B} - \hat{\mathbf{B}}) \boldsymbol\Sigma_{\epsilon}^{-1} ) = (\boldsymbol\Sigma_{\epsilon}^{-1} \otimes \mathbf{X}^{\rm T}\mathbf{X} ){\rm vec}(\mathbf{B} - \hat{\mathbf{B}}),$

where $\mathbf{A} \otimes \mathbf{B}$ denotes the Kronecker product of matrices A and B, a generalization of the outer product which multiplies an $m \times n$ matrix by a $p \times q$ matrix to generate an $mp \times nq$ matrix, consisting of every combination of products of elements from the two matrices.

Then

${\rm vec}(\mathbf{B} - \hat{\mathbf{B}})^{\rm T} (\boldsymbol\Sigma_{\epsilon}^{-1} \otimes \mathbf{X}^{\rm T}\mathbf{X} ){\rm vec}(\mathbf{B} - \hat{\mathbf{B}})$
$= (\boldsymbol\beta-\hat{\boldsymbol\beta})^{\rm T}(\boldsymbol\Sigma_{\epsilon}^{-1} \otimes \mathbf{X}^{\rm T}\mathbf{X} )(\boldsymbol\beta-\hat{\boldsymbol\beta})$

which will lead to a likelihood which is normal in $(\boldsymbol\beta - \hat{\boldsymbol\beta})$.

With the likelihood in a more tractable form, we can now find a natural (conditional) conjugate prior.