## 26.2 Inverse Wishart distribution

### 26.2.1 Probability density function

If $$K \in \mathbb{N}$$, $$\nu \in (K-1,\infty)$$, and $$S \in \mathbb{R}^{K \times K}$$ is symmetric and positive definite, then for symmetric and positive-definite $$W \in \mathbb{R}^{K \times K}$$, $\text{InvWishart}(W|\nu,S) = \frac{1}{2^{\nu K / 2}} \ \frac{1}{\Gamma_K \! \left( \frac{\nu}{2} \right)} \ \left| S \right|^{\nu/2} \ \left| W \right|^{-(\nu + K + 1)/2} \ \exp \! \left( - \frac{1}{2} \ \text{tr}(SW^{-1}) \right) \! .$

### 26.2.2 Sampling statement

W ~ inv_wishart(nu, Sigma)

Increment target log probability density with inv_wishart_lupdf(W | nu, Sigma).
Available since 2.0

### 26.2.3 Stan functions

real inv_wishart_lpdf(matrix W | real nu, matrix Sigma)
The log of the inverse Wishart density for symmetric and positive-definite matrix W given degrees of freedom nu and symmetric and positive-definite scale matrix Sigma
Available since 2.12

real inv_wishart_lupdf(matrix W | real nu, matrix Sigma)
The log of the inverse Wishart density for symmetric and positive-definite matrix W given degrees of freedom nu and symmetric and positive-definite scale matrix Sigma dropping constant additive terms
Available since 2.25

matrix inv_wishart_rng(real nu, matrix Sigma)
Generate an inverse Wishart variate with degrees of freedom nu and symmetric and positive-definite scale matrix Sigma; may only be used in transformed data and generated quantities blocks
Available since 2.0