This is an old version, view current version.

22.1 Multivariate normal distribution

22.1.1 Probability density function

If KN, μRK, and ΣRK×K is symmetric and positive definite, then for yRK, MultiNormal(y|μ,Σ)=1(2π)K/2 1|Σ| exp(12(yμ)Σ1(yμ)), where |Σ| is the absolute determinant of Σ.

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 μ 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