# Conjugate prior

In Bayesian probability theory, a class of prior probability distributions p(θ) is said to be conjugate to a class of likelihood functions p(x|θ) if the resulting posterior distributions p(θ|x) are in the same family as p(θ). For example, the Gaussian family is conjugate to itself (or self-conjugate): if the likelihood function is Gaussian, choosing a Gaussian prior will ensure that the posterior distribution is also Gaussian. The concept, as well as the term "conjugate prior", were introduced by Howard Raiffa and Robert Schlaifer in their work on Bayesian decision theory.[1] A similar concept had been discovered independently by George Alfred Barnard.[2]

Consider the general problem of inferring a distribution for a parameter θ given some datum or data x. From Bayes' theorem, the posterior distribution is calculated from the prior p(θ) and the likelihood function ${\displaystyle \theta \mapsto p(x\mid \theta )\!}$ as

${\displaystyle p(\theta |x)={\frac {p(x|\theta )\,p(\theta )}{\int p(x|\theta )\,p(\theta )\,d\theta }}.\!}$

Let the likelihood function be considered fixed; the likelihood function is usually well-determined from a statement of the data-generating process. It is clear that different choices of the prior distribution p(θ) may make the integral more or less difficult to calculate, and the product p(x|θ) × p(θ) may take one algebraic form or another. For certain choices of the prior, the posterior has the same algebraic form as the prior (generally with different parameters). Such a choice is a conjugate prior.

A conjugate prior is an algebraic convenience: otherwise a difficult numerical integration may be necessary.

All members of the exponential family have conjugate priors. See Gelman et al.[3] for a catalog.

## Example

For a random variable which is a Bernoulli trial with unknown probability of success q in [0,1], the usual conjugate prior is the beta distribution with

${\displaystyle p(q=x)={x^{\alpha -1}(1-x)^{\beta -1} \over \mathrm {B} (\alpha ,\beta )}}$

where ${\displaystyle \alpha }$ and ${\displaystyle \beta }$ are chosen to reflect any existing belief or information (${\displaystyle \alpha }$ = 1 and ${\displaystyle \beta }$ = 1 would give a uniform distribution) and Β(${\displaystyle \alpha }$${\displaystyle \beta }$) is the Beta function acting as a normalising constant.

If we then sample this random variable and get s successes and f failures, we have

${\displaystyle P(s,f|q=x)={s+f \choose s}x^{s}(1-x)^{f},}$
${\displaystyle p(q=x|s,f)={{{s+f \choose s}x^{s+\alpha -1}(1-x)^{f+\beta -1}/\mathrm {B} (\alpha ,\beta )} \over \int _{y=0}^{1}\left({s+f \choose s}y^{s+\alpha -1}(1-y)^{f+\beta -1}/\mathrm {B} (\alpha ,\beta )\right)dy}={x^{s+\alpha -1}(1-x)^{f+\beta -1} \over \mathrm {B} (s+\alpha ,f+\beta )},}$

which is another Beta distribution with a simple change to the parameters. This posterior distribution could then be used as the prior for more samples, with the parameters simply adding each extra piece of information as it comes.

## Table of conjugate distributions

Let n denote the number of observations

### Discrete likelihood distributions

Likelihood Model parameters Conjugate prior distribution Prior hyperparameters Posterior hyperparameters
Bernoulli p (probability) Beta ${\displaystyle \alpha ,\ \beta \!}$ [4] ${\displaystyle \alpha +\sum _{i=1}^{n}x_{i},\ \beta +n-\sum _{i=1}^{n}x_{i}\!}$
Binomial p (probability) Beta ${\displaystyle \alpha ,\ \beta \!}$ [4] ${\displaystyle \alpha +\sum _{i=1}^{n}x_{i},\ \beta +\sum _{i=1}^{n}N_{i}-x_{i}\!}$
Poisson λ (rate) Gamma ${\displaystyle \alpha ,\ \beta \!}$ [4] ${\displaystyle \alpha +\sum _{i=1}^{n}x_{i},\ \beta +n\!}$
Multinomial p (probability vector) Dirichlet ${\displaystyle {\vec {\alpha }}\!}$ ${\displaystyle {\vec {\alpha }}+\sum _{i=1}^{n}{\vec {x}}^{\,(i)}\!}$
Geometric p0 (probability) Beta ${\displaystyle \alpha ,\ \beta \!}$ [4] ${\displaystyle \alpha +n,\ \beta +\sum _{i=1}^{n}x_{i}\!}$

### Continuous likelihood distributions

Likelihood Model parameters Conjugate prior distribution Prior hyperparameters Posterior hyperparameters
Uniform ${\displaystyle U(0,\theta )\!}$ Pareto ${\displaystyle X_{m},\ k\!}$ ${\displaystyle \max\{\,X_{(n)},X_{m}\},k+n\!}$
Exponential λ (rate) Gamma ${\displaystyle \alpha ,\ \beta \!}$ [4] ${\displaystyle \alpha +n,\ \beta +\sum _{i=1}^{n}x_{i}\!}$
Normal
with known variance σ2
μ (mean) Normal ${\displaystyle \mu _{0},\sigma _{0}^{2}\!}$ ${\displaystyle ({\frac {\mu _{0}}{\sigma _{0}^{2}}}+{\frac {\sum _{i=1}^{n}x_{i}}{\sigma ^{2}}})/({\frac {1}{\sigma _{0}^{2}}}+{\frac {n}{\sigma ^{2}}}),({\frac {1}{\sigma _{0}^{2}}}+{\frac {n}{\sigma ^{2}}})^{-1}}$
Normal
with known mean μ
σ2 (variance) Scaled inverse chi-square ${\displaystyle \nu ,\ \sigma _{0}^{2}\!}$ ${\displaystyle \nu +n,{\frac {\nu \sigma _{0}^{2}+\sum _{i=1}^{n}(x_{i}-\mu )^{2}}{\nu +n}}\!}$
Normal
with known mean μ
τ (precision) Gamma ${\displaystyle \alpha ,\ \beta \!}$[4] ${\displaystyle \alpha +{\frac {n}{2}},\beta +{\frac {\sum _{i=1}^{n}(x_{i}-\mu )^{2}}{2}}\!}$
Normal
with known mean μ
σ2 (variance) Inverse Gamma Distribution ${\displaystyle \mathbf {\alpha ,\beta } }$ [4] ${\displaystyle \mathbf {\alpha } +{\frac {n}{2}},\mathbf {\beta } +{\frac {\sum _{i=1}^{n}{(x_{i}-\mu )^{2}}}{2}}}$
Normal μ and σ2
Assuming dependence
Normal-Scaled inverse gamma ${\displaystyle m,\ u,\ \nu ,\ \sigma ^{2}\ }$ ${\displaystyle {\frac {um+n{\bar {x}}}{u+n}},u+n,\nu +n,{\frac {\nu \sigma ^{2}+(n-1)S^{2}}{\nu +n}}+{\frac {nu({\bar {x}}-m)^{2}}{(u+n)(\nu +n)}}}$, where ${\displaystyle {\bar {x}}}$ is the sample mean and ${\displaystyle S^{2}}$ is the sample variance.
Normal μ and τ
Assuming dependence
Normal-gamma ${\displaystyle m,\ u,\ \alpha ,\ \beta \ }$ ${\displaystyle {\frac {um+n{\bar {x}}}{u+n}},u+n,\alpha +{\frac {n}{2}},\beta +{\frac {nS^{2}}{2}}+{\frac {nu({\bar {x}}-m)^{2}}{2(n+u)}}}$, where ${\displaystyle {\bar {x}}}$ is sample mean and ${\displaystyle S^{2}}$ is the sample variance.
Multivariate normal with known covariance matrix μ (mean vector) Multivariate normal ${\displaystyle \mathbf {\mu } _{0},\Sigma _{0}}$ ${\displaystyle \left(\Sigma _{0}^{-1}+n\Sigma ^{-1}\right)^{-1}\left(\Sigma _{0}^{-1}\mu _{0}+n\Sigma ^{-1}{\bar {x}}\right),\left(\Sigma _{0}^{-1}+n\Sigma ^{-1}\right)^{-1}}$, where ${\displaystyle {\bar {x}}}$ is the sample mean.
Multivariate normal Σ (variance matrix) inverse-Wishart
Pareto k (shape) Gamma ${\displaystyle \alpha ,\beta \!}$ ${\displaystyle \alpha +n,\ \beta +\sum _{i=1}^{n}\ln {\frac {x_{i}}{x_{\mathrm {m} }}}\!}$
Pareto xm (location) Pareto
Gamma
with known shape α
β (inverse scale) Gamma ${\displaystyle \alpha _{0},\beta _{0}\!}$ ${\displaystyle \alpha _{0}+\alpha ,\beta +x\!}$, (if ${\displaystyle n=1\!}$)
Gamma [5] α (shape), β (inverse scale) ${\displaystyle {\frac {1}{Z}}{\frac {p^{\alpha -1}e^{-\beta q}}{\Gamma (\alpha )^{r}\beta ^{-\alpha s}}}}$ ${\displaystyle p,q,r,s\!}$ ${\displaystyle p\prod _{i=1}^{n}x_{i},q+\sum _{i=1}^{n}x_{i},r+n,s+n\!}$

## Notes

1. Howard Raiffa and Robert Schlaifer. Applied Statistical Decision Theory. Division of Research, Graduate School of Business Administration, Harvard University, 1961.
2. Jeff Miller et al. Earliest Known Uses of Some of the Words of Mathematics, "conjugate prior distributions". Electronic document, revision of November 13, 2005, retrieved December 2, 2005.
3. Andrew Gelman, John B. Carlin, Hal S. Stern, and Donald B. Rubin. Bayesian Data Analysis, 2nd edition. CRC Press, 2003. ISBN 1-58488-388-X.
4. β is inverse scale or rate
5. Fink, D. 1995 A Compendium of Conjugate Priors. In progress report: Extension and enhancement of methods for setting data quality objectives. (DOE contract 95‑831).