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.

PDF

00.51012345f(x)mean

CDF

00.250.50.751012345F(x)

mean 1 · variance 1 · sd 1 · mode 0.5 · entropy 0.6952 nats

Formulas

Parameters
  • , the shape
  • , the scale
Support
PDF
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

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?

← Noncentral chi-squaredInverse Gaussian →