For a pair of random variables,, suppose that the conditional distribution of X given T is given by meaning that the conditional distribution is a normal distribution with mean and precision — equivalently, with variance 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 has a normal-gamma distribution, and this is denoted by
By construction, the marginal distribution of is a gamma distribution, and the conditional distribution of given is a Gaussian distribution. The marginal distribution of is a three-parameter non-standardized Student's t-distribution with parameters.
Assume that x is distributed according to a normal distribution with unknown mean and precision. and that the prior distribution on and, , has a normal-gamma distribution for which the density satisfies Suppose i.e. the components of are conditionally independent given and the conditional distribution of each of them given is normal with expected value and variance The posterior distribution of and given this dataset can be analytically determined by Bayes' theorem. Explicitly, where is the likelihood of the data given the parameters. 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, the mean of the data samples, and, 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.,
Interpretation of parameters
The interpretation of parameters in terms of pseudo-observations is as follows:
The new mean takes a weighted average of the old pseudo-mean and the observed mean, weighted by the number of associated observations.
The precision was estimated from pseudo-observations with sample mean and sample variance .
The posterior updates the number of pseudo-observations simply by adding up the corresponding number of new observations.
As a consequence, if one has a prior mean of from samples and a prior precision of from samples, the prior distribution over and is and after observing samples with mean and variance, the posterior probability is Note that in some programming languages, such as Matlab, the gamma distribution is implemented with the inverse definition of, so the fourth argument of the Normal-Gamma distribution is.
Generating normal-gamma random variates
Generation of random variates is straightforward:
Sample from a gamma distribution with parameters and
Sample from a normal distribution with mean and variance