S-114.600 Introduction to Bayesian
Hierarchical modeling with BUGS
Set up a
for a simple data set. We want to inspect the quality produced
by 5 machines in a factory. Quality assessment is expensive so only
5 measurements were made with each machine. In addition to the five machines,
we are also interested in the quality produced by a prospective sixth machine.
One way of doing this is to add a sixth machine with 'NA' (Not Available) measurements
to the data in BUGS.
- and a hierarchical model
Because the BUGS software is not too easy to use, the hierarchical model is given.
You only have to modify it to produce the pooled and separate models. And run the
simulations for the hierarchical model, of course.
You will need the following files:
In WinBUGS you can set up a model with Doodle or write the model directly.
Using Doodle is not recommended. Use the given model as such and as the basis
for the pooled and separate models. In WinBUGS you can run the model and save the results
with a few mouse clicks.
- bugs.dat: data
- bugsa.in: initial values for the pooled model
- bugsb.in: initial values for the separate model
- bugsc.in: initial values for the hierarchical model
- bugs.m: Matlab example on how to transfer the data to Matlab and convert
precision into variance.
- bugs.dat: data
- bugscwin.bug: the hierarchical model for WinBUGS
Open the files with WINBUGS File->Open... and select 'Text' as the file
format. Since x has missing values (NA), after 'load inits' you have to click
'gen inits' to generate the initial values for these.
Note that in BUGS the second parameter of the Gaussian distribution
(dnorm) is precision, the inverse of the variance, instead of standard deviation.
The conjugate prior on precision is the Gamma distribution (dgamma).
- the model specifications for the three models (not the entire
bug-file, just the specs)
- the posterior of the quality of the fifth machine with the
- the predictive distribution of the fifth machine with the
- the posterior of the expected value of the quality of the sixth machine with the
- some commentary (a few sentences) on the results
The following function lets you read the results given by BUGS into Matlab
for analysis (see also the example in bugs.m)
This page is maintained by
This page has been updated 9. 10. 2003