Bayesian Modeling Using WinBUGS

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

A hands-on introduction to the principles of Bayesian modeling using WinBUGS

Bayesian Modeling Using WinBUGS provides an easily accessible introduction to the use of WinBUGS programming techniques in a variety of Bayesian modeling settings. The author provides an accessible treatment of the topic, offering readers a smooth introduction to the principles of Bayesian modeling with detailed guidance on the practical implementation of key principles.

The book begins with a basic introduction to Bayesian inference and the WinBUGS software and goes on to cover key topics, including:

  • Markov Chain Monte Carlo algorithms in Bayesian inference

  • Generalized linear models

  • Bayesian hierarchical models

  • Predictive distribution and model checking

  • Bayesian model and variable evaluation

Computational notes and screen captures illustrate the use of both WinBUGS as well as R software to apply the discussed techniques. Exercises at the end of each chapter allow readers to test their understanding of the presented concepts and all data sets and code are available on the book's related Web site.

Requiring only a working knowledge of probability theory and statistics, Bayesian Modeling Using WinBUGS serves as an excellent book for courses on Bayesian statistics at the upper-undergraduate and graduate levels. It is also a valuable reference for researchers and practitioners in the fields of statistics, actuarial science, medicine, and the social sciences who use WinBUGS in their everyday work.

Author(s): Ioannis Ntzoufras
Edition: 1
Publisher: Wiley
Year: 2009

Language: English
Pages: 520
Tags: Mathematical & Statistical;Software;Computers & Technology;Probability & Statistics;Applied;Mathematics;Science & Math;Computer Science;Algorithms;Artificial Intelligence;Database Storage & Design;Graphics & Visualization;Networking;Object-Oriented Software Design;Operating Systems;Programming Languages;Software Design & Engineering;New, Used & Rental Textbooks;Specialty Boutique;Statistics;Mathematics;Science & Mathematics;New, Used & Rental Textbooks;Specialty Boutique

CONTENTS ... 7
1 Introduction to Bayesian Inference ... 7
2 Markov Chain Monte Carlo Algorithms in Bayesian Inference ... 8
3 WinBUGS Software: Introduction, Setup, and Basic Analysis ... 8
4 Win BUGS Software: Illustration, Results, and Further Analysis ... 8
PREFACE ... 16
ACKNOWLEDGMENTS ... 18
ACRONYMS ... 19
Chapter 1 INTRODUCTION TO BAYESIAN INFERENCE ... 22
1.1 INTRODUCTION: BAYESIAN MODELING IN THE 21ST CENTURY ... 22
1.2 DEFINITION OF STATISTICAL MODELS ... 24
1.3 BAYES THEOREM ... 24
1.4 MODEL-BASED BAYESIAN INFERENCE ... 25
1.5 INFERENCE USING CONJUGATE PRIOR DISTRIBUTIONS ... 28
1.5.1 Inference for the Poisson rate of count data ... 28
1.5.2 Inference for the success probability of binomial data ... 29
1.5.3 Inference for the mean of normal data with known variance ... 30
1.5.4 Inference for the mean and variance of normal data ... 32
1.5.5 Inference for normal regression models ... 33
1.5.6 Other conjugate prior distributions ... 35
1.5.7 Illustrative examples ... 35
1.6 NONCONJUGATE ANALYSIS ... 45
Problems ... 48
Chapter 2 MARKOV CHAIN MONTE CARLO ALGORITHMS IN BAYESIAN INFERENCE ... 51
2.1 SIMULATION, MONTE CARLO INTEGRATION, AND THEIR IMPLEMENTATION IN BAYESIAN INFERENCE ... 51
2.2 MARKOV CHAIN MONTE CARLO METHODS ... 55
2.2.1 The algorithm ... 56
2.2.2 Terminology and implementation details ... 57
2.2.2.1 Definitions and initial terminology ... 57
2.2.2.2 Describing the target distribution using MCMC output. ... 58
2.2.2.3 Monte Carlo error ... 59
2.2.2.4 Convergence of the algorithm ... 61
2.3 POPULAR MCMC ALGORITHMS ... 62
2.3.1 The Metropolis-Hastings algorithm ... 62
2.3.1.1 Random-walk Metropolis ... 63
2.3.1.2 The independence sampler. ... 64
2.3.2 Componentwise Metropolis-Hastings ... 65
2.3.2.1 Simple examples ... 66
2.3.3 The Gibbs sampler ... 91
2.3.3.1 A simple example using the Gibbs sampler ... 92
2.3.4 Metropolis within Gibbs ... 96
2.3.5 The slice Gibbs sampler ... 96
2.3.6 A simple example using the slice sampler ... 97
2.4 SUMMARY AND CLOSING REMARKS ... 101
Problems ... 101
Chapter 3 WinBUGS SOFTWARE: INTRODUCTION,SETUP, AND BASIC ANALYSIS ... 103
3.1 INTRODUCTION AND HISTORICAL BACKGROUND ... 103
3.2 THE WinBUGS ENVIRONMENT ... 104
3.2.1 Downloading and installing WinBUGS ... 104
3.2.2 A short description of the menus ... 105
3.3 PRELIMINARIES ON USING WinBUGS ... 108
3.3.1 Code structure and type of parameters/nodes ... 108
3.3.2 Scalar, vector, matrix, and array nodes ... 109
3.4 BUILDING BAYESIAN MODELS IN WinBUGS ... 113
3.4.1 Function description ... 113
3.4.2 Using the for syntax and array, matrix,and vector calculations ... 117
3.4.3 Use of parentheses, brackets and curly braces in WinBUGS ... 118
3.4.4 Differences between WinBUGS and R/Splus syntax ... 118
3.4.5 Model specification in WinBUGS ... 119
3.4.6 Data and initial value specification ... 120
3.4.6.1 Rectangular data format ... 120
3.4.6.2 List data format ... 121
3.4.6.3 Importing data from R/Splus ... 122
3.4.6.4 A simple example of data specification. ... 124
3.4.6.5 A simple example using arrays ... 125
3.4.6.6 Mixed and multiple data definition ... 125
3.4.6.7 Initial values ... 127
3.4.6.8 Other details. ... 127
3.4.7 An example of a complete model specification ... 127
3.4.8 Data transformations ... 128
3.5 COMPILING THE MODEL AND SIMULATING VALUES ... 128
3.6 BASIC OUTPUT ANALYSIS USING THE SAMPLE MONITOR TOOL ... 137
3.7 SUMMARIZING THE PROCEDURE ... 140
3.8 CHAPTER SUMMARY AND CONCLUDING COMMENTS ... 141
Problems ... 141
Chapter 4 Win BUGS SOFTWARE: ILLUSTRATION,RESULTS,AND FURTHER ANALYSIS ... 144
4.1 A COMPLETE EXAMPLE OF RUNNING MCMC IN WinBUGS FOR A SIMPLE MODEL ... 144
4.1.1 The model ... 144
4.1.2 Data and initial values ... 146
4.1.3 Compiling and running the model ... 146
4.1.4 MCMC output analysis and results ... 148
4.1.4.1 Checking convergence ... 148
4.1.4.2 Calculation of posterior summaries ... 150
4.2 FURTHER OUTPUT ANALYSIS USING THE INFERENCE MENU ... 151
4.2.1 Comparison of nodes ... 152
4.2.2 Calculation of correlations ... 155
4.2.3 Using the summary tool ... 156
4.2.4 Evaluation and ranking of individuals ... 157
4.2.5 Calculation of deviance information criterion ... 159
4.3 MULTIPLE CHAINS ... 160
4.3.1 Generation of multiple chains ... 160
4.3.2 Output analysis ... 161
4.3.3 The Gelman-Rubin convergence diagnostic ... 162
4.4 CHANGING THE PROPERTIES OF A FIGURE ... 164
4.4.1 General graphical options ... 164
4.4.2 Special graphical options ... 164
4.5 OTHER TOOLS AND MENUS ... 167
4.5.1 The node info tool ... 167
4.5.2 Monitoring the acceptance rate of the Metropolis-Hastings algorithm ... 167
4.5.3 Saving the current state of the chain ... 168
4.5.4 Setting the starting seed number ... 168
4.5.5 Running the model as a script ... 168
4.6 SUMMARY AND CONCLUDING REMARKS ... 168
Problems ... 169
Chapter 5 INTRODUCTION TO BAYESIAN MODELS: NORMAL MODELS ... 170
5.1 GENERAL MODELING PRINCIPLES ... 170
5.2 MODEL SPECIFICATION IN NORMAL REGRESSION MODELS ... 171
5.2.1 Specifying the likelihood ... 172
5.2.2 Specifying a simple independent prior distribution ... 173
5.2.3 Interpretation of the regression coeff icients ... 173
5.2.4 A regression example using WinBUGS ... 176
5.3 USING VECTORS AND MULTIVARIATE PRIORS IN NORMAL REGRESSION MODELS ... 180
5.3.1 Defining the model using matrices ... 180
5.3.2 Prior distributions for normal regression models ... 181
5.3.3 Multivariate normal priors in WinBUGS ... 182
5.3.4 Continuation of Example 5.1 ... 183
5.4 ANALYSIS OF VARIANCE MODELS ... 186
5.4.1 The one-way ANOVA model ... 186
5.4.2 Parametrization and parameter interpretation ... 187
5.4.2.1 Corner constraints ... 187
5.4.2.2 Sum-to-zero constraints. ... 188
5.4.3 One-way ANOVA model in WinBUGS ... 188
5.4.4 A one-way ANOVA example using WinBUGS ... 190
5.4.5 Two-way ANOVA models ... 192
5.4.5.1 The main effects model. ... 192
5.4.5.2 Parametrization and parameter interpretation ... 193
5.4.5.3 The two-way interaction model. ... 193
5.4.5.4 Data in tabular format (equal observations per cell). ... 195
5.4.5.5 A two-way ANOVA example. ... 197
5.4.6 Multifactor analysis of variance ... 203
Problems ... 203
Chapter 6 INCORPORATING CATEGORICAL VARIABLES IN NORMAL MODELS AND FURTHER MODELING ISSUES ... 207
6.1 ANALYSIS OF VARIANCE MODELS USING DUMMY VARIABLES ... 209
6.2 ANALYSIS OF COVARIANCE MODELS ... 213
6.2.1 Models using one quantitative variable and one qualitative variable ... 215
6.2.2 The parallel lines model ... 215
6.2.3 The separate lines model ... 219
6.3 A BIOASSAY EXAMPLE ... 221
6.3.1 Parallel lines analysis ... 222
6.3.2 Slope ratio analysis: Models with common intercept and different slope ... 230
6.3.3 Comparison of the two approaches ... 235
6.4 FURTHER MODELING ISSUES ... 236
6.4.1 Extending the simple ANCOVA model ... 236
6.4.2 Using binary indicators to specify models in multiple regression ... 237
6.4.3 Selection of variables using the deviance information criterion (DIC) ... 237
6.4.3.1 A stepwise method for DIC based variable selection in WinBUGS ... 238
6.5 CLOSING REMARKS ... 244
Problems ... 244
Chapter 7 INTRODUCTION TO GENERALIZED LINEAR MODELS: BINOMIAL AND POISSON DATA ... 246
7.1 INTRODUCTION ... 246
7.1.1 The exponential family ... 247
7.1.2 Common distributions as members of the exponential family ... 248
7.1.3 Link functions ... 251
7.1.3.1 Common link functions ... 251
7.1.3.2 More complicated link functions for binomial data. ... 252
7.1.4 Common generalized linear models ... 253
7.1.5 Interpretation of GLM coefficients ... 255
7.2 PRIOR DISTRIBUTIONS ... 256
7.3 POSTERIOR INFERENCE ... 258
7.3.1 The posterior distribution of a generalized linear model ... 258
7.3.2 GLM specification in WinBUGS ... 259
7.4 POISSON REGRESSION MODELS ... 259
7.4.1 Interpretation of Poisson log-linear parameters ... 259
7.4.2 A simple Poisson regression example ... 262
7.4.2.1 Model specification in WinBUGS ... 262
7.4.2.2 Results ... 263
7.4.2.3 Interpretation of the model parameters. ... 263
7.4.2.4 Estimating specific profiles ... 264
7.4.2.5 Selection of variables using DIC ... 265
7.4.3 A Poisson regression model for modeling football data ... 266
7.4.3.1 Background information and the model ... 266
7.4.3.2 Model specification in WinBUGS ... 267
7.4.3.3 Results. ... 267
7.4.3.4 Prediction of future games ... 268
7.4.3.5 Regeneration of the full league ... 270
7.5 BINOMIAL RESPONSE MODELS ... 272
7.5.1 Interpretation of model parameters in binomial response models ... 274
7.5.1.1 Odds and odds ratios. ... 274
7.5.1.2 Logistic regression parameters and odds ratios ... 276
7.5.1.3 Parameter interpretation in probit models. ... 276
7.5.1.4 Relationship between log it and probit parameters. ... 278
7.5.1.5 Parameter interpretation in log-log and clog-log models. ... 279
7.5.2 A simple example ... 280
7.5.2.1 Model specification in WinBUGS. ... 280
7.5.2.2 Results and parameter interpretation. ... 284
7.6 MODELS FOR CONTINGENCY TABLES ... 286
Problems ... 287
Chapter 8 MODELS FOR POSITIVE CONTINUOUS DATA, COUNT DATA,AND OTHER GLM-BASED EXTENSIONS ... 292
8.1 MODELS WITH NONSTANDARD DISTRIBUTIONS ... 292
8.1.1 Specification of arbitrary likelihood using the zeros-ones trick ... 293
8.1.2 The inverse Gaussian model ... 294
8.2 MODELS FOR POSITIVE CONTINUOUS RESPONSE VARIABLES ... 296
8.2.1 The gamma model ... 296
8.2.2 Other models ... 297
8.2.3 An example ... 298
8.3 ADDITIONAL MODELS FOR COUNT DATA ... 299
8.3.1 The negative binomial model ... 300
8.3.2 The generalized Poisson model ... 303
8.3.3 Zero inflated models ... 305
8.3.4 The bivariate Poisson model ... 308
8.3.5 The Poisson difference model ... 310
8.4 FURTHER GLMĀ·BASED MODELS AND EXTENSIONS ... 313
8.4.1 Survival analysis models ... 314
8.4.2 Multinomial models ... 315
8.4.3 Additional models and further reading ... 317
Problems ... 318
Chapter 9 BAYESIAN HIERARCHICAL MODELS ... 322
9.1 INTRODUCTION ... 322
9.1.1 A simple motivating example ... 323
9.1.2 Why use a hierarchical model? ... 324
9.1.3 Other advantages and characteristics ... 325
9.2 SOME SIMPLE EXAMPLES ... 325
9.2.1 Repeated measures data ... 325
9.2.1.1 Model formulation. ... 325
9.2.1.2 Win BUGS code. ... 327
9.2.1.3 Results. ... 327
9.2.1.4 Handling missing data. ... 327
9.2.2 Introducing random effects in performance parameters ... 330
9.2.2.1 State space model. ... 330
9.2.3 Poisson mixture models for count data ... 332
9.2.3.1 The Poisson-gamma model. ... 332
9.2.3.2 The Poisson-log-normal model. ... 333
9.2.4 The use of hierarchical models in meta-analysis ... 335
9.3 THE GENERALIZED LINEAR MIXED MODEL FORMULATION ... 337
9.3.1 A hierarchical normal model: A simple crossover trial ... 338
9.3.2 Logit GLMM for correlated binary responses ... 342
9.3.2.1 The logit model in 2x2 tables of dependent binary data. ... 343
9.3.3 Poisson log-linear GLMMs for correlated count data ... 350
9.4 DISCUSSION, CLOSING REMARKS,AND FURTHER READING ... 355
Problems ... 357
Chapter 10 THE PREDICTIVE DISTRIBUTION AND MODEL CHECKING ... 358
10.1 INTRODUCTION ... 358
10.1.1 Prediction within Bayesian framework ... 358
10.1.2 Using posterior predictive densities for model evaluation and checking ... 359
10.1.3 Cross-validation predictive densities ... 361
10.2 ESTIMATING THE PREDICTIVE DISTRIBUTION FOR FUTURE OR MISSING OBSERVATIONS USING MCMC ... 361
10.2.1 A simple example: Estimating missing observations ... 362
10.2.2 An example of Bayesian prediction using a simple model ... 364
10.2.2.1 Model formulation. ... 366
10.3 USING THE PREDICTIVE DISTRIBUTION FOR MODEL CHECKING ... 371
10.3.1 Comparison of actual and predictive frequencies for discrete data ... 371
10.3.2 Comparison of cumulative frequencies for predictive and actual values for continuous data ... 374
10.3.3 Comparison of ordered predictive and actual values for continuous data ... 375
10.3.4 Estimation of the posterior predictive ordinate ... 376
10.3.5 Checking individual observations using residuals ... 379
10.3.6 Checking structural assumptions of the model ... 382
10.3.7 Checking the goodness-of-fit of a model ... 385
10.4 USING CROSS-VALIDATION PREDICTIVE DENSITIES FOR MODEL CHECKING, EVALUATION, AND COMPARISON ... 392
10.4.1 Estimating the conditional predictive ordinate ... 392
10.4.2 Generating values from the leave-one-out cross-validatory predictive distributions ... 394
10.5 ILLUSTRATION OF A COMPLETE PREDICTIVE ANALYSIS: NORMAL REGRESSION MODELS ... 395
10.5.1 Checking structural assumptions of the model ... 395
10.5.2 Detailed checks based on residual analysis ... 396
10.5.3 Overall goodness-of-fit of the model ... 397
10.5.4 Implementation using WinBUGS ... 397
10.5.5 An Illustrative example ... 400
10.5.6 Summary of the model checking procedure ... 403
10.6 DISCUSSION ... 404
Problems ... 405
Chapter 11 BAYESIAN MODEL AND VARIABLE EVALUATION ... 406
11.1 PRIOR PREDICTIVE DISTRIBUTIONS AS MEASURES OF MODEL COMPARISON: POSTERIOR MODEL ODDS AND BAYES FACTORS ... 406
11.2 SENSITIVITY OF THE POSTERIOR MODEL PROBABILITIES: THE LINDLEY-BARTLETT PARADOX ... 408
11.3 COMPUTATION OF THE MARGINAL LIKELIHOOD ... 409
11.3.1 Approximations based on the normal distribution ... 409
11.3.2 Sampling from the prior: A naive Monte Carlo estimator ... 409
11.3.3 Sampling from the posterior: The harmonic mean estimator ... 410
11.3.4 Importance sampling estimators ... 411
11.3.5 Bridge sampling estimators ... 411
11.3.6 Chib's marginal likelihood estimator ... 412
11.3.7 Additional details and further reading ... 414
11.4 COMPUTATION OF THE MARGINAL LIKELIHOOD USING WinBUGS ... 414
11.4.1 A beta-binomial example ... 416
11.4.2 A normal regression example with conjugate normal-inverse gamma prior ... 420
11.5 BAYESIAN VARIABLE SELECTION USING GIBBS-BASED METHODS ... 422
11.5.1 Prior distributions for variable selection in GLM ... 423
11.5.2 Gibbs variable selection ... 426
11.5.3 Other Gibbs-based methods for variable selection ... 427
11.6 POSTERIOR INFERENCE USING THE OUTPUT OF BAYESIAN VARIABLE SELECTION SAMPLERS ... 429
11.7 IMPLEMENTATION OF GIBBS VARIABLE SELECTION IN WinBUGS USING AN ILLUSTRATIVE EXAMPLE ... 431
11.8 THE CARLIN-CHIB METHOD ... 436
11.9 REVERSIBLE JUMP MCMC(RJMCMC) ... 437
11.10 USING POSTERIOR PREDICTIVE DENSITIES FOR MODEL EVALUATION ... 438
11.10.1 Estimation from an MCMC output ... 440
11.10.2 A simple example in WinBUGS ... 441
11.11 INFORMATION CRITERIA ... 441
11.11.1 The Bayes information criterion (BIC) ... 442
11.11.2 The Akaike information criterion (AIC) ... 443
11.11.3 Other criteria ... 444
11.11.4 Calculation of penalized deviance measures from the MCMC output ... 445
11.11.5 Implementation in WinBUGS ... 445
11.11.6 A simple example in WinBUGS ... 446
11.12 DISCUSSION AND FURTHER READING ... 449
Problems ... 449
APPENDIX A MODEL SPECIFICATION VIA DIRECTED ACYCLIC GRAPHS: THE DOODLE MENU ... 451
A.1 INTRODUCTION: STARTING WITH DOODLE ... 451
A.2 NODES ... 452
A.3 EDGES ... 454
A.4 PANELS ... 454
A.5 A SIMPLE EXAMPLE ... 455
APPENDIX B THE BATCH MODE: RUNNING A MODEL IN THE BACKGROUND USING SCRIPTS ... 458
B.1 INTRODUCTION ... 458
B.2 BASIC COMMANDS:COMPILING AND RUNNING THE MODEL ... 459
APPENDIX C CHECKING CONVERGENCE USING CODA/BOA ... 461
C.1 INTRODUCTION ... 461
C.2 A SHORT HISTORICAL REVIEW ... 462
C.3 DIAGNOSTICS IMPLEMENTED BY CODA/BOA ... 462
C.3.1 The Geweke diagnostic ... 462
C.3.2 The Gelman-Rubin diagnostic ... 463
C.3.3 The Raftery-Lewis diagnostic ... 463
C.3.4 The Heidelberger-Welch diagnostic ... 463
C.3.5 Final remarks ... 464
C.4 A FIRST LOOK AT CODA/BOA ... 464
C.4.1 CODA ... 464
C.4.2 BOA ... 465
C.5 A SIMPLE EXAMPLE ... 467
C.5.1 Illustration in CODA ... 467
C.5.2 Illustration in BOA ... 471
APPENDIX D NOTATION SUMMARY ... 475
REFERENCES ... 482
INDEX ... 498