Introduction

The density function of the inverse-Wishart distribution:

$$ f(\mathbf{X}; \boldsymbol{\Psi}, \nu) = \dfrac{1}{2^{\frac{\nu p}{2}} |\boldsymbol{\Psi}|^{\frac{\nu}{2}} \Gamma_p\left( \frac{\nu}{2} \right)} | \mathbf{X} |^{\frac{\nu - p - 1}{2}} \exp \left( - \frac{1}{2} \text{tr} (\boldsymbol{\Psi}^{-1} \mathbf{X}) \right) $$

where $\Gamma_p$ is the multivariate gamma function.

Parameters:

  • Psi_par is $\boldsymbol{\Psi}$
  • nu_par is $\nu$

Density


Definition:

template<typename mT, typename pT>
statslib_inline
return_t<pT> dwish(const mT& X, const mT& Psi_par, const pT nu_par, bool log_form = false);

Computes the density function.


Examples:

// parameters
arma::mat Psi = arma::eye(5,5);
double nu = 10.0;

// Armadillo input
arma::mat X(10,1);
X.fill(2.5);

arma::mat dens_vals_mat = stats::dwish(X,Psi,nu);
arma::mat log_dens_vals_mat = stats::dwish(X,Psi,nu,true);

Random Sampling


Definition:

 
template<typename mT, typename pT>
statslib_inline
mT rwish(const mT& Psi_par, const pT nu_par, const bool pre_chol = false);

Generates pseudo-random draws.

Here pre_chol indicates whether Psi_par is being passed as a Cholesky decomposition (in lower triangular format).


Examples:

// parameters
arma::mat Psi = arma::eye(5,5);
double nu = 10.0;

// Armadillo output
arma::mat rand_mat = stats::rwish<arma::mat>(Psi,nu);