[bugsicon]     Introduction

Contents

    Intoduction to WinBUGS
    Advice for new users
    MCMC methods
    How  WinBUGS  syntax differs from that of  Classic   BUGS
    Changes from WinBUGS 1.3
   


Intoduction to WinBUGS [top]
This manual describes the
WinBUGS software - an interactive Windows version of the BUGS program for Bayesian analysis of complex statistical models using Markov chain Monte Carlo (MCMC) techniques. WinBUGS allows models to be described using a slightly amended version of the BUGS language, or as Doodles (graphical representations of models) which can, if desired, be translated to a text-based description. The BUGS language is more flexible than the Doodles.

Users are advised that this manual only concerns the syntax and functionality of WinBUGS , and does not deal with issues of Bayesian reasoning, prior distributions, statistical modelling, monitoring convergence, and so on. If you are new to MCMC, you are strongly advised to use this software in conjunction with a course in which the strengths and weaknesses of this procedure are described. Please note the disclaimer at the beginning of this manual.

There is a large literature on Bayesian analysis and MCMC methods. For further reading, see, for example, Carlin and Louis (1996), Gelman et al (1995), Gilks, Richardson and Spiegelhalter (1996): Brooks (1998) provides an excellent introduction to MCMC. Chapter 9 of the
Classic BUGS manual, 'Topics in Modelling', discusses 'non-informative' priors, model criticism, ranking, measurement error, conditional likelihoods, parameterisation, spatial models and so on, while the CODA documentation considers convergence diagnostics. Congdon (2001) shows how to analyse a very wide range of models using WinBUGS . The BUGS website provides additional links to sites of interest, some of which provide extensive examples and tutorial material.

Note that
WinBUGS simulates each node in turn: this can make convergence very slow and the program very inefficient for models with strongly related parameters, such as hidden-Markov and other time series structures.

Advice for new users [top]
Although
WinBUGS can be used without further reference to any of the earlier BUGS project, experience with using Classic BUGS may be an advantage, and certainly the documentation on BUGS Version 0.5 and 0.6 (available from http://www.mrc-bsu.cam.ac.uk/bugs) contains examples and discussion on wider issues in modelling using MCMC methods. If you are using WinBUGS for the first time, the following stages might be reasonable:

1. Step through the
simple worked example in the tutorial.
2. Try other examples provided with this release (see
Examples Volume 1 ,
Examples Volume 2 and Examples Volume 3 )
3. Edit the
BUGS language to fit an example of your own.

If you are interested in using Doodles:

4. Try editing an existing Doodle (e.g. from Examples Volume 1 ), perhaps to fit a problem of your own.
5. Try constructing a Doodle from scratch.

Note that there are many features in the
BUGS language that cannot be expressed with Doodles. If you wish to proceed to serious, non-educational use, you may want to dispense with DoodleBUGS entirely, or just use it for initially setting up a simplified model that can be elaborated later using the BUGS language. Unfortunately we do not have a program to back-translate from a text-based model description to a Doodle!

MCMC methods [top]
Users should already be aware of the background to Bayesian Markov chain Monte Carlo methods: see for example Gilks
et al (1996). Having specified the model as a full joint distribution on all quantities, whether parameters or observables, we wish to sample values of the unknown parameters from their conditional (posterior) distribution given those stochastic nodes that have been observed. The basic idea behind the Gibbs sampling algorithm is to successively sample from the conditional distribution of each node given all the others in the graph (these are known as full conditional distributions): the Metropolis-within-Gibbs algorithm is appropriate for difficult full conditional distributions and does not necessarily generate a new value at each iteration. It can be shown that under broad conditions this process eventually provides samples from the joint posterior distribution of the unknown quantities. Empirical summary statistics can be formed from these samples and used to draw inferences about their true values.

The sampling methods are used in the following hierarchies (in each case a method is only used if no previous method in the hierarchy is appropriate):

   Continuous target distribution   Method
   

   Conjugate   Direct sampling using standard algorithms
   Log-concave   Derivative-free adaptive rejection sampling
         (Gilks, 1992)
   Restricted range   Slice sampling (Neal, 1997)
   Unrestricted range   Current point Metropolis
      
   Discrete target distribution   Method

   Finite upper bound   Inversion
   Shifted Poisson   Direct sampling using standard algorithm
   
In cases where the graph contains a Generalized Linear Model (GLM) component, it is possible to request (see Updater options... ) that WinBUGS groups (or 'blocks') together the fixed-effect parameters and updates them via the multivariate sampling technique described in Gamerman (1997) . This is essentially a Metropolis-Hastings algorithm where at each iteration the proposal distribution is formed by performing one iteration, starting at the current point, of Iterative Weighted Least Squares (IWLS).

If WinBUGS is unable to classify the full conditional for a particular parameter (p, say) according to the above hierarchy, then an error message will be returned saying "Unable to choose update method for p".

Simulations are carried out univariately, except for explicitly defined multivariate nodes and, if requested, blocks of fixed-effect parameters in GLMs (see above ). There is also the option of using ordered over-relaxation (Neal, 1998), which generates multiple samples at each iteration and then selects one that is negatively correlated with the current value. The time per iteration will be increased, but the within-chain correlations should be reduced and hence fewer iterations may be necessary. However, this method is not always effective and should be used with caution.

A slice-sampling algorithm is used for non log-concave densities on a restricted range. This has a default adaptive phase of 500 iterations which will be discarded from all summary statistics.

The current Metropolis MCMC algorithm is based on a symmetric normal proposal distribution, whose standard deviation is tuned over the first 4000 iterations in order to get an acceptance rate of between 20% and 40%. All summary statistics for the model will ignore information from this adapting phase.

It is possible for the user to change some aspects of the various available MCMC updating algorithms, such as the length of an adaptive phase - please see Update options... for details. It is also now possible to change the sampling methods for certain classes of distribution, although this is delicate and should be done carefully - see Changing MCMC Defaults (advanced users only) for details.

The shifted Poisson distribution occurs when a Poisson prior is placed on the order of a single binomial observation.

How WinBUGS syntax differs from that of Classic BUGS [top]

Changes to the
BUGS syntax have been kept, as far as possible, to simplifications. There is now:

- No need for constants (these are declared as part of the data).
- No need for variable declaration (but all names used to declare data must appear in the model).
- No need to specify files for data and initial values.
- No limitation on dimensionality of arrays.
- No limitation on size of problems (except those dictated by hardware).
- No need for semi-colons at end of statements (these were never necessary anyway!)

A major change from the
Classic BUGS syntax is that when defining multivariate nodes, the range of the variable must be explicitly defined: for example

         x[1:K] ~ dmnorm(mu[], tau[,])

must be used instead of x[] ~ dmnorm(mu[], tau[,]), and for precision matrices you must write, say

         tau[1:K, 1:K] ~ dwish(R[,], 3)

rather than tau[,] ~ dwish(R[,], 3).

The following format must now be used to invert a matrix:

         sigma[1:K, 1:K] <- inverse(tau[,])
      
Note that inverse(.) is now a vector-valued function as opposed to the relatively inefficient component-wise evaluation required in previous versions of the software.

To convert Classic BUGS files to run under WinBUGS :
   
   a) Open the .bug file as a text file, delete unnecessary declarations, and save as an .odc document.
   b) Open .dat files: data has to be formatted as described in
Formatting of data : eg
      * matrices in data files need to have the full '.structure' format
      * all data in datafile need to be described in the model
      * need data list of constants and file sizes
      * need column headings on rectangular arrays
      The data can be copied into the .odc file, or kept as a separate file.
   c) Copy the contents of the .in file into the .odc file.
   
Changes from WinBUGS 1.3 [top]
- modular on-line manual;
-
ability to run in batch-mode using scripts ;
- running of default
script on start-up to allow calling from other programs;
- new graphics (see
here , for example) and editing of graphics - note that graphics from previous versions of the software will be incompatible with this version (2.0) ;
-
missing data and range constraints allowed for multivariate normal;
- new distributions:
negative binomial , generalized gamma , multivariate Student-t ;
-
DIC menu option for model comparison;
-
Options menu , for advanced control of MCMC algorithms, for example;
-
new syntax for (more efficient) 'inverse' function;
-
"interp.lin" interpolation function, "cut" function;
- recursively- (and thus efficiently-) calculated
running quantiles ;
- MCMC algorithms: block updating of fixed effects - see
here and/or here for details;
-
non-integer binomial and Poisson data ;
-
Poisson as prior for continuous quantity ;
-
'coverage' of random number generator ;
- additional restrictions:
END key word for rectangular arrays;
- spatial (CAR) models moved to GeoBUGS;
-
new display options ;
-
now possible to print out posterior correlation coefficients for monitored variables ;
- new manual sections: Batch-mode: Scripts , Tricks , WinBUGS Graphics , Tutorial , and Changing MCMC Defaults .