Home

Getting started with WinBUGS

image

Contents

1. BS winBUGS14 File Tools Edit Attributes Info Model Inference Options Doodle Map Text Window Help WinBUGS Licence Licence Agreement Shortcut to ai OY mints S51 BUGS Introduction This software and any associated documentation whether electronic or printed hereinafter called WinBJdGS PACKAGE is made available under a licence Click On WinBUGS a and may be used only in EA with the terms of that agreement This is a legal agreement between you the Licensee and MRC and Imperial 1cOon to Start a College of Science Technology and Medicine the Licenser The terms of the licence are b provided in the following pages session Users are required to register and to pay a tee for the use of the WwinbUGS PACKAGE Details of fees and the procedure for i registration and acceptance ofthe licence terms is provided here Register to get full There is no fee payable for the use of the demonstration Internet version of the i WinBUtss package Users of the demonstration version of the VvinBUtss verston access package can upgrade to the full version on payment of a tee The current fee is zero dollars 0 By completing and sending the registration you demonstrate your agreement to the terms of this licence and will become legally bound to the terms therein It should be emphasised that the statistical tools provided in the WinBuiss PACKAGE are by their very nature partly subjective The Licenser cannot offe
2. loading the software 2 Click on Overview and view the movie computer platforms It is not being developed further but is still freely available FAQ Pages BUGS resources online CODA is a suite of S plus R functions for convergence dia nostics Suitable for use with References 3 J either version of BUGS Events The programs are reasonably easy to use and come with a range of examples Considerable Quick Links caution is however needed in their use since the software is not perfect and MCMC is i inherently less robust than analytic statistical WinBUGS development methods There is no in built protection against site misuse CASCADING B STYLE SHEETS 1996 2003 BUGS Hosted by the MRC Biostatistics Unit Cambridge UK Site designed by Alastair Stevens Obtaining the File Flease read the LICENSE AGREEMENT for YWwinBUGs before downloading anything The single file you need is VWvwinBUGS 14 exe and selecting the link will yield a dialog box Inviting you to save the file onto your system WINBUGS 1 1 and WinBUGS 1 2 are still avallable for those with historical interests VvinBUGS 1 3 and its key are also avallable and may still be useful if problems are obtained with VwinBUGS 14 and for running PKEUGS see below Installing WinBUGS 1 4 in Windows For installation run the file WinBUGS14 exe One way to do this is as follows Exit all other programs currently running particularly if using Window
3. 97 5 sample 01995 ratio Liab Ug 0M Tb 1115 103 25 Does it appear as if the sample rates of unemployment are significantly different Hint The area under the difference curve to the right of zero is not much larger than the area to the left of zero Also the area to the right of one under the ratio curve 1s not much larger than the area to the left of one Also the mean difference is close to zero and the mean ratio 1s close to one The 95 credible interval for the difference in unemployment rates is 0 15 0 20 which is interpreted to mean that there is a 95 probability that the difference lies somewhere in this interval This interval includes 0 Similarly the 95 credible interval for the ratio of unemployment rates is 0 61 1 90 which includes the value of 1 In Bayesian analysis the 95 credible interval is the analogue of the 95 confidence interval in conventional statistics However with a Bayesian analysis we state that there is a 95 probability that the parameter is between the interval values Whereas in a conventional analysis we state that 95 of all such intervals will contain the true but unknown value for the parameter assuming the null hypothesis 1s correct 26 Summary This tutorial describes the basics of using WinBUGS It explains how to make directed graphs using Doodle A directed graph provides visual representation of a statistical model The graphs simplify complex models communicate the struc
4. 032 0 113 0 3474 0 5669 1 S000 model is syntactically correct model compiled initial values generated model initialized Kernel density pi sample 5000 40 0 0 Node statistics node mean sc MC error 27 45 median 97 4 start sample pi 0 3253 00715 0 001059 0 2057 0 3258 0 4437 1 S000 15 Inference by combining your prior with data The real power of WinBUGS comes from the ability to combine your prior beliefs with data you have in hand thus allowing you to make inferences Continuing with our unemployment example suppose you have results from a small sample of 14 people A total of n 14 people were surveyed and r 4 of them were unemployed These data will have a binomial distribution with proportion pi and denominator N Go back to your directed graph and add two additional nodes Add a constant node N Add a stochastic node r with binomial density proportion equal to pi and order N Left click in your Doodle window change type to constant and name to N Left click again to add a stochastic node with name r density dbin proportion pi and order N To add links between the nodes click on node r to highlight it With the Ctrl key held click on node pi and node N Arrows will be added to the nodes The arrows will point to the highlighted node The solid arrows indicates a statistical relationship is distributed as 16 ed untitled The directed graph describes the new sae mane density dbin
5. Getting started with WinBUGS James B Elsner and Thomas H Jagger Department of Geography Florida State University Some material for this tutorial was taken from http www unt edu rss class rich 5840 session 1 doc 2 The BUGS Project Bayesian inference Using Gibbs Sampling i fe p i BUGS http www mrc bsu cam ac uk bugs Project The BUGS Project welcome Welcome Page Latest News Overview amp Demo WinBUGS New WinBUGS examples GeoBUGS PKBUGS Classic BUGS CODA About 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 Biostatistics Unit but now is developed jointly with the Imperial College School of Medicine at St Mary s London New users should see the Overview page for a summary of how the programs work and what sort of problems they re useful for The main program WinBUGS has a graphical user interface and on lin monitoring and convergence diagnostics A restricted version is available free and users who register receive a key providing full functionality also free The original Classic BUGS program uses text based model description and a command line interface and versions are available for major 1 Click on WinBUGS and follow instructions for down
6. an be as informative as you like To get things started lets assume that you choose a prior as a random value from a beta distribution restricted between the values of 0 1 and 0 6 Specifying your prior Create a directed graph In WinBUGS select Doodle gt New view height mm 100 node width mm 000 In the New Doodle dialog click on Cancel the default options You will see a blank worksheet called untitled pA WinBUGS14 Left click anywhere 1n the middle of the sheet to create a node A node has a name and type along with other ia kale ee hes characteristics and a ee parameters depending on its type lt D Notes To delete a node highlight it then Ctrl Delete To highlight a node click on it Use the Help gt Doodle help to learn more Fie Tools Edit Attributes Info Model Inference Options Doodle Map Window Help 4 untitled untitledz E O x Click on name then type pI Note a 1 b 1 lower bound 0 1 Upper bound 0 6 the graphical node is labeled simultaneously Leave type as stochastic Click on density and change to dbeta This means winBUGS will choose 4 H F a random value from the beta distribution Click on a and type 1 then on b and type 1 These are the parameters of the beta distribution Click on lower bound at type 0 1 then on upper bound and type 0 6 These are the bounds we Set on the true value of our prio
7. cates that all values of pi between 0 1 and 0 6 are equally likely This is what we decided that we know about the unemployment rate before a we look at our data sample There are other useful buttons on the Sample Monitor Tool For example by pressing we get the following table appended in the Log window hode statistics The mean value for our prior 1s node mean sd MC error 2 5 median 97 5 start 0 349 with 95 of the 5000 sample values in the range between fi 0 349 Diggy 000203 0113 Dagi 6 ScbY d SOUL 0 113 and 0 5869 12 The MC error is the Monte Carlo error 1t decreases as the number of samples increases It helps in deciding when enough samples have been taken Since we know the density is flat on top we can reduce the wiggles by increasing the number of samples Try running 50 000 samples pi sample 50000 Bd Node statistics node mean sc MC error 2 5 median 97 5 start sample pi i 01442 5 905E 4 0 1126 0 3511 Os5o 4 1 SUO00 Note the smoother density and the reduction in the MC error from 0 002 with 5000 samples to 0 0006 for 50000 samples 13 For comparison and practice let s rerun the analysis with a slightly different model Let s restrict our prior to the range between 0 2 and 0 45 In words we are more precise about what we know concerning the value of pi Go back to the Doodle window and change the upper and lower bounds accordingly Then select Write Code Check to see if the code
8. fference 23 Add the links to finish the model Note that the links to the logical nodes are made with a hollow arrow which indicates a deterministic relationship as opposed to the solid arrow which indicates a stochastic relationship The final doodle and corresponding code for the two proportion model are Directed Graph model CrS a gt pi dbeta 1 1 I 0 2 0 45 omy ae pi2 dbeta 1 1 I 0 2 0 45 Yo r2 dbin pi2 N2 ratio lt pi2 pl difference lt pi2 pl A deterministic relationship as indicated by a hollow arrow gets coded in the model using the lt symbol as is used in R or Splus A statistical relationship gets coded n the model with a symbol Add the data In the model window type list N 14 r 4 N2 12 r2 5 24 Use the Specification Tool to check the model load the data compile and generate the initial values Use the Sample Monitor Tool to set ratio and difference node chains i to fr Percents beg fi and 1000000 thir fi a 25 clear trace history density i Use the Update Tool to generate 5000 values of the a sea eae lE l stats coda Wantiles gr diag auto cor ratio and difference Usia x E o mo refresh fioo update thin fi iteration 5000 over relax adapting difference sample 5000 ratio sample 5000 A N node mein sil MC error 2 5 median 97 5 node sample difference OOs DOA UMA I D0 mean sd MC error 2 5 median
9. is consistent with the Doddle With the Model window highlighted window containing the code select Model gt Specification to open the Specification Tool First press m1 You will receive the following warninggysresrys A P 4 the new model will replace the old one l OK Cancel Click __ Then click emie and Lerm Select Inference gt Samples to bring up the Sample Monitor Tool Type in pi and the press Select Model gt Update to open the Update Tool Change updates to 5000 then press u Select Inference gt Samples Scroll to pi in the node window and press _ s and al 14 The new results are added to the Log window Note that the x and y axes scales are different in the two graphs We see that the range of possible values is constrained and that the mean value shifts to the left as smaller The graph indicates that we believe the true value for pi is bounded but that within the bounds any value is equally likely This simple example demonstrates how WinBUGS works It shows how to start with a doodle and end up with a set of random numbers that encapsulate our belief about the unknown population parameter model is syntactically correct model compiled initial values generated model initialized Kernel density pi sample S5000 20 0 0 Mode statistics node mean scl MC error 2 5 median 497 5 start sample pi 0 349 0 1444 0002
10. nerates updated samples of pi updated from the initial by combining the prior information on pi and the new information on pi given by the data r and N 18 node sample pi node sample pi Prior pi sample 5000 mean si MC error 2 5 median 97 5 start l 0 3253 OOF 00010A 0 2057 3250 IEEE l q Posterior pi sample 5000 mean Sil MC error 2 5 median 97 4 start U4 BRIS 94106 4 02072 030 D43 1 Note how the data changes our view of the unemployment rate For one thing the data gives us reason to think that the unemployment rate pi is less than 0 4 There is still plenty of uncertainty but it is less than before we took the sample The standard deviation sd of pi from the prior is 0 072 but is 0 067 from the posterior The 95 credible interval shrinks accordingly For more practice and to see the effect of a larger sample on the posterior rerun the model with n 140 and r 40 19 Posterior pi sample 5000 node mean Si MC error 2 5 median 97 5 sample pi 1 20 D034 5096E 4 0 2194 0 2064 0 364 Thus as we increase our information about pi through more data the influence of the prior on the posterior decreases This is seen by the fact that the posterior density looks less like the original prior distribution Example 2 Suppose that we take another survey perhaps at some time later This time 12 different people were asked and 5 said they were unemployed What is the evidence that the underlying rate
11. proportion pi H j bound upper bound model The number of unemployed r 1s estimated from our prior and data as arandom variable having a binomial distribution with proportion pi and order N N is a constant and the prior for p1 is a beta distribution with two parameters a b 1 and restricted between 0 2 and 0 45 podel i dbeta 1 1 I 0 2 0 45 Select Doodle gt Write Code im Pore e I To enter the data type the following in the model code window list N 14 r 4 model dbeta 1 1 i 0 2 0 45 fa dbin pi N n N When you make you add arrows make sure the parameters of the stochastic list N 14 r 4 ist 1 4 node do not change 17 a untitled5 Select Model gt Specification n Click Zi pi dbeta 1 1 I 0 2 0 45 r dbin pi N Highlight the word list and EA specification Tool press If jist N 1 4 ral check model load data everything e Compie num of chains i is well you will see the message data loaded edite forchain f E gen imit Press compie then seninits Select Inference gt Samples Type pr and press WinBUGS has data for a node with a distribution so it will calculate the appropriate likelihood function and prior for pi and combine them into a posterior distribution It knows about conjugate pair of distributions so the calculation 1s straightforward Select Model gt Update Change updates to 5000 then press _ WinBUGS ge
12. r We will begin by using winBUGS to look at samples from our prior To do this we need to write code using this doodle WinBUGS executes from the code The doodle helps us keep track of our model which at this stage consists of a single node called pi On the main menu select Doodle gt Write Code r A RRE O untithed3 Dino ee ents irtena ee ee lol x model A new window opens that displays f i the model code pi dbeta 1 1 I 0 1 0 6 Left click over the text to highlight it Click on Attributes gt 16 point The model selects a random number from a beta distribution with parameters a b 1 keeping only those values that lie between 0 1 and 0 6 ap Note is read distributed as To run the model select Model gt Specification to bring up the PECE Tool dialog box Click e m In the lower left corner of the main dialog box you rae aa should see the words model is syntactically correct The a compile button in the Specification Tool becomes active compile load mits for chain i El ie as model it syntactically corect gen mits Click _ comie In the lower left corner you should see the words model compiled Click Lei This creates a starting value for the model You should see the words initial values generated model initialized 10 Before you produce results select Options gt Output options a Select the log radio button Note here
13. r advice on interpretation of results obtained using the VvinBUiss PACKAGE Any assistance will be strictly limited to attempting to help if there are problems formulating the statistical problem with the VWWinBUiGsS PACKAGE The Licencer makes no representation or warranties with respect to the V inBUtss PACKAGE and specifically disclaims any implied warranties of merchantability and fitness for a particular purpose The Licenser reserves the right to revise VWinBUtssS PACKAGE and to make changes therein from time to time without obligation to notify any person or organisation of such revision or changes While Licenser will make every effort to ensure the reliability of the VvinBUiss PACKAGE neither the Licenser nor its employees or agents may be held The WinBUGS user manual and Examples Vol I and Vol II provide a reference for beginners and novices A good way to approach a problem with WinBUGS is to scan through the examples to find a problem like yours You can then modify the code to fit your problem When you click on examples you will open them in what is called a compound document This organizes programs graphs and explanations into a single file A good example is the surgical institutional ranking FY PA winBUGS14 Fie Tools Edit Attributes Info Model Inference Options Doodle Map Text Window Help ooo help eas E d Examples Vol I Examples Vol II WinBUGS User Manual Licence About W
14. s AP Copy VWinBUGs 14 exe to your computer 50 into Explore and double click on WwinBUGs 14 exe Follow the instructions inthe dialog box You should have a new directory called vvinbUGs 14 within Program Files Inside the VwinBUGSs 14 directory is a program called VWWinBUGS 14 exe Right click an the pretty VviInBUGS icon select create shortcut then drag this shortcut to the desktop Double click on VWinBUtGss 14 exe to run VWinBLitss 14 CO oP on FS w ha Ifyou have problems after installation check again that you did not have programs running You could also try disabling any virus checker Obtaining the key for unrestricted use WinbUtss Is free but has absorbed a lot of time and grant money over the last 12 years or so We need to keep our employers happy with our time spent on the project and it helps if we can keep track of how many people are downloading It and where they come fram Itis also very helpful to have an idea of what itis being used for Flease fill inthe registration form and return itto us we will then e mail you the key which will remove the restrictions in WinbUtss 14 After folowing the instructions given inthe key check that the Keys ocf file in WVinBUtGS 14iBugsiCade has been updated Some people have found they need to re boot the machine to complete installation of the key Flease note that the key currently being issued 1s valid until June 30th 2004 ou willbe sent a new key before this one expires
15. s for the two surveys 1s really different Note From the first sample 4 14 or 29 of the people were not employed From the second sample 5 12 or 42 of the people are unemployed Looking only at the percentages the difference appears to be large Using WinBUGS we can determine how much we know about the differences in the rates from these two small surveys by calculating a posterior for the difference Alternatively we can calculate a posterior for the ratio A model for the ratio and difference of two binomial samples Use the model from example 1 and add a second set of nodes for the new survey Call the prior p12 the number of unemployed r2 and the number of surveyed N2 lt gt C The nodes can be rearranged using click and drag p12 is set up the same as pi using a beta density a b 1 and bounded N2 is a constant like N r2 is set up the same as r using a binomial density with proportion p12 and order N2 Notes 22 To get the differences and ratios we create two logical nodes a untitled nappe ratio type logical link identity Pi pipil Left click to create a node Change type to logical name to ratio leave Ce link as identity and set value to p12 p1 gt untitled name difference type logical link identity walue piz pi Left click to create a node Change m type to logical name to difference leave link as identity and set value to p12 p1 lt gt lt gt di
16. ture of the problem and provide the basis for computation It explains how to compile load data and run WinBUGS code The code can be written automatically from the directed graph It explains how to view output using a log file The density and statistics give information about the posterior distribution that can be used for drawing inferences The examples were easy as they relied on conjugate distributions beta binomial Also there was only one unknown parameter in example 1 and only two unknown parameters in example 2 WinBUGS works well for these types of problems For more complicated problems with lots of parameters we cannot be so sure WinBUGS provides a set of diagnostic tools that allow you to check whether things are working properly AA Things can go wrong and the help manual contains a warning Using examples from the manual is a good path to follow but always look critically at your results to see if they make sense Use the diagnostic tools
17. winBUies WinBUGS User Manual version 1 4 January 003 David Spiegelhalter Andrew Thomas Micky Best Dave Lunn TMRC Biostatistics nit Institute of Public Health Robinson Waw Cambridge CA 25R UE Deparment of Epidemiology amp Public Health Imperial College School of Medicine Norfolk Place London v2 TPG UK e mail bugsemre bsu cam ac uk general andrew thoamas ic ac uk technical internet http wwa mirc bsu cam ac uk bugs Permission and Disclaimer please click here to read the legal bit More informally potential users are reminded to be extremely careful if using this program for serious statistical analysis We have tested the program on quite a wide set of examples but be particularly careful with types of model that are currently not featured If there is a problem inBiltss might just crash which is not very good but it might well carry on and produce answers that are wrong which is even worse Please let us know of any successes or failures ee ee S DE ee eet a ee De es es ee ell Example 1 Inference is required about the proportion of people in the population who are unemployed Let us call this value pr Think The true value of pi is in the range between O and 1 where 0 means no one is unemployed and 1 means everyone 1s Realistically we might have some prior information on the value of p1 For instance newspaper reports economic theory previous surveys etc Your prior c
18. you can also select f window log the output precision i i node chains ercentiles Select Inference gt Samples This brings up the A Elinan jf Sample Monitor Tool In the node window type I ea oomoo win f fio 25 pi then select se Note here you can also ea w tiw dri select the percentiles of interest stats coda quanties bor diag auta cor date Tool xj To run the model select Model gt Update This opens updates e000 teftesh foo the Update Tool Change updates to 5000 then press update thin T iteration a00 w Watch as the iterations are counted by 100 Foverrelas JT adapting to 5000 percentiles node fpi chains T Return to Inference gt Samples to open the Sample i ig Fi Monitor Tool Scroll to pi in the node window 2 end omeo wn f 10 then press density clear ct trace history density T g0 slats coda quantiles bgr diag auto cor 95 11 nips Wel is syntactically correct model compiled The Log window displays text indicating the model code is correct and that the model compiled and was initialized Eales eis eee Kernel density After pressing rse the Log window displays a plot showing the distribution of prior values 10 The x axis is the set of possible values for pi and the y axis indicates how often the model chooses a particular value The table top shape to the graph indi

Download Pdf Manuals

image

Related Search

Related Contents

Graco Inc. 258733 Paint Sprayer User Manual    StarTech.com 6 ft Standard Computer Power Cord - NEMA 5-15P to Right Angle C13  e+p T 54 wire connector  Radio User Standard Operating Procedures  CALEC® ST IIKurzversion  Interactive Graphics Intersection Design System    

Copyright © All rights reserved.
Failed to retrieve file