[logo]
The BUGS Project
The BUGS Project
demonstration
((((
Welcome Page
Latest News
Contact us/BUGS list
WinBUGS
New WinBUGS examples
FAQs
DIC
GeoBUGS
PKBUGS
Running from other software
BUGS resources online
WinBUGS development site
OpenBUGS site

More About the Surgical Example

Principles of statistical analysis using BUGS

BUGS is a program that carries out Bayesian inference on statistical problems using a simulation technique known as Gibbs sampling. BUGS assumes a Bayesian or full probability model, in which all quantities are treated as random variables. The model consists of a defined joint distribution over all unobserved (parameters and missing data) and observed quantities (the data); we then need to condition on the data in order to obtain a posterior distribution over the parameters and unobserved data. Marginalising over this posterior distribution in order to obtain inferences on the main quantities of interest is carried out using a Monte Carlo approach to numerical integration (Gibbs sampling). Instead of calculating exact or approximate estimates, this computer-intensive technique generates a stream of simulated values for each quantity of interest. These samples must then be examined to check convergence. Empirical summary statistics (means, interval estimates, density plots etc.) can then be formed from these samples and used to draw inferences about the true values of the quantities of interest.

Specifying a model for the surgical example

The number of deaths tex2html_wrap_inline267 for hospital i may be modelled as a binary response variable with `true' failure probability tex2html_wrap_inline271 :

eqnarray44

Rather than assume complete independence, we suppose that the failure rates across hospitals are similar in some way. This is equivalent to specifying a random effects model for the true failure probabilities tex2html_wrap_inline271 as follows:

eqnarray51

Note that (for computational reasons) the parameterisation of the normal distribution is non-standard, i.e. tex2html_wrap_inline275 = 1/variance(Y) = the precision of the random effects.

To complete the specification of our Bayesian full probability model, we assume standard `non-informative' priors for the population mean (logit) probability of failure, tex2html_wrap_inline279 , and precision, tex2html_wrap_inline281 :

eqnarray56

Programming the example using the BUGS language

The BUGS language allows a concise expression for the above model. The user creates an ASCII text file which contains the model description. The file surgical.bug containing the BUGS model description for the surgical example is shown below.

model surgical;
const
   N = 12;    # number of hospitals 
var
    r[N],     # number of deaths
    n[N],     # total number of operations
    p[N],     # `true' probability of death
      mu,     # population mean failure rate (on logit scale)
     tau;     # precision of the random effects

data r, n in "surgical.dat";
inits in "surgical.in";

{
  for (i in 1:N) {
    r[i] ~ dbin(p[i], n[i]);
    logit(p[i]) <- b[i];
    b[i] ~ dnorm(mu, tau);
  }

# Priors:
  mu ~ dnorm(0.0,1.0E-6);
  tau ~ dgamma(1.0E-3, 1.0E-3); 
}

The first part of the file contains declarations that specify the name of the model, any constants, the variables that might be used, and the files containing the data and initial values. (In order to start the Gibbs sampler simulation, initial values must be specified for all variables that are not given values in the data file. If the user does not specify these in the initial value file, BUGS will generate appropriate values automatically). The remainder of the model description file contains a declarative representation of the full probability model. (Note that a hash - # - indicates that the rest of the line is a comment and is ignored by the program.)

Running the example in BUGS

BUGS is invoked by typing bugs at your usual DOS or UNIX command line prompt. A simple set of commands is available for controlling a BUGS session. These are illustrated in the BUGS demo.


© 1996-2008 BUGS
Hosted by the MRC Biostatistics Unit, Cambridge, UK
Site designed by Alastair Stevens
TOP