Lecture 28 Bayesian Inference: Priors and Posteriors
So far the parameter has been a fixed but unknown number, and a sentence such as “ is probably close to ” had no meaning. In this lecture and in lecture 29 we will see that the parameter itself can be given a probability distribution. The prior distribution is chosen before the data are seen, and the posterior distribution is obtained from it once the data are seen.
28.1 Prior, Likelihood and Posterior
In the Bayesian approach the parameter is a random variable. The model then describes the distribution of the data for a given value of the parameter, and thus the model density is a conditional density. In the Bayesian lectures we write it as instead of . Here is the whole data set, so that is the likelihood of lecture 4.
Let be a random variable with values in and density , and assume that given the data have joint density (or probability weights) . Then the density is called the prior density (or prior) of and the conditional density of given is called the posterior density (or posterior).
The prior represents the knowledge about which is available before the data are seen, and where there is little such knowledge we choose it by a rule which depends only on the model (section 28.4), so that the posterior is determined by the data as far as possible. We use the letter for both densities, and the argument shows which one is meant: is the prior and is the posterior.
The following lemma shows how the posterior is computed from the prior and the likelihood. It is Bayes’ theorem (proposition A.20) for the parameter and the data.
In the situation of definition 28.1, let be the marginal density of the data. Then the posterior density is given by
The joint density of is given by . Integrating out gives the marginal density of . Dividing the joint density by gives the conditional density of given . This completes the proof. ∎
The denominator makes the posterior integrate to one and does not involve . In practice we therefore do not compute it directly, but write
where means “equal up to a factor free of ”. In words, the posterior is proportional to the likelihood times the prior. We then try to recognise the right-hand side as the kernel of a known density, i.e. as the density with its normalising constant removed. The missing constant can then be read off from table A.2.
The posterior is the complete Bayesian answer. A statement like “” now has a meaning.
28.2 Conjugate Priors
The rule (28.2) works best if the posterior distribution belongs to the same family of distributions as the prior distribution, so that the update only changes the parameters of the prior. These parameters are called hyperparameters.
A family of prior distributions is conjugate for a model with densities , if for every prior in and every data set the posterior also belongs to .
For exponential families, conjugate priors can be written down by inspection: the likelihood depends on the natural parameter only through the exponent (lemma 7.5), and for a prior with an exponent of the same form the posterior has this form again.
Let with be a one-parameter exponential family in its natural parametrisation, and for real numbers and let
for all , whenever the right-hand side has a finite integral over . Then these priors are conjugate for the model: if the prior is , the data have natural statistic and the marginal density satisfies , then the posterior is .
The update adds the natural statistic to and the sample size to . We now compute the posterior for the Bernoulli model directly, in terms of the original parameter.
Let be i.i.d. Bernoulli with success probability and let the prior be the distribution with . From table A.2 we know that this distribution has density
for , and mean . If is the number of successes in the sample, then the likelihood is , as in example 5.3, and thus we have
The right-hand side is the kernel of the density, i.e. this density without its normalising constant . Since the posterior integrates to one, it must have the same constant, and thus the posterior distribution is with density
for . The Beta distributions are therefore conjugate for the Bernoulli model, and the update adds the successes to and the failures to . The posterior mean is given by
which is a weighted average of the prior mean and the sample proportion , i.e. the maximum likelihood estimate from example 5.3. The weight of the prior mean tends to zero as .
The example is an instance of proposition 28.4. Changing variables to the log-odds of example 7.2, with the factor from proposition A.19, turns the prior into . Thus the prior acts like earlier observations, of which were successes. This equivalent sample size is a guide for choosing the hyperparameters in practice (exercise 28.1). For , and the posterior distribution is with mean , between the prior mean and the sample proportion .
The same proposition shows that normal priors are conjugate for the normal mean with known variance: the cumulant function of this model is quadratic (exercise 7.5), and thus the priors with are normal densities. The following proposition gives the updated mean and variance. Its proof, which is based on completing the square, is exercise 28.3.
Let be i.i.d. with known variance and let the prior be . Then the posterior distribution is where
The reciprocal of a variance is called a precision. The proposition shows that precisions add, and that the posterior mean is the average of and , weighted by the prior precision and the precision of .
28.3 Point Estimates from the Posterior
If a single number is required for , the posterior mean, median and mode can all be used. If the error of an estimate is measured by its square, as in lecture 2, the following lemma shows that the optimal choice is the posterior mean . This is called the Bayes estimator (under squared error) for .
Assume that the posterior distribution has finite variance. Then the posterior mean minimises the posterior expected squared error, i.e. for every number we have
and the inequality is strict unless .
Adding and subtracting inside the square, as in the proof of lemma 2.7, we get
The middle term vanishes, because , and the last term is non-negative and zero only for . This completes the proof. ∎
28.4 Flat, Improper and Jeffreys Priors
If little is known about before the data are seen, the obvious choice is the flat prior, which is constant on . For the Bernoulli model this prior is and from example 28.5 we know that the posterior mean is , which is close to but is shifted towards .
On an unbounded parameter space a constant function has infinite integral and thus is not a density. A prior with infinite integral is called improper. Improper priors are nevertheless used: if has finite integral over , this product is normalised and used as the formal posterior. The finiteness of the integral must be checked in each case (exercise 28.2). For the normal mean, the flat prior on leads to the proper posterior , because the likelihood, as a function of , is proportional to this density (exercise 28.3).
The flat prior has a more basic defect: flatness depends on the parametrisation. If is uniform on , then has density by proposition A.19, and a prior which is meant to express no knowledge about expresses some knowledge about . A rule which does not depend on the parametrisation can be built from the Fisher information, since proposition 11.9 shows how the information transforms.
In the situation of section 11.1, the Jeffreys prior for is given by
for all , where is the Fisher information of an observation.
This prior is justified by the following invariance property, which the flat prior lacks.
Let where is a twice continuously differentiable bijection with for all , and let and be as in proposition 11.9. If has the Jeffreys prior , then has the density . This is the Jeffreys prior computed using the -parametrisation.
Let . If has density , then the change-of-variable formula from proposition A.19 shows that has density . For an improper prior there is no random variable to transform, and we take this formula as the definition of the transformed prior. Using proposition 11.9 and for we get
This completes the proof. ∎
Depending on the model, the Jeffreys prior can be proper or improper.
For the Bernoulli model, from example 11.5 we know and thus the Jeffreys prior is given by
for . This is the kernel of the density. The Jeffreys prior is proper and has more weight near the boundaries of the interval than the flat prior does. From example 28.5 we know that the posterior distribution is with mean .
A location model has densities with , and a scale model has densities with , where is a fixed density. Under the conditions of section 11.1, the Fisher information is constant in a location model and is with a constant in a scale model (exercise 28.5). Thus, whatever the density , the Jeffreys prior is flat for a location parameter and is proportional to for a scale parameter. Both priors are improper. For example, the normal mean with known variance is a location parameter, and the model is a scale model with .
-
•
The data can be used to update the prior density to the posterior . The normalising constant can be found by recognising the kernel of a known density.
-
•
A family of priors is conjugate for a model if the posterior always belongs to the same family. For a one-parameter exponential family in its natural parametrisation, the priors proportional to are conjugate. Beta priors are conjugate for the Bernoulli model, and normal priors are conjugate for the normal mean with known variance.
-
•
For the Beta-Bernoulli and normal-normal pairs, the posterior mean is a weighted average of the prior mean and the maximum likelihood estimate. As increases, the prior weight decreases. The posterior mean is the Bayes estimator for under squared error.
-
•
A flat prior is not invariant under reparametrisation, but the Jeffreys prior is. The Jeffreys prior is for the Bernoulli model, is flat for a location parameter, and is proportional to for a scale parameter. An improper prior can only be used if the posterior is proper.
A Bernoulli model is to be fitted with a prior for the success probability .
-
1.
Find and such that the prior mean is and the equivalent sample size is . Use the variance in table A.2 to find the prior standard deviation.
-
2.
Find and such that the prior has mean and standard deviation . What is the equivalent sample size for this prior?
-
3.
For the prior in the first part of the question, a sample of size has successes. Determine the posterior distribution and the posterior mean. Write the posterior mean as a weighted average of the prior mean and .
The Haldane prior for the Bernoulli success probability is the limit of the kernel , i.e. the function for .
-
1.
Show that this prior is improper.
-
2.
Show that the formal posterior is a proper distribution if and only if . Identify the resulting distribution.
-
3.
For , determine the posterior mean and compare it to the maximum likelihood estimate.
-
4.
Describe what happens for .
Using the following steps, prove proposition 28.6.
-
1.
Show that the likelihood, as a function of , satisfies .
-
2.
Multiply the prior density by this function and show, by completing the square in , that
where and are as in the proposition.
-
3.
What happens to and when with fixed? And when with fixed?
Let be i.i.d. Bernoulli with success probability and let with be the Bayes estimator from example 28.5. Now fix and regard as an estimator in the sense of lecture 2.
-
1.
What are the bias and variance of ? Show that the estimator is biased for every , but consistent.
-
2.
For and , compare the mean squared errors and for and .
Let be a fixed density such that the following models satisfy the conditions of section 11.1, and let .
-
1.
For the location model , show that the score is and thus that the Fisher information does not depend on .
-
2.
For the scale model and , show that the score is and that where does not depend on .
-
3.
For the model with parameter , show that .