Multivariate-Normal Distribution

Table of contents


Density Function

The density function of the Multivariate-Normal distribution:

\[f(\mathbf{x}; \boldsymbol{\mu}, \boldsymbol{\Sigma}) = \dfrac{1}{\sqrt{(2\pi)^k |\boldsymbol{\Sigma}|}} \exp \left( - \frac{1}{2} (\mathbf{x} - \boldsymbol{\mu})^\top \boldsymbol{\Sigma}^{-1} (\mathbf{x} - \boldsymbol{\mu}) \right)\]

where \(k\) is the dimension of the real-valued vector \(\mathbf{x}\) and \(| \cdot |\) denotes the matrix determinant.

template<typename vT, typename mT, typename eT = double>
inline eT dmvnorm(const vT &X, const vT &mu_par, const mT &Sigma_par, const bool log_form = false)

Density function of the Multivariate-Normal distribution.

Parameters
  • X – a column vector.

  • mu_par – mean vector.

  • Sigma_par – the covariance matrix.

  • log_form – return the log-density or the true form.

Returns

the density function evaluated at X.


Random Sampling

template<typename vT, typename mT, typename not_arma_mat<mT>::type* = nullptr>
inline vT rmvnorm(const vT &mu_par, const mT &Sigma_par, rand_engine_t &engine, const bool pre_chol = false)

Random sampling function for the Multivariate-Normal distribution.

Parameters
  • mu_par – mean vector.

  • Sigma_par – the covariance matrix.

  • engine – a random engine, passed by reference.

  • pre_chol – indicate whether Sigma_par is passed in lower triangular (Cholesky) format.

Returns

a pseudo-random draw from the Multivariate-Normal distribution.