In Bayesian probability theory, if, given a likelihood function <math>p(x \mid \theta)</math>, the posterior distribution <math>p(\theta \mid x)</math> is in the same probability distribution family as the prior probability distribution <math>p(\theta)</math>, the prior and posterior are then called conjugate distributions with respect to that likelihood function and the prior is called a conjugate prior for the likelihood function <math>p(x \mid \theta)</math>.
A conjugate prior is an algebraic convenience, giving a closed-form expression for the posterior; otherwise, numerical integration may be necessary. Further, conjugate priors may clarify how a likelihood function updates a prior distribution.
The concept, as well as the term "conjugate prior", were introduced by Howard Raiffa and Robert Schlaifer in their work on Bayesian decision theory.
Example
The form of the conjugate prior can generally be determined by inspection of the probability density or probability mass function of a distribution. For example, consider a random variable which consists of the number of successes <math>s</math> in <math>n</math> Bernoulli trials with unknown probability of success <math>q</math> in [0,1]. This random variable will follow the binomial distribution, with a probability mass function of the form
:<math>p(s) = {n \choose s}q^s (1-q)^{n-s}</math>
The usual conjugate prior is the beta distribution with parameters (<math>\alpha</math>, <math>\beta</math>):
:<math>p(q) = {q^{\alpha-1}(1-q)^{\beta-1} \over \Beta(\alpha,\beta)}</math>
where <math>\alpha</math> and <math>\beta</math> are chosen to reflect any existing belief or information (<math>\alpha=1</math> and <math>\beta=1</math> would give a uniform distribution) and <math>\Beta(\alpha,\beta)</math> is the Beta function acting as a normalising constant.
In this context, <math>\alpha</math> and <math>\beta</math> are called hyperparameters (parameters of the prior), to distinguish them from parameters of the underlying model (here <math>q</math>). A typical characteristic of conjugate priors is that the dimensionality of the hyperparameters is one greater than that of the parameters of the original distribution. If all parameters are scalar values, then there will be one more hyperparameter than parameter; but this also applies to vector-valued and matrix-valued parameters. (See the general article on the exponential family, and also consider the Wishart distribution, conjugate prior of the covariance matrix of a multivariate normal distribution, for an example where a large dimensionality is involved.)
If we sample this random variable and get <math>s</math> successes and <math>f = n - s</math> failures, then we have
:<math>\begin{align}
P(s, f \mid q=x) &= {s+f \choose s} x^s(1-x)^f,\\
P(q=x) &= {x^{\alpha-1}(1-x)^{\beta-1} \over \Beta(\alpha,\beta)},\\
P(q=x \mid s,f) &= \frac{P(s, f \mid x)P(x)}{\int P(s, f \mid y)P(y)dy}\\
& = {0!} \approx 0.93</math>
This is the Poisson distribution that is the most likely to have generated the observed data <math>\mathbf{x}</math>. But the data could also have come from another Poisson distribution, e.g., one with <math>\lambda = 3</math>, or <math>\lambda = 2</math>, etc. In fact, there is an infinite number of Poisson distributions that could have generated the observed data. With relatively few data points, we should be quite uncertain about which exact Poisson distribution generated this data. Intuitively we should instead take a weighted average of the probability of <math>p(x>0| \lambda)</math> for each of those Poisson distributions, weighted by how likely they each are, given the data we've observed <math>\mathbf{x}</math>.
Generally, this quantity is known as the posterior predictive distribution <math>p(x|\mathbf{x}) = \int_\theta p(x|\theta)p(\theta|\mathbf{x})d\theta\,,</math> where <math>x</math> is a new data point, <math>\mathbf{x}</math> is the observed data and <math>\theta</math> are the parameters of the model. Using Bayes' theorem we can expand <math>p(\theta|\mathbf{x}) = \frac{p(\mathbf{x}|\theta)p(\theta)}{p(\mathbf{x})}\,,</math> therefore <math>p(x|\mathbf{x}) = \int_\theta p(x|\theta)\frac{p(\mathbf{x}|\theta)p(\theta)}{p(\mathbf{x})}d\theta\,.</math> Generally, this integral is hard to compute. However, if you choose a conjugate prior distribution <math>p(\theta)</math>, a closed-form expression can be derived. This is the posterior predictive column in the tables below.
Returning to our example, if we pick the Gamma distribution as our prior distribution over the rate of the Poisson distributions, then the posterior predictive is the negative binomial distribution, as can be seen from the table below. The Gamma distribution is parameterized by two hyperparameters <math>\alpha, \beta</math>, which we have to choose. By looking at plots of the gamma distribution, we pick <math>\alpha = \beta = 2</math>, which seems to be a reasonable prior for the average number of cars. The choice of prior hyperparameters is inherently subjective and based on prior knowledge.
Given the prior hyperparameters <math>\alpha</math> and <math>\beta</math> we can compute the posterior hyperparameters <math display="inline">\alpha' = \alpha + \sum_i x_i = 2 + 3+4+1 = 10</math> and <math display="inline">\beta' = \beta + n = 2+3 = 5</math>
Given the posterior hyperparameters, we can finally compute the posterior predictive of <math display="inline">p(x>0|\mathbf{x}) = 1-p(x=0|\mathbf{x}) = 1 - NB\left(0\, |\, 10, \frac{5}{1+5}\right) \approx 0.84</math>
This much more conservative estimate reflects the uncertainty in the model parameters, which the posterior predictive takes into account.
Table of conjugate distributions
Let n denote the number of observations. In all cases below, the data is assumed to consist of n points <math>x_1,\ldots,x_n</math> (which will be random vectors in the multivariate cases).
If the likelihood function belongs to the exponential family, then a conjugate prior exists, often also in the exponential family; see Exponential family: Conjugate distributions.
When the likelihood function is a discrete distribution
{| class="wikitable"
! Likelihood <br> <math>p(x_i|\theta)</math>!! Model parameters <br> <math>\theta</math>!! Conjugate prior (and posterior) distribution <br> <math>p(\theta|\Theta), p(\theta|\mathbf{x},\Theta) = p(\theta|\Theta') </math>!! Prior hyperparameters <br><math>\Theta</math>!! Posterior hyperparameters
|-
| Normal<br>with known precision τ || μ (mean) || Normal || <math>\mu_0,\, \tau_0^{-1}\!</math>|| <math> \frac{\tau_0 \mu_0 + \tau \sum_{i=1}^n x_i}{\tau_0 + n \tau},\, \left(\tau_0 + n \tau\right)^{-1}</math>
| mean was estimated from observations with total precision (sum of all individual precisions)<math>\tau_0</math> and with sample mean <math>\mu_0</math>
| <math>\mathcal{N}\left(\tilde{x}\mid\mu_0', \frac{1}{\tau_0'} +\frac{1}{\tau}\right)</math>|| μ and σ<sup>2</sup><br>Assuming exchangeability|| Normal-inverse gamma
| <math> \mu_0 ,\, \nu ,\, \alpha ,\, \beta</math>|| <math>\frac{\nu\mu_0+n\bar{x{\nu+n} ,\, \nu+n,\, \alpha+\frac{n}{2} ,\, </math><br/><math>
\beta + \tfrac{1}{2} \sum_{i=1}^n (x_i - \bar{x})^2 + \frac{n\nu}{\nu+n}\frac{(\bar{x}-\mu_0)^2}{2} </math>
- <math> \bar{x} </math> is the sample mean
| mean was estimated from <math>\nu</math> observations with sample mean <math>\mu_0</math>; variance was estimated from <math>2\alpha</math> observations with sample mean <math>\mu_0</math> and sum of squared deviations <math>2\beta</math>
| <math>t_{2\alpha'}\left(\tilde{x}\mid\mu',\frac{\beta'(\nu'+1)}{\nu' \alpha'}\right)</math>
| <math>\operatorname{Lomax}(\tilde{x}\mid\beta',\alpha')</math><br />(Lomax distribution)
|-
| Gamma <br>with known shape α|| β (rate) || Gamma || <math>\alpha_0,\, \beta_0\!</math>||<math>\alpha_0+n\alpha,\, \beta_0+\sum_{i=1}^n x_i\!</math>
| <math>\alpha_0/\alpha</math> observations with sum <math>\beta_0</math>
| <math>\operatorname{CG}(\tilde{\mathbf{x\mid\alpha,{\alpha_0}',{\beta_0}')=\operatorname{\beta'}(\tilde{\mathbf{x|\alpha,{\alpha_0}',1,{\beta_0}')</math>
.
