Here is code for one of the problems in Problem Set #6, which we briefly discussed.

We discussed the hierarchical model in the homework, since we need the full conditionals for a problem to be posed for the next homework assignment. It is given by:

Need to find the full conditionals:

To do this, we want We see that

So, looking only at terms involving , (see * above), we can read off that

Similarly, from (*), looking at the terms involving , we see that

The secret is that we used conjugate priors…building a hierarchical model using conjugate priors gave us the full conditionals in a form that we could sample from effectively.

So…the general procedure for getting the full conditionals is first to write down the joint distribution, ignoring constants. Look at this, and pick out those terms that depend on the parameter being sampled on. Ignore terms that don’t depend on that parameter. See if you can recognize this as the kernel of a standard distribution from which you can sample.

MCMC allows us to do this even if the full conditionals cannot easily be sampled from.

Jeff then provided some useful definitions of various distributions (e.g., gamma’s, , inverse gamma).

Def: means

Def: means

Def: means

Fact: If then

from which we get

for , mode is

Fact: If then

Fact: If then

Fact: inverse gamma is the conjugate prior for normal models, i.e., if then if the prior on is , we have

Another example of Gibbs sampling: Normal model with uninformative priors

Suppose and (looks like but is improper. )

Recall that , where

So

We have the full conditional for . Need the full conditional for . Write down likelihood*prior, see if we recognize it.

Joint is By inspection this is inverse gamma with parameters N/2, S/2, where .

So

Note that we went from N-1 dof in the marginal-conditional sampling earlier to N dof in Gibbs sampling. This is because we already know when sampling on but we did not know it when doing the marginal-conditional sampling. In the previous case the difference involves , but here it involves .

We looked at a program to do this. Looked at some nice plots.

Started with (way off). What happens? The sampler very quickly moved to the region of interest.

But we wouldn’t want to include the first values in the posterior sample…they are anomalies. So often we run for a long time and discard some portion of the first samples. This is the “burn-in”.

Showed trace plot for and for this example (starting way off). The ones he showed illustrated good mixing.

Convergence issues are the “Achilles’ heel” of MCMC. There are no accepted standards for convergence. You have to be very careful, because you may not have sampled the whole sample space. Sampling from various starting points. Winbugs code to start from multiple places to see if you get the same results. What’s really problematic are multimodal posterior distributions. There are methods to handle these, but they are not trivial to implement.

## Leave a Reply