This is an old version, view current version.

## 24.1 Wishart Distribution

### 24.1.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{Wishart}(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}\left( S^{-1} W \right) \right) \! ,$ where $$\text{tr}()$$ is the matrix trace function, and $$\Gamma_K()$$ is the multivariate Gamma function, $\Gamma_K(x) = \frac{1}{\pi^{K(K-1)/4}} \ \prod_{k=1}^K \Gamma \left( x + \frac{1 - k}{2} \right) \!.$

### 24.1.2 Sampling Statement

W ~ wishart(nu, Sigma)

Increment target log probability density with wishart_lpdf(W | nu, Sigma) dropping constant additive terms.

### 24.1.3 Stan Functions

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

matrix wishart_rng(real nu, matrix Sigma)
Generate a 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