1 / 141

Bayesian Methods and WinBUGS: A Comprehensive Guide

This guide provides an introduction to Bayesian methods and WinBUGS software, including basic programming, advanced controls, convergence techniques, hierarchical modeling, and more.

cortney
Download Presentation

Bayesian Methods and WinBUGS: A Comprehensive Guide

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. Bayesian Methods and WinBUGSRich EvansIowa State UniversityCollege of Veterinary Medicine,Production Animal Medicine

  2. Agenda • Basics • Run a simple program • Advanced • Use more controls • Additional programming • Convergence • Hierarchical models Bayesian methods and WinBUGS

  3. Bayesian inference: Why do it? • Efron, B.  (1986), ``Why isn't everyone a Bayesian? (C/R: p5-11; p330-331)'', The American Statistician, 40, 1-5 • Before MCMC • Theoretical reasons • Philosophical reasons • Easier for some problems • Another tool in the statistical toolbox Bayesian methods and WinBUGS

  4. Motivating example: Estimating Prevalence • Estimate the prevalence of M. Hyo. in a swine population. • Use a Bayesian version of the Discordant Resolution method (Alonzo and Pepe, 1999). • 63 swine were tested with TWEEN 20 and the DAKO ELISA tests. • Subjects with discordant results were retested using the IDEXX. Bayesian methods and WinBUGS

  5. Example Test positive=1 Bayesian methods and WinBUGS

  6. Example: Issues and fix-ups • There aren’t good confidence intervals for prevalence using the DR method • Easy with the Bayesian method • Uncertainty about the test results is not reflected in the inference • Want to model uncertainty about the resolution • 2 of 3 values agreeing is not conclusive Bayesian methods and WinBUGS

  7. Model • Each subject has a disease-positive probability • The 2 or 3 binary outcomes are sampled with this probability • The subject disease probabilities come from a common distribution, and their mean is the disease prevalence. • The prevalence has a beta prior distribution, and those parameters have hyper-priors Bayesian methods and WinBUGS

  8. “missing” included in the analysis Bayesian methods and WinBUGS

  9. Example Posterior distribution may be intractable Markov chain sampling (e.g., using WinBUGS) Monte Carlo estimates Inference, e.g.,

  10. WinBUGS results Bayesian methods and WinBUGS

  11. Prior parameters for prev Bayesian methods and WinBUGS

  12. DR method prev = 0.73 Bayesian methods and WinBUGS

  13. Bayesian methods and WinBUGS

  14. Bayesian inference for m Prior information (dist) for m Data, sampling distribution “turn the crank” (definition of conditional dist, joint/marg) Posterior distribution Posterior expected values and variances (The dist. of a rv contains all possible info about the rv) Bayesian methods and WinBUGS

  15. Model parts Data WinBUGS Markov chains (like data from posterior) CODA or BOA Inference or prediction

  16. WinBUGS resources • The BUGS project • http://www.mrc-bsu.cam.ac.uk/bugs/ • CODA or BOA • Mailing list • Helpful hints and tricks • Obtaining WinBUGS • Get the key to unlock the student version Bayesian methods and WinBUGS

  17. WinBUGS Development web-site • The site is designed to facilitate the distribution of various (free) extensions of WinBUGS, • allow users to implement their own specialized functions by 'hard-wiring' them into the software via compiled Pascal code • The home-page for the new web-site is:http://homepages.tesco.net/~creeping_death/ Bayesian methods and WinBUGS

  18. WinBUGS • Model specification language rather than a programming language Bayesian methods and WinBUGS

  19. WinBUGS • Need only the data and model • MCMC diagnostics • Trace plots • Autocorrelation • B-G-R plots • It will output in CODA format • Output text files • Use .ind and .out extensions (not .txt) Bayesian methods and WinBUGS

  20. WinBUGS easy example • Estimate an experiment mean  • We have some information from a prior experiment • In order to make the inference more precise, we will include information from the prior experiment in the inference for  Bayesian methods and WinBUGS

  21. Example Sampling distribution parameter of interest Prior distribution The mean and standard error from a prior experiment Prior distribution with non-informative parameters Bayesian methods and WinBUGS

  22. Distributions in WinBUGS • Provides many distributions • It is possible to use arbitrary distributions • See the BUGS project web page for the technique Bayesian methods and WinBUGS

  23. Bayesian methods and WinBUGS

  24. model body Data and initial values

  25. model Sampling distribution Priordistributions Standard deviation of y

  26. model ~ is “is distributed as” Distributions have “d”s “less than dash” is assignment

  27. model Loops are S-Plus syntax. Indexing can be nested (y[x[i]]) and multivariate (y[i,j]) Data and initial values in S-Plus format Not all parameters need user specified inits

  28. 1 2 3 4 5 Bayesian methods and WinBUGS

  29. Running an example • Model -> specification tool • Load model • Load data • Compile • Load inits Bayesian methods and WinBUGS

  30. Running an example • Model -> Update tool • Burn in • Inference -> samples • Choose parameters to monitor • Update tool to continue iterating Bayesian methods and WinBUGS

  31. Running an example • Run a basic program • Burn in, thinning, over relax • Monitoring and clearing variables • AutoC button • Stop and start a program during a run Bayesian methods and WinBUGS

  32. Running an example • Run with multiple chains • Eyeball convergence • Auto corr • Trace plots • Quantiles • GR convergence Bayesian methods and WinBUGS

  33. End Part I Bayesian methods and WinBUGS

  34. Advanced WinBUGS Bayesian methods and WinBUGS

  35. Editing Graphics • Edit -> object properties • Title • Axis bounds • Fonts • margins • Smoothing Bayesian methods and WinBUGS

  36. Editing text • Attributes menu • Text menu Bayesian methods and WinBUGS

  37. Scripts • Set of Scripting commands that circumvent the “button” interface • Files (.odc or .txt) • Script file (commands) • WinBUGS program • Data file(s) • Initial value file(s) • Can run in the background Bayesian methods and WinBUGS

  38. Scripts • See the WinBUGS help file for the list of commands • Run the Normal example • Use forward “/” slashes in file names!!! • check('c:/Projects/talks/DavisISVEE/Normalexample.odc') Bayesian methods and WinBUGS

  39. Indexing • Similar to Splus • Y[i,j,k] • Y[z[i]] • Useful for ragged arrays • Vector for the response (Y) and a corresponding group identification vector (z) z has discrete values Bayesian methods and WinBUGS

  40. Indexing: ragged array Bayesian methods and WinBUGS

  41. Indexing: ragged arrayWinBUGS For (i in 1:N){ Y[z[i]] ~ dnorm(mu[z[i]],tau[z[i]])} Bayesian methods and WinBUGS

  42. Censoring • Restrict variables • Y ~ dnorm(a,s)I(0,3) • Y ~ dgamma(a,s)I(,X) Parameter Bayesian methods and WinBUGS

  43. Output analysis • Convergence (in a coming lecture) • Diagnostics and summaries • Data analysis and inference • Histograms • Auto and cross corrrelation • Summary statistics and probability intervals Bayesian methods and WinBUGS

  44. Output analysis Histogram, adjustable smoothing (easily cut and pasted into Excel, which is useful when investigating many similar parameters) Bayesian methods and WinBUGS

  45. Output analysis: ranks • Ranking institutions, surgeons, farms, regions is relatively easy in WinBUGS • The idea is to assign ranks at each iteration of the MC generation and then do Monte Carlo on the ranks Bayesian methods and WinBUGS

  46. Example: Swine farm size by state • NAHMS is a United States Department of Agriculture sponsored program to collect, analyze and disseminate information about animal (primarily production animal) health, management, and productivity. • The swine surveys are limited to swine farms and to states that produce the majority of swine. In 1995, 418 swine farms from 16 states (these states accounted for 91% of the total US hog and pig production in 1995) were surveyed with questionnaires. • The number of farms surveyed in each state is roughly proportional to the number of swine farms in the state. One survey question asks for the swine farm sizes (total number of hogs and pigs on June 1, 1995). Bayesian methods and WinBUGS

  47. The model Bayesian methods and WinBUGS

More Related