Conjugate priors have been widely used in many Bayesian inference techniques. Therefore it is very important to understand its basic concepts. In this blog post, I will introduce the concept of conjugate priors and give a concrete example of proving conjugate priors.
Definition
According to Bayes’ theorem, it is universally true that
In Bayesian probability theory, if the posterior distributions p(θ∣x) are in the same probability distribution family as the prior probability distribution p(θ), the prior and posterior are then called conjugate distributions, and the prior is called a conjugate prior for the likelihood function p(x∣θ).
Example
If we have random variable μ from normal distribution N(μ0,σ02), i.e.,
p(μ)=2πσ021e−2σ02(μ−μ0)2
We also have random variable x from normal distribution N(μ,σ2), i.e.,
p(x∣μ)=2πσ21e−2σ2(x−μ)2
Note that μ0,σ02,σ2 are not random variable but prefixed parameters in this case.
We have N data points X={x1,x2,⋯,xN} independently sampled from normal distribution N(μ,σ2).
p(X∣μ)=[2πσ21]Ne−2σ2∑i=1N(xi−μ)2
We will show that p(μ∣X) is also a normal distribution, thus the posterior p(μ∣X) and the prior p(μ) are in the same normal distribution family and they are conjugate. p(μ) is a conjugate prior for the likelihood p(X∣μ).
Here const are terms irrelevant to random variable μ. For simplicity, we define:
μ′=σ2N+σ021σ2NXˉ+σ02μ0σ′2=(σ2N+σ021)−1
Therefore, p(μ∣X) follows normal distribution N(μ′,σ′2). Since both the posterior p(μ∣X) and the prior p(μ) are in the normal distribution family, we say that p(μ)∼N(μ0,σ02) is a conjugate prior for the likelihood p(X∣μ). It turns out that p(X∣μ) is a multivariate normal distribution by definition.
Caveats
By the way, the distribution of the mean of X, p(Xˉ∣μ), is an exact normal distribution. But the proof I found was oversimplified.
Here is what they did. They first define random variables:
Xˉ=N1i=1∑Nxis2=N−11i=1∑N(xi−Xˉ)2
Then they transform the probability density expression for p(X∣μ):
Is random variable s related to Xˉ? It has been proved that s and Xˉ are independent, given the samples are normally distributed. One of the proofs could be found here, which surprised me because I never thought it would be non-trivial. We may come back to this proof in the future.
Therefore, we could remove exp{2σ2(N−1)s2} from the right side since s and Xˉ are independent.
Therefore, p(Xˉ∣μ) strictly follows the exact normal distribution N(Xˉ∣μ;Nσ2).
This has something related to the central limit theorem. The central limit theorem states as the sample size become sufficiently large, the distribution of sample means approximates to normal distribution, regardless of what distribution the samples come from. It approximates normal distribution, but it might not be the exact normal distribution. In our case, with our derivation, we showed that the distribution of sample means is an exact normal distribution if the samples come from a normal distribution.
Final Remarks
Deriving and proving conjugate priors could be complex and tedious. Fortunately, Wikipedia has documented all the known conjugate prior for certain likelihoods so far.
One last important property, all members of the exponential family have conjugate priors. This property is very useful in variational inference. Normal distribution is one of the members of the exponential family. For example, as we have shown, in our case p(x∣μ) (there is only one sample in X) does have a conjugate prior which follows normal distribution.
Acknowledgement
I would like to thank CrazyStat from Hacker News for providing critical comments and corrections to this post.