22.1 Multivariate Normal Distribution

22.1.1 Probability Density Function

If \(K \in \mathbb{N}\), \(\mu \in \mathbb{R}^K\), and \(\Sigma \in \mathbb{R}^{K \times K}\) is symmetric and positive definite, then for \(y \in \mathbb{R}^K\), \[ \text{MultiNormal}(y|\mu,\Sigma) = \frac{1}{\left( 2 \pi \right)^{K/2}} \ \frac{1}{\sqrt{|\Sigma|}} \ \exp \! \left( \! - \frac{1}{2} (y - \mu)^{\top} \, \Sigma^{-1} \, (y - \mu) \right) \! , \] where \(|\Sigma|\) is the absolute determinant of \(\Sigma\).

22.1.2 Sampling Statement

y ~ multi_normal(mu, Sigma)

Increment target log probability density with multi_normal_lpdf( y | mu, Sigma) dropping constant additive terms.

22.1.3 Stan Functions

The multivariate normal probability function is overloaded to allow the variate vector \(y\) and location vector \(\mu\) to be vectors or row vectors (or to mix the two types). The density function is also vectorized, so it allows arrays of row vectors or vectors as arguments; see section vectorized function signatures for a description of vectorization.

real multi_normal_lpdf(vectors y | vectors mu, matrix Sigma)
The log of the multivariate normal density of vector(s) y given location vector(s) mu and covariance matrix Sigma

real multi_normal_lpdf(vectors y | row_vectors mu, matrix Sigma)
The log of the multivariate normal density of vector(s) y given location row vector(s) mu and covariance matrix Sigma

real multi_normal_lpdf(row_vectors y | vectors mu, matrix Sigma)
The log of the multivariate normal density of row vector(s) y given location vector(s) mu and covariance matrix Sigma

real multi_normal_lpdf(row_vectors y | row_vectors mu, matrix Sigma)
The log of the multivariate normal density of row vector(s) y given location row vector(s) mu and covariance matrix Sigma

Although there is a direct multi-normal RNG function, if more than one result is required, it’s much more efficient to Cholesky factor the covariance matrix and call multi_normal_cholesky_rng; see section multi-variate normal, cholesky parameterization.

vector multi_normal_rng(vector mu, matrix Sigma)
Generate a multivariate normal variate with location mu and covariance matrix Sigma; may only be used in generated quantities block

vector multi_normal_rng(row_vector mu, matrix Sigma)
Generate a multivariate normal variate with location mu and covariance matrix Sigma; may only be used in generated quantities block

vectors multi_normal_rng(vectors mu, matrix Sigma)
Generate an array of multivariate normal variates with locations mu and covariance matrix Sigma; may only be used in generated quantities block

vectors multi_normal_rng(row_vectors mu, matrix Sigma)
Generate an array of multivariate normal variates with locations mu and covariance matrix Sigma; may only be used in generated quantities block