For a pair of random variables, (X,T), suppose that the conditional distribution of X given T is given by
meaning that the conditional distribution is a normal distribution with mean μ {\displaystyle \mu } and precision λ T {\displaystyle \lambda T} — equivalently, with variance 1 / ( λ T ) . {\displaystyle 1/(\lambda T).}
Suppose also that the marginal distribution of T is given by
where this means that T has a gamma distribution. Here λ, α and β are parameters of the joint distribution.
Then (X,T) has a normal-gamma distribution, and this is denoted by
The joint probability density function of (X,T) is
where the conditional probability for f ( x , τ ∣ μ , λ , α , β ) = f ( x ∣ τ , μ , λ , α , β ) f ( τ ∣ μ , λ , α , β ) {\displaystyle f(x,\tau \mid \mu ,\lambda ,\alpha ,\beta )=f(x\mid \tau ,\mu ,\lambda ,\alpha ,\beta )f(\tau \mid \mu ,\lambda ,\alpha ,\beta )} was used.
By construction, the marginal distribution of τ {\displaystyle \tau } is a gamma distribution, and the conditional distribution of x {\displaystyle x} given τ {\displaystyle \tau } is a Gaussian distribution. The marginal distribution of x {\displaystyle x} is a three-parameter non-standardized Student's t-distribution with parameters ( ν , μ , σ 2 ) = ( 2 α , μ , β / ( λ α ) ) {\displaystyle (\nu ,\mu ,\sigma ^{2})=(2\alpha ,\mu ,\beta /(\lambda \alpha ))} .
The normal-gamma distribution is a four-parameter exponential family with natural parameters α − 1 / 2 , − β − λ μ 2 / 2 , λ μ , − λ / 2 {\displaystyle \alpha -1/2,-\beta -\lambda \mu ^{2}/2,\lambda \mu ,-\lambda /2} and natural statistics ln τ , τ , τ x , τ x 2 {\displaystyle \ln \tau ,\tau ,\tau x,\tau x^{2}} .
The following moments can be easily computed using the moment generating function of the sufficient statistic:2
where ψ ( α ) {\displaystyle \psi \left(\alpha \right)} is the digamma function,
If ( X , T ) ∼ N o r m a l G a m m a ( μ , λ , α , β ) , {\displaystyle (X,T)\sim \mathrm {NormalGamma} (\mu ,\lambda ,\alpha ,\beta ),} then for any b > 0 , ( b X , b T ) {\displaystyle b>0,(bX,bT)} is distributed as N o r m a l G a m m a ( b μ , λ / b 3 , α , β / b ) . {\displaystyle {\rm {NormalGamma}}(b\mu ,\lambda /b^{3},\alpha ,\beta /b).}
Assume that x is distributed according to a normal distribution with unknown mean μ {\displaystyle \mu } and precision τ {\displaystyle \tau } .
and that the prior distribution on μ {\displaystyle \mu } and τ {\displaystyle \tau } , ( μ , τ ) {\displaystyle (\mu ,\tau )} , has a normal-gamma distribution
for which the density π satisfies
Suppose
i.e. the components of X = ( x 1 , … , x n ) {\displaystyle \mathbf {X} =(x_{1},\ldots ,x_{n})} are conditionally independent given μ , τ {\displaystyle \mu ,\tau } and the conditional distribution of each of them given μ , τ {\displaystyle \mu ,\tau } is normal with expected value μ {\displaystyle \mu } and variance 1 / τ . {\displaystyle 1/\tau .} The posterior distribution of μ {\displaystyle \mu } and τ {\displaystyle \tau } given this dataset X {\displaystyle \mathbb {X} } can be analytically determined by Bayes' theorem3 explicitly,
where L {\displaystyle \mathbf {L} } is the likelihood of the parameters given the data.
Since the data are i.i.d, the likelihood of the entire dataset is equal to the product of the likelihoods of the individual data samples:
This expression can be simplified as follows:
where x ¯ = 1 n ∑ i = 1 n x i {\displaystyle {\bar {x}}={\frac {1}{n}}\sum _{i=1}^{n}x_{i}} , the mean of the data samples, and s = 1 n ∑ i = 1 n ( x i − x ¯ ) 2 {\displaystyle s={\frac {1}{n}}\sum _{i=1}^{n}(x_{i}-{\bar {x}})^{2}} , the sample variance.
The posterior distribution of the parameters is proportional to the prior times the likelihood.
The final exponential term is simplified by completing the square.
On inserting this back into the expression above,
This final expression is in exactly the same form as a Normal-Gamma distribution, i.e.,
The interpretation of parameters in terms of pseudo-observations is as follows:
As a consequence, if one has a prior mean of μ 0 {\displaystyle \mu _{0}} from n μ {\displaystyle n_{\mu }} samples and a prior precision of τ 0 {\displaystyle \tau _{0}} from n τ {\displaystyle n_{\tau }} samples, the prior distribution over μ {\displaystyle \mu } and τ {\displaystyle \tau } is
and after observing n {\displaystyle n} samples with mean μ {\displaystyle \mu } and variance s {\displaystyle s} , the posterior probability is
Note that in some programming languages, such as Matlab, the gamma distribution is implemented with the inverse definition of β {\displaystyle \beta } , so the fourth argument of the Normal-Gamma distribution is 2 τ 0 / n τ {\displaystyle 2\tau _{0}/n_{\tau }} .
Generation of random variates is straightforward:
Bernardo & Smith (1993, pages 136, 268, 434) ↩
Wasserman, Larry (2004), "Parametric Inference", Springer Texts in Statistics, New York, NY: Springer New York, pp. 119–148, ISBN 978-1-4419-2322-6, retrieved 2023-12-08 978-1-4419-2322-6 ↩
"Bayes' Theorem: Introduction". Archived from the original on 2014-08-07. Retrieved 2014-08-05. http://www.trinity.edu/cbrown/bayesweb/ ↩