贝叶斯专业软件WinBUGS.ppt
“WinBUGS”by Haitao Chu,Presented as part of the Statistical Software Interest Groups seminar series.April 15,2003,Outline,What is BUGS/WinBUGS?Why do we want to use WinBUGS?Where do we get WinBUGS?How do we install WinBUGS?How do we use WinBUGS?Example What kind of output can WinBUGS give us?What kind of sampling method does WinBUGS implement?Summary,What is BUGS?,What is BUGS?,Bayesian inference Using Gibbs Sampling is a piece of computer software for the Bayesian analysis of complex statistical models using Markov chain Monte Carlo(MCMC)methods.It grew from a statistical research project at the MRC BIOSTATISTICAL UNIT in Cambridge,but now is developed jointly with the Imperial College School of Medicine at St Marys,London.,What is BUGS?,The Classic BUGS program uses text-based model description and a command-line interface,and versions are available for major computer platforms(Sparc,Dos).However,it is not being further developed.,What is WinBUGS?,WinBUGS,a windows program with an option of a graphical user interface,the standard point-and-click windows interface,and on-line monitoring and convergence diagnostics.It also supports Batch-mode running(version 1.4).GeoBUGS,an add-on to WinBUGS that fits spatial models and produces a range of maps as output.PKBUGS,an efficient and user-friendly interface for specifying complex population pharmacokinetic and pharmacodynamic(PK/PD)models within WinBUGS software.,Why do we want to use WinBUGS?,Its ability to fit complex statistical models using MCMC methods.Its flexibility to program,two different ways to specify modelDoodleBUGS:Direct graphicsBUGS languageFree to downloadA lot of examples in WinBUGSA lot of online resourceshttp:/www.mrc-bsu.cam.ac.uk/bugs/weblinks/webresource.shtml,Where do we get WinBUGS,Free download http:/www.mrc-bsu.cam.ac.uk/bugs.Package needs to be downloaded WinBUGS14.exePotential useful packages for convergence diagnosticsCODA(Convergence Diagnostic and Output Analysis)for S+or RBOA(Bayesian Output Analysis)for S+or R,How do we install WinBUGS?,Downloading the file WinBUGS14.exe(also available in S:/Haitao Chu/WinBUGs)Exit all other programs currently running(particularly if using Windows XP)Go into Explore and double click on WinBUGS14.exe 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 Drag the pretty icon to your desktop to create a shortcut.Double click on WinBUGS14.exe to run WinBUGS14.,How do we install WinBUGS?,Obtaining the key for unrestricted use by registration athttp:/www.mrc-bsu.cam.ac.uk/bugs/winbugs/register.shtmlFollowing the instructions from automatic response of your registration to remove the restrictions in WinBUGS 1.4 check that the date of Keys.ocf file in.WinBUGS14BugsCode has been updated.,How do we use WinBUGS?,Educational Example:Pumps:conjugate Gamma-Poisson hierarchical modelThe pumps dataGamma-Poisson hierarchical modelModel specification in WinBUGS DoodleBUGS,Direct graphicsBUGS languageFormat data and specify initial valuesTutorial,The pumps data,ti:the length of operation time of the pump(in 1000s of hours).xi:the number of failures,Gamma-Poisson hierarchical model,Model specification through DoodleBUGS,NodesConstants,denoted by rectanglesStochastic nodes,denoted by ellipsesDeterministic nodes,logical function of other nodesEdgesDirected linksSolid arrow:stochastic dependenceHollow arrow:logical functionUndirected links,dashed linerepresenting an upper or lower boundPlates,repeated parts of the graphRead the User Manual&Doodle help at the Help menu,Model specification through DoodleBUGS,Constant node,Stochastic node,Plate,Stochastic dependence,logical function,Deterministic node,Model specification through BUGS language,Format data and specify initial values,Data formatS-Plus formatlist(t=c(94.3,15.7,62.9,126,5.24,31.4,1.05,1.05,2.1,10.5),x=c(5,1,5,14,3,19,1,1,4,22),N=10)Rectangular formatPlease see formatting of data at model specification at User ManualInitial valueslist(alpha=1,beta=1)list(alpha=10,beta=10),Tutorial:Interactive submission,Standard windows“point and click”methodExamplePumps conjugate Gamma-Poisson hierarchical model in Example Volume I at Help menuS:/Haitao Chu/WinBUGS/pumps/pumps.odc,Tutorial:Batch mode submission,Files required The script itself,S:/Haitao Chu/WinBUGS/pumps/pumpsbatch.odcModel file,S:/Haitao Chu/WinBUGS/pumps/pumpsmodel.txtData file,S:/Haitao Chu/WinBUGS/pumps/pumpsdata.txtInitial values fileS:/Haitao Chu/WinBUGS/pumps/pumpsin1.txtS:/Haitao Chu/WinBUGS/pumps/pumpsin2.txtFormat of the files native WinBUGS format with.odc extensiontext format with.txt extension,Tutorial:running WinBUGS from R and other programs,From Rhttp:/www.stat.columbia.edu/gelman/bugsRS:/Haitao Chu/WinBUGS/bugsRFrom other programshttp:/www.mrc-bsu.cam.ac.uk/bugs/winbugs/remote14.shtml,What kind of output can WinBUGS give us?,Samples at Inference Menutrace:plots the variable value against iteration number.history:plots out a complete trace for the variable.density:smoothed kernel density estimate for continuous variable or a histogram for discrete variable.auto cor:auto correlation,up to lag-50stats:Summary statistics,pooling over the chains selected.coda:output the monitored values to CODA or BOA,What kind of output can WinBUGS give us?,Samples at Inference Menuquantiles:plots out the running mean with running 95%confidence intervals against iteration number.bgr diag:Brooks-Gelman-Rubin convergence statistic Brooks and Gelman(1998)Green:the width of the central 80%interval of the pooled runs Blue:the average width of the 80%intervals within the individual runsRed:their ratio R(=pooled/within).Convergence:R to 1,and with convergence of both the pooled and within interval widths to stability.,What kind of output can WinBUGS give us?,Compare at Inference Menu,Box Plot,Caterpillar Plot,What kind of output can WinBUGS give us?,Rank at Inference Menustats:the distribution of the ranks of each component of the variable.histogram:the empirical distribution of the simulated rank for each componentDIC at Inference MenuDeviance Information Criterion,What kind of sampling method does WinBUGS implement?,Sampling methods are used in the following hierarchies Continuous target distributionConjugateDirect sampling using standard algorithmsLog-concaveDerivative-free adaptive rejection sampling Non-log-concave(restricted range)Slice samplingNon-log-concave(unrestricted range)MetropolisDiscrete target distribution(I have no experience)Finite upper boundInversionShifted PoissonDirect sampling using standard algorithm,Summary,What is BUGS/WinBUGS?Why do we want to use WinBUGS?Where do we get WinBUGS?How do we install WinBUGS?How do we use WinBUGS?What kind of output can WinBUGS give us?What kind of sampling method does WinBUGS implement?MCMC can be dangerous,Thank you very much for attending and participating in this Statistical Software Interest Group seminarMore volunteers!,The End,