1 / 62

Introduction to WinBUGS

Introduction to WinBUGS. Win dows B ayesian inference U sing G ibbs S ampling Software for the Bayesian analysis of complex statistical models using Markov chain Monte Carlo (MCMC) methods. Olivier Gimenez. A brief history. 1989 : project began with a Unix version called BUGS

pascha
Download Presentation

Introduction to WinBUGS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to WinBUGS Windows Bayesian inference Using Gibbs Sampling Software for the Bayesian analysis of complex statistical models using Markov chain Monte Carlo (MCMC) methods Olivier Gimenez

  2. A brief history • 1989: project began with a Unix version called BUGS • 1998: first Windows version, WinBUGS was born • Initially developed by the MRC Biostatistics Unit in Cambridge and now joint work with Imperial College School of Medicine at St Mary's, London.

  3. Who? Nicky Best Imperial College Faculty of Medicine, London (UK) Thomas Andrew University of Helsinki, Helsinki (Finland) Wally Gilks MRC Biostatistics Unit Institute of Public Health Cambridge (UK) David Spiegelhalter MRC Biostatistics Unit Institute of Public Health Cambridge (UK)

  4. How to obtain and install WinBUGS 1. downloadable from: http://www.mrc-bsu.cam.ac.uk/bugs/winbugs/contents.shtml (... see section Obtaining the Fileto download WinBUGS14.exe) 2. to install WinBUGS: • Exit all other programs currently running (particularly if using Windows XP); • Copy WinBUGS14.exe to your computer; • Double click on WinBUGS14.exe and follow the instructions in the dialog box; • You should have a new directory called WinBUGS14 within Program Files; Inside the WinBUGS14 directory is a program called WinBUGS14.exe; Right-click on the pretty WinBUGS icon, select `create shortcut', then drag this shortcut to the desktop; • Double click on WinBUGS14.exe to run WinBUGS14.

  5. How to obtain and install WinBUGS • To obtain the key for unrestricted use: • Fill in the registration form • ~1h later, you will receive an email from Bugs with subject WinBUGS registration - AUTOMATIC RESPONSE! • Follow the instructions... • Congratulations, you're ready to use WinBUGS

  6. Principle • You specify the prior and build up the likelihood • WinBUGS computes the posterior by running a Gibbs sampling algorithm, based on: (|D) / L(D|) () • WinBUGS computes some convergence diagnostics that you have to check

  7. A biological example throughout White stork (Ciconia ciconia) in Alsace 1948-1970 Demographic components (fecundity, breeding success, survival, etc…) Climate (Temperature, rainfall, etc…)

  8. WinBUGS & Linear Regression 2.55 1.85 2.05 2.88 3.13 2.21 2.43 2.69 2.55 2.84 2.47 2.69 2.52 2.31 2.07 2.35 2.98 1.98 2.53 2.21 2.62 1.78 2.30 15.1 67 13.3 52 15.3 88 13.3 61 14.6 32 15.6 36 13.1 72 13.1 43 15.0 92 11.7 32 15.3 86 14.4 28 14.4 57 12.7 55 11.7 66 11.9 26 15.9 28 13.4 96 14.0 48 13.9 90 12.9 86 15.1 78 13.0 87 Y Number of chicks per pairs T Temp. May (°C) R Rainf. May (mm)

  9. WinBUGS & Linear Regression 1. Do temperature and rainfall affect the number of chicks? 2. Regression model: Yi =  + r Ri + t Ti + i , i=1,...,23 i i.i.d. ~ N(0,2) Yii.i.d. ~ N(i,2), i=1,...,23 i =  + r Ri + t Ti 3. Estimation of parameters: , r, t,  4. Frequentist inference uses t-tests

  10. Linear Regression using Frequentist approach 2.55 1.85 2.05 2.88 3.13 2.21 ... 2.30 15.1 67 13.3 52 15.3 88 13.3 61 14.6 32 15.6 36 ... ... 13.0 87 Y Number of chicks per pairs T Temp. May (°C) R Rainf. May (mm) Y = 2.451 + 0.031 T - 0.007 R Estimate Std. Error t value Pr(>|t|) temperature 0.031069 0.054690 0.568 0.57629 rainfall -0.007316 0.002897 -2.525 0.02011 *

  11. Linear Regression using Frequentist approach 2.55 1.85 2.05 2.88 3.13 2.21 ... 2.30 15.1 67 13.3 52 15.3 88 13.3 61 14.6 32 15.6 36 ... ... 13.0 87 Y Number of chicks per pairs T Temp. May (°C) R Rainf. May (mm) Y = 2.451 + 0.031 T - 0.007 R Estimate Std. Error t value Pr(>|t|) temperature 0.031069 0.054690 0.568 0.57629 rainfall -0.007316 0.002897 -2.525 0.02011 *  Influence of Rainfall only

  12. 1 - a model giving the likelihood and the priors 2 - some data of course 3 - initial values to start the MCMC algorithm Running WinBUGS What do you need?

  13. use the WinBUGS command 'model' Specify the priors We use noninformative or vague or flat priors here don't forget to embrace the model with {...} Define the likelihood... Yi~ N( + r Ri + t Ti ,2) Note: 2 = 1/ Monitor any other parameter you'd like to... e.g. 2 = 1/ Running WinBUGS The model

  14. ...and 'vector' structures (R/Splus syntax) Use 'list' structures (R/Splus syntax)... Running WinBUGS Data and initial values

  15. 1 - a model giving the likelihood and the priors 2 - data 3 - initial values Running WinBUGS Overall

  16. Running WinBUGS At last!! 1- check model 2- load data 3- compile model 4- load initial values 5- generate burn-in values 6- parameters to be monitored 7- perform the sampling to generate posteriors 8- check convergence and display results

  17. Running WinBUGS 1. Check model

  18. Running WinBUGS 1. Check model: highlight 'model'

  19. Running WinBUGS 1. Check model: open the Model Specification Tool

  20. Running WinBUGS 1. Check model: Now click 'check model'

  21. Running WinBUGS 1. Check model: Watch out for the confirmation at the foot of the screen

  22. Running WinBUGS 2. Load data: Now highlight the 'list' in the data window

  23. Running WinBUGS 2. Load data: then click 'load data'

  24. Running WinBUGS 2. Load data: watch out for the confirmation at the foot of the screen

  25. Running WinBUGS 3. Compile model: Next, click 'compile'

  26. Running WinBUGS 3. Compile model: watch out for the confirmation at the foot of the screen

  27. Running WinBUGS 4. Load initial values: highlight the 'list' in the data window

  28. Running WinBUGS 4. Load initial values: click 'load inits'

  29. Running WinBUGS 4. Load initial values: watch out for the confirmation at the foot of the screen

  30. Running WinBUGS 5. Generate Burn-in values: Open the Model Update Tool

  31. Running WinBUGS 5. Generate Burn-in values: Give the number of burn-in iterations (1000)

  32. Running WinBUGS 5. Generate Burn-in values: click 'update' to do the sampling

  33. Running WinBUGS 6. Monitor parameters: open the Inference Samples Tool

  34. Running WinBUGS 6. Monitor parameters: Enter 'intercept' in the node box and click 'set'

  35. Running WinBUGS 6. Monitor parameters: Enter 'slope_temperature' in the node box and click 'set'

  36. Running WinBUGS 6. Monitor parameters: Enter 'slope_rainfall' in the node box and click 'set'

  37. Running WinBUGS 7. Generate posterior values: enter the number of samples you want to take (10000)

  38. Running WinBUGS 7. Generate posterior values: click 'update' to do the sampling

  39. Running WinBUGS 8. Summarize posteriors: Enter '*' in the node box and click 'stats'

  40. Running WinBUGS 8. Summarize posteriors: mean, median and credible intervals

  41. Running WinBUGS 8. Summarize posteriors: 95% Credible intervals tell us the same story Estimate Std. Error t value Pr(>|t|) temperature 0.031069 0.054690 0.568 0.57629 rainfall -0.007316 0.002897 -2.525 0.02011 *

  42. Running WinBUGS 8. Summarize posteriors: 95% Credible intervals tell us the same story Estimate Std. Error t value Pr(>|t|) temperature 0.031069 0.054690 0.568 0.57629 rainfall -0.007316 0.002897 -2.525 0.02011 *

  43. Running WinBUGS 8. Summarize posteriors: click 'history'

  44. Running WinBUGS 8. Summarize posteriors: click 'auto cor'  Problem of autocorrelation

  45. Coping with autocorrelation use standardized covariates

  46. Coping with autocorrelation use standardized covariates

  47. Re-running WinBUGS 1,2,...7, and 8. Summarize posteriors: click 'auto cor'  autocorrelation OK

  48. Re-running WinBUGS 1,2,...7, and 8. Summarize posteriors: click 'density'

  49. Re-running WinBUGS 1,2,...7, and 8. Summarize posteriors: click 'quantiles'

  50. Running WinBUGS 8. Checking for convergence using the Brooks-Gelman-Rubin criterion • A way to identify non-convergence is to simulate multiple sequences for over-dispersed starting points • Intuitively, the behaviour of all of the chains should be basically the same. • In other words, the variance within the chains should be the same as the variance across the chains. • In WinBUGS, stipulate the number of chains after 'load data' and before 'compile' (obviously, as many sets of initial values as chains have to be loaded, or generated)

More Related