# Inverse Wishart Distribution in Stan

Hi,

When I tried to assign an Inverse Wishart Distribution on the covariance of the multivariate normal distribution, I found the following link: 25.2 Inverse Wishart Distribution | Stan Functions Reference. The two parameters that need to be specified are \nu and \Sigma, however, in the common literature, the usually representation is like \Sigma \sim Inv-Wishart_4(I). May I ask that in this case how should I code the \Sigma \sim Inv-Wishart_4(I) in Stan using the built-in inv_wishart() function?

Thanks so much for your help!

The parametrization being used is the same; InvWishart_4(I) would be InvWishart(4, I) in Stan.

Thanks so much for your help!

May I ask that how could I code the identity matrix I with dimension 4 in Stan? I have tried to use diag_matrix(1) but not sure how to specify the corresponding dimension.

matrix[n,n] mat = identity_matrix(n).

Thanks so much!

May I ask that where should I put this statement in the Stan program? (for example, should I put it in ‘Data’ or ‘Parameter’ chunk?)

It should go in transformed data.

But if you’re using a Wishart with an identity matrix as the parameter, you really want to read this first:

Inverse-Wishart distribution - Wikipedia

You’ll notice that the density hugely simplifies with an identity matrix parameter (e.g., the determinant is unity, so all those terms go away). Stan’s going to have to do all the solving, determinant calculation, etc., if you code it directly. So it’ll be much more efficient to write a density for the Wishart as a user-defined function that fixes the identity matrix parameter.

You may also want to consider the alternative of a scaled LKJ prior, which we describe in the regression chapter of the user’s guide. Here’s @bgoodri’s paper motivating it:

http://www.stat.columbia.edu/~gelman/research/unpublished/Visualization.pdf

The problem with Wisharts is that they look like prior data, meaning they require specifying both scales and correlations together in the form of prior data (that may not look like prior data, but it’s conjugate in the exponential family, so the Wishart params can be represented as prior multivariate observations [perhaps fractional]).

We’ve also coded the LKJ priors much more efficiently than we’ve coded Wisharts because we haven’t been recommending Wishart priors.