Multivariate distribution
Inverse Wishart distribution
A random positive-definite matrix whose inverse is Wishart. It is the standard conjugate prior for the covariance matrix of a multivariate normal: with prior Inverse Wishart() and observations with scatter matrix about a known mean, the posterior is Inverse Wishart(). It is the matrix version of the inverse gamma. The plot shows the case: the joint density of the two variances , with the covariance integrated out numerically.
Joint density of (X₁, X₂)
E[X₁] = 0.5714 · E[X₂] = 0.5714 · Var X₁ = 0.1306 · Var X₂ = 0.1306 · Cov = 0.0449 · corr = 0.344
Formulas
| Parameters |
|
|---|---|
| Support | |
| CDF | |
| Mean | |
| Variance |
Each diagonal entry is inverse gamma: . The inverse Wishart ties the variances and correlations together in one parameter , which is why many Bayesian models (Stan's LKJ prior, for example) now put separate priors on the scales and the correlation matrix.
Worked example
A covariance matrix has an Inverse Wishart() prior. Twenty observations with known mean 0 have scatter matrix . What is the posterior mean of the first variance?
The posterior is Inverse Wishart(), so a little below the sample variance , pulled toward the prior. answer checked by code
How it relates to others
- Transformation← Wishart: If is Wishart(), its inverse is Inverse Wishart(). checked by code
- Special case→ Inverse gamma: Each diagonal entry of a Inverse Wishart() matrix is Inverse gamma(); with the inverse Wishart is an inverse gamma. checked by code
- Conjugate prior→ Multivariate normal: An Inverse Wishart() prior on the covariance of a multivariate normal with known mean , and observations , give an Inverse Wishart() posterior, where . checked by code
All the relationships, as a diagram →
In Python
from scipy import stats
import numpy as np
X = stats.invwishart(df=10, scale=[[4, 2], [2, 4]])
X.pdf([[0.5, 0.2], [0.2, 0.6]]) # density here: 3.07
X.mean()
X.rvs(size=5, random_state=0)
rng = np.random.default_rng(0)
X.rvs(size=5, random_state=rng)X.pdf takes the whole matrix, e.g. X.pdf([[0.5, 0.2], [0.2, 0.6]]). NumPy has no inverse Wishart sampler; SciPy's rvs takes a NumPy generator as random_state.
Choosing between this and its neighbours? Which prior distribution should I use?