Continuous distribution
Inverse gamma distribution
The distribution of when is gamma. Its main use is Bayesian: it is the conjugate prior for the variance of a normal distribution with known mean, so the posterior for is again inverse gamma.
Inverse gamma probability calculator
P(X ≤ 0.75) = 0.501825
At the parameters set by the sliders. The shaded region on the plot is the probability; the dots on the CDF mark F at its ends.
CDF
mean 1 · variance 1 · sd 1 · mode 0.5 · entropy 0.6952 nats
Formulas
| Parameters |
|
|---|---|
| Support | |
| CDF | |
| Mean | |
| Variance | |
| Mode | |
| MGF | |
| Entropy |
Worked example
A measurement error has known mean 0 and unknown variance with prior InvGamma(3, 2). Ten errors have sum of squares 8. What is the posterior mean of ?
The posterior is InvGamma = InvGamma(8, 6), whose mean is , between the prior mean 1 and the sample value 0.8. answer checked by code
How it relates to others
- Transformation← Gamma: If is Gamma() (rate ), is Inverse gamma() (scale ). checked by code
- Conjugate prior→ Normal: An Inverse gamma() prior on the variance of a normal with known mean gives an Inverse gamma() posterior. checked by code
- Mixture→ Multivariate t: If is Inverse gamma() and is Normal(), then is multivariate . checked by code
- Special case← Inverse Wishart: Each diagonal entry of a Inverse Wishart() matrix is Inverse gamma(); with the inverse Wishart is an inverse gamma. checked by code
- Special case→ Lévy: Inverse gamma() is Lévy(). checked by code
All the relationships, as a diagram →
In Python
from scipy import stats
import numpy as np
X = stats.invgamma(a=3, scale=2)
X.pdf(1) # f(1) = 0.5413
X.cdf(1) # P(X ≤ 1) = 0.6767
X.mean(), X.var() # 1, 1
X.ppf(0.95) # 95th percentile
X.rvs(size=10, random_state=0)
rng = np.random.default_rng(0)
1 / rng.gamma(shape=3, scale=1/2, size=10)NumPy has no inverse gamma sampler: take the reciprocal of a gamma with rate β (scale 1/β).
Choosing between this and its neighbours? Which prior distribution should I use?