24.1 Multivariate normal distribution
24.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\).
24.1.2 Sampling statement
y ~
multi_normal
(mu, Sigma)
Increment target log probability density with multi_normal_lupdf(y | mu, Sigma)
.
Available since 2.0
24.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
Available since 2.12
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
Available since 2.25
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
Available since 2.12
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
Available since 2.25
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
Available since 2.12
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
Available since 2.25
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
Available since 2.12
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
Available since 2.25
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
Available since 2.0
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
Available since 2.18
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
Available since 2.18
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
Available since 2.18