CS作业代写 WinBUGS User Manual

WinBUGS User Manual
Version 1.4, January 2003
1 2 2 2
1 MRC Biostatistics Unit, Institute of Public Health, Robinson Way, Cambridge CB2 2SR, UK

Copyright By PowCoder代写 加微信 powcoder

2 Department of Epidemiology & Public Health, Imperial College School of Medicine, Norfolk Place,
London W2 1PG, UK
e-mail: [general] [technical]
internet: http://www.mrc-bsu.cam.ac.uk/bugs
Permission and Disclaimer
please click here to read the legal bit
More informally, potential users are reminded to be extremely careful if using this program for serious statistical analysis. We have tested the program on quite a wide set of examples, but be particularly careful with types of model that are currently not featured. If there is a problem, WinBUGS might just crash, which is not very good, but it might well carry on and produce answers that are wrong, which is even worse. Please let us know of any successes or failures.
Beware: MCMC sampling can be dangerous!
Introduction Ł
This manual
Advice for new users
MCMC methods
How WinBUGS syntax differs from that of ClassicBUGS Changes from WinBUGS 1.3
Compound Documents Ł
What is a compound document? Working with compound documents Editing compound documents

Compound documents and e-mail
Printing compound documents and Doodles Reading in text files
Model Specification Ł
Graphical models
Graphs as a formal language
The BUGS language: stochastic nodes Censoring and truncation
Constraints on using certain distributions Logical nodes
Arrays and indexing
Repeated structures
Data transformations
Nested indexing and mixtures Formatting of data
DoodleBUGS: The Doodle Editor Ł
General properties Creating a node Selecting a node Deleting a node Moving a node Creating a plate Selecting a plate Deleting a plate Moving a plate Resizing a plate Creating an edge Deleting an edge Moving a Doodle Resizing a Doodle Printing a Doodle
The Model Menu Ł
General properties Specification… Update…
Monitor Metropolis Save State Seed…
The Inference Menu Ł
General properties Samples… Compare… Correlations… Summary… Rank…

The Info Menu Ł
General properties Open Log
Node info… Components
Batch-mode: Scripts
The Options Menu Ł
Output options… Blocking options… Update options…
Tricks: Advanced Use of the BUGS Language Ł
Specifying a new sampling distribution Specifying a new prior distribution Specifying a discrete prior on a set of values Using pD and DIC
Mixtures of models of different complexity Where the size of a set is a random quantity Assessing sensitivity to prior assumptions Modelling unknown denominators
Handling unbalanced datasets
Learning about the parameters of a Dirichlet distribution Use of the “cut” function
WinBUGS Graphics Ł
General properties Margins
Specific properties (via Special…) Density plot
Caterpillar plot
Model fit plot
Scatterplot
Tips and Troubleshooting Ł
Restrictions when modelling Some error messages Some Trap messages
The program hangs Speeding up sampling Improving convergence

Tutorial Ł
Introduction
Specifying a model in the BUGS language Running a model in WinBUGS
Monitoring parameter values
Checking convergence
How many iterations after convergence? Obtaining summaries of the posterior distribution
Changing MCMC Defaults (advanced users only) Ł Defaults for numbers of iterations
Defaults for sampling methods
References
Introduction
Distributions Ł
Discrete Univariate Continuous Univariate Discrete Multivariate Continuous Multivariate
This manual
Advice for new users
MCMC methods
How WinBUGS syntax differs from that of Classic BUGS Changes from WinBUGS 1.3
This manual [ top | home ]
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.
The sections cover the following topics:
Introduction: the software and how a new user can start using WinBUGS. Differences with previous incarnations of BUGS and WinBUGS are described.
Compound Documents: the use of the compound document interface that underlies the program, showing how documents can be created, edited and manipulated.
Model Specification: the role of graphical models and the specification of the BUGS language. DoodleBUGS: The Doodle Editor: the DoodleBUGS software which allows complex Bayesian models to be

specified as Doodles using a graphical interface.
The Model Menu: the Model Menu permits models expressed as either Doodles or in the BUGS language to be parsed, checked and compiled.
The Inference Menu: the Inference Menu controls the monitoring, display and summary of the simulated variables: tools include specialized graphics and space-saving short-cuts for simple summaries of large numbers of variables.
The Info Menu: the Info menu provides a log of the run and other information.
The Options Menu: facility that allows the user some control over where the output is displayed and the various available MCMC algorithms.
Batch-mode: Scripts: how to run WinBUGS in batch-mode using ‘scripts’.
Tricks: Advanced Use of the BUGS Language: special tricks for dealing with non-standard problems, e.g. specification of arbitrary likelihood functions.
WinBUGS Graphics: how to display and change the format of graphical output.
Tips and Troubleshooting: tips and troubleshooting advice for frequently experienced problems.
Tutorial: a tutorial for new users.
Changing MCMC Defaults (advanced users only): how to change some of the default settings for the MCMC algorithms used in WinBUGS.
Distributions: lists the various (closed-form) distributions available in WinBUGS.
References: references to relevant publications.
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.
If you have the educational version of WinBUGS, you can run any model on the example data-sets provided (except possibly some of the newer examples). If you want to analyse your own data you will only be able to build models with less than 100 nodes (including logical nodes). However, the key for removing this restriction can be obtained by registering via the BUGS website, from which the current distribution policy can also be obtained.
Advice for new users [ top | home ]
Although WinBUGS can be used without further reference to any of the 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 and Examples Volume 2) 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 | home ]
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
Conjugate Log-concave Restricted range Unrestricted range
Discrete target distribution
Finite upper bound Shifted Poisson
Direct sampling using standard algorithms Derivative-free adaptive rejection sampling (Gilks, 1992) Slice sampling (Neal, 1997)
Current point Metropolis
Direct sampling using standard algorithm
In cases where the graph contains a Generalized Linear Model (GLM) component, it is possible to request (see Blocking 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 an 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 | home ]
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,
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 | home ] - 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 (1.4); - 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 command 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. Compound Documents What is a compound document? Working with compound documents Editing compound documents Compound documents and e-mail Printing compound documents and Doodles Reading in text files What is a compound document? [ top | home ] A compound document contains various types of information (formatted text, tables, formulae, plots, graphs etc) displayed in a single window and stored in a single file. The tools needed to create and manipulate these information types are always available, so there is no need to continuously move between different programs. The WinBUGS software has been designed so that it produces output directly to a compound document and can get its input directly from a compound document. To see an example of a compound document click here. WinBUGS is written in Component Pascal using the BlackBox development framework: see http://www.oberon.ch. In WinBUGS a document is a description of a statistical analysis, the user interface to the software, and the resulting output. Compound documents are stored with the .odc extension. Working with compound documents [ top | home ] A compound document is like a word-processor document that contains special rectangular embedded regions or elements, each of which can be manipulated by standard word-processing tools -- each rectangle behaves like a single large character, and can be focused, selected, moved, copied, deleted etc. If an element is focused the tools to manipulate its interior become available. The WinBUGS software works with many different types of elements, the most interesting of which are Doodles, which allow statistical models to be described in terms of graphs. DoodleBUGS is a specialised graphics editor and is described fully in DoodleBUGS: The Doodle Editor. Other elements are rather simpler and are used to display plots of an analysis. Editing compound documents [ top | home ] WinBUGS contains a built-in word processor, which can be used to manipulate any output produced by the software. If a more powerful editing tool is needed WinBUGS documents or parts of them can be pasted into a standard OLE enabled word processor. Text is selected by holding down the left mouse button while dragging the mouse over a region of text. Warning: if text is selected and a key pressed the selection will be replaced by the character typed. The selection can be removed by pressing the "Esc" key or clicking the mouse. A single element can be selected by clicking once into it with the left mouse button. A selected element is distinguished by a thin bounding rectangle. If this bounding rectangle contains small solid squares at the corners and mid sides it can be resized by dragging these with the mouse. An element can be focused by clicking twice into it with the left mouse button. A focused element is distinguished by a hairy grey bounding rectangle. A selection can be moved to a new position by dragging it with the mouse. To copy the selection hold down the "control" key while releasing the mouse button. These operations work across windows and across applications, and so the problem specification and the output can both be pasted into a single document, which can then be copied into another word-processor or presentation package. The style, size, font and colour of selected text can be changed using the Attributes menu. The vertical offset of the selection can be changed using the Text menu. The formatting of text can be altered by embedding special elements. The most common format control is the ruler: pick option Show Marks in menu Text to see what rulers look like. The small black up-poi 程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com