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_lupdf(y | mu, Sigma)
.
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_lupdf
(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 dropping constant additive
terms
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_lupdf
(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 dropping constant additive
terms
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_lupdf
(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 dropping constant additive
terms
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
real
multi_normal_lupdf
(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 dropping constant additive
terms
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 transformed data and generated quantities blocks
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 transformed data and generated quantities blocks
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 transformed data and generated
quantities blocks
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 transformed data and generated
quantities blocks