Here we provide BUGS model code, data and other material necessary to reproduce all of the worked examples in the book.
The examples are available either in HTML format to view online, or in .odc compound document format.
.odc files must be opened in WinBUGS or OpenBUGS for Windows. They are read-only, so if you want to modify them for your own use, then copy and paste the code or data into a new blank document.
The examples were developed for the latest version of WinBUGS (1.4.3), and have not been tested on any other version of BUGS.
The examples are available either in HTML format to view online, or in .odc compound document format.
.odc files must be opened in WinBUGS or OpenBUGS for Windows. They are read-only, so if you want to modify them for your own use, then copy and paste the code or data into a new blank document.
The examples were developed for the latest version of WinBUGS (1.4.3), and have not been tested on any other version of BUGS.
- Download zipped bundle of all examples in the book in .odc format: bugsbook-examples
The results from running this code should agree with the results quoted in the book… up to Monte Carlo error. Note that it will not always be possible to reproduce the results to an arbitrary number of significant figures, due to differences in random number sampling behaviour across different computing platforms. Exact outputs are particularly likely to differ when initial values have been generated automatically.
WinBUGS and OpenBUGS also come with a substantial set of worked examples — see the Help menu in WinBUGS or the Examples menu in OpenBUGS.
Chapter 1 – Introduction: probability and parameters
(no BUGS examples)
Chapter 2 – Monte Carlo simulations using BUGS
- 2.1.2: Coins: running WinBUGS: html | odc
- 2.3.1: Simulating from a Student’s t distribution: html | odc
- 2.4.1: Cube: html | odc
- 2.5.1: Repairs: the “how many” trick: html | odc
- 2.6.1: Heart transplant cost-effectiveness: risks assumed known: html | odc
- 2.7.1: Surgery (continued): prediction: html | odc
- 2.7.2: Heart transplant cost-effectiveness (continued): html | odc
Chapter 3 – Introduction to Bayesian inference
- 3.3.2: Surgery (continued): beta-binomial analysis using BUGS: html | odc
- 3.3.3: Trihalomethanes in tap water: html | odc
- 3.4.1: Three coins: html | odc
- 3.5.1: Heart transplants: learning from data: html | odc
Chapter 4 – Introduction to Markov chain Monte Carlo methods
- 4.1.1: Surgery (continued): non-conjugate inference: html | odc
- 4.1.2: A multi-parameter model: html | odc
Chapter 5 – Prior distributions
- 5.2.1: Surgery (continued): prior sensitivity: html | odc
- 5.2.2: Coin tossing: estimating number of tosses: html | odc
- 5.3.1: Power calculations: html | odc
- 5.3.2: Power calculations (continued): html | odc
- 5.4.1: A biased coin?: html | odc
- 5.5.1: GREAT trial: html | odc
- 5.5.2: Trams: a classic problem from Jeffreys 1939: html | odc
Chapter 6 – Regression models
- 6.1.1: Growth curve: html | odc
- 6.1.2: New York crime: html | odc
- 6.1.3: New York crime (continued): html | odc
- 6.2.1: New York crime (continued): robust regression: html | odc
- 6.3.1: Dugongs: html | odc
- 6.4.1: Jaws: html | odc
- 6.5.1: Binary data: Beetles: html | odc
- 6.5.2: Count data: Salmonella: html | odc
- 6.6.1: Beetles (continued): ED95: html | odc
Chapter 7 – Categorical data
- 7.1.1: Lady tasting tea: html | odc
- 7.2.1: Asthma: state transitions in a clinical trial: html | odc
- 7.2.2: Population genetics: self-fertilising plants: html | odc
- 7.2.3: Asthma (continued): including a treatment effect: html | odc
- 7.3.1: Kidney transplants: ordered logistic regression: html | odc
Chapter 8 – Model checking and comparison
- 8.2.1: Newcomb’s speed of light data: odc
- 8.3.1: Bristol surgery mortality: odc
- 8.3.2: Jaws (continued): model checking: odc
- 8.3.3: Dugongs (continued): residuals: odc
- 8.3.4: Bristol (continued): tenth data: odc
- 8.4.1: Bristol (continued): cross-validation: odc
- 8.4.2: Is a sequence of flips of a biased coin real or fake?: odc
- 8.4.3: Newcomb (continued): checking for a low minimum value: odc
- 8.4.4: Newcomb (continued): checking for skewness: odc
- 8.4.5: Dugongs (continued): prediction as model checking:odc
- 8.4.6: Claims: odc
- 8.5.1: Newcomb (continued): checking normality: odc
- 8.6.1: Dugongs (continued): effective number of parameters: odc
- 8.6.2: Transformed binomial: negative pD due to severe posterior skewness:odc
- 8.6.3: Conflicting ts: negative pD due to a prior-data conflict: odc
- 8.6.4: Salmonella (continued): odc
- 8.7.1: Paul the psychic octopus: odc
- 8.10.1: Surgery (continued): assessing prior-data conflict:odc
- 8.10.2: Surgery (continued): mixture of priors: odc
- 8.10.3: Prior robustness using a t prior distribution: odc
Chapter 9 – Issues in Modelling
- 9.1.1: Growth curve (continued): ignorable missing response data mechanism: odc
- 9.1.2: Growth curve (continued): informative missing response data mechanism: odc
- 9.1.3: Dugongs (continued): ignorable missing covariate mechanism: odc
- 9.1.4: Birthweight: regression model for imputing missing covariates: odc
- 9.2.1: Dugongs (continued): prediction: odc
- 9.3.1: Cervix: case-control study with errors in covariates: odc
- 9.3.2: Dugongs (continued): measurement error on age: odc
- 9.3.3: Air pollution: Berkson measurement error: odc
- 9.4.1: Cutting feedback: odc
- 9.5.1: A clumsy way of modelling the normal distribution: odc
- 9.6.1: Censored chickens: odc
- 9.6.2: Truncated chickens: odc
- 9.6.3: Grouped chicken: odc
- 9.7.1: Half-normal: odc
- 9.7.2: Doughnut: bivariate normal with a hole in it: odc
- 9.7.3: Bristol (continued): sum-to-zero constraint: odc
- 9.8.1: Bootstrapping in BUGS: the Newcomb data: odc
- 9.9.1: Bristol (continued): ranking: odc
Chapter 10 – Hierarchical models
- 10.1.1: Bristol (continued): hierarchical model: odc
- 10.3.1: Salmonella (continued): hierarchical model: odc
- 10.3.3: Hepatitis B (continued): odc
- 10.3.4: Students’ goals: hierarchical categorical/multinomial models: odc
- 10.4.1: Cadralazine: hierarchical model for variances: odc
- 10.5.1: Bristol (continued): overparameterisation: odc
- 10.7.1: Bristol (continued): cross-validatory check of random effects model: odc
- 10.7.2: Bristol (continued): approximate cross-validatory check of random effects model: odc
- 10.7.3: Rats: checking a random effects growth model for outliers: odc
- 10.7.4: Rats: odc
- 10.8.1: Hepatitis B (continued): measurement error: odc
Chapter 11 – Specialised models
- 11.1.1: Icelandic volcano eruptions: predicting event times: odc
- 11.2.1: Sunspots: odc
- 11.2.2: Tuna: odc
- 11.3.1: Mapping lip cancer in Scotland: odc
- 11.3.2: Estimating radioactivity levels on Rongelap Island: odc
- 11.4.1: Limiting long-term illness: combining individual and aggregate data: odc
- 11.6.1: Eyes: odc
- 11.6.2: Eyes (continued): DIC with the zeros trick: odc
- 11.6.3: Zero-inflated Poisson: odc
- 11.7.1: Stagnant water: change point model: odc
- 11.7.2: Leukaemia: survival models with piecewise-constant hazards: odc
- 11.8.1: Galaxy clustering: Dirichlet process mixture models: odc
Chapter 12 – Different implementations of BUGS
- 12.4.3: Using the WinBUGS graphical interface: Seedsmodel.txt | Seedsdata.txt | Seedsinits1.txt | Seedsinits2.txt |
- 12.4.5: Scripting: Seeds_script.txt
- 12.4.7: R2WinBUGS: Seeds_R2WinBUGS.R |
- 12.5.3: BRugs: Seeds_BRugs.R |
- 12.6.4: Running JAGS from the command line: Seeds_jags.cmd | seeds-data.R | seeds-inits1.R | seeds-inits2.R |
- 12.6.5: Running JAGS from R: Seeds_rjags.R