DOC PREVIEW
UI STAT 5400 - Introduction to WinBUGS

This preview shows page 1 out of 4 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Computing in Statistics, 22S:166Lab 4Oct. 18, 2006Introduction to WinBUGS1 If you want WinBUGS for your home PCWinBUGS was developed by David Spiegelhalter and colleagues at the Medical ResearchCouncil Biostatistics Unit in Cambridge, England. If you want WinBUGS for your ownPC, you can download files fromhttp://www.mrc-bsu.cam.ac.uk/bugs/welcome.shtmlBe sure to get the “key” that transforms the student version into the full-function version.2 Bringing up WinBUGS and Finding DocumentationSelect WinBUGS from the “All Programs” menu list.On-line documentation is available under the “Help” menu, and it can be printed. I will alsoput a written copy of the documentation on reserve in the Mathematical Sciences library.Be sure to take a look at the examples as well as the manual itself.3 Finding the example WinBUGS codeBring up Netscape and go to the course web page. Under “Handouts,” click on “win-bugs.example.” Open this document in a window, as we will want to copy and paste it intoa WinBUGS window.4 To fit a model using WinBUGSModels may be defined for WinBUGS by using either a simple, R/Splus-like commandlanguage or by drawing graphical models. The steps below are for the command languageversion.Things to note:• WinBUGS parameterizes the normal distribution in terms of mean and precision.• WinBUGS does not permit improper priors, except for the dflat() prior (uniformon the whole real line), which cannot be used for precisions. The manual recommendsvery small values of both parameters for a gamma to approximate a gamma(0, 0)1prior. This prior is not recommended for certain precisions in hierarchical models, aswe will discuss later in the semester.• If you wish to estimate the posterior distribution of a function of model parameters,WinBUGS can compute the function and generate samples of it.• If you wish to estimate the posterior predictive distribution of potential new data,you can add one or more ”NA”s to the data list. This is WinBUGS’ notation foran unknown data value. It will then treat that as one more unknown quantity tosimulate.1. Select the “File” menu, and from it select “New.”2. Highlight and copy the code from the course web page and paste it into the WinBUGSnew window. You can also type in new code in this type of window, or load inpreviously-saved programs.WinBUGS code must include the following sections (see example):• model• data (alternatively, the data may be a file that has been read into another win-dow)• initial values3. Use the mouse to highlight the word “model” at the beginning of the model sectionof your code. Then select the “Model” menu and from it select “Specification” andthen “check model.” Watch for a message at the bottom of the WinBUGS windoweither confirming the validity of the model or reporting errors.4. Highlight the word “list” at the beginning of your data listing. From the “Specificationtool” box select “load data.” Again check for a message confirming data loading orerrors.5. In the “Specification tool” box, change the number of chains from 1 to 3.6. From the “Specification tool” box select “Compile.”7. Highlight the word “list” at the beginning of your initial values section. Select the“Model” menu and from it select “load inits.” Again check for a message. You willget a message that some nodes are unitialized. Continue to load initial values for eachof the other 2 chains.8. Select the “Model” menu and “Update.” You will be prompted for how many iterationsyou want to run the sampler. For now, just accept the default of 1000.9. To start saving samples from the posterior distribution of the unknown quantities inyour model, select the “Inference” menu and “Samples” from it. Type the name ofeach parameter whose posterior distribution you want to study in the window in theprompt box (this will be just p in this simple example), and click on ”set” after eachone.210. Select the “Model” menu and “Update.” You will be prompted for how many iterationsyou want to run the sampler. For now, enter 2000.11. Go to the Options pull-down menu and be sure that “Use log” is checked. This willcause all the output we are about to request to go into a single window instead ofcreating a bzillion small windows cluttering up the screen.12. Go back to the “Sample monitor” box and select the desired parameter in the nodebox. Entering an asterisk requests all monitored nodes. Then, one at a time, click“trace,” “history,” “stats”, “density,” and “GRdiag.” We will discuss the meaning ofthis output.13. To get more precision in your posterior estimation, you may return to the “Update”box and request additional samples. Then go back to the previous step to includethese samples in the output analysis.14. To print the content of any window, click on that window and then select the “File”menu and “Print.” If you wish, you may copy and paste graphical and tabular outputfrom the “Sample monitor” windows into a single window for compact printing.Now we will run a second example, model 3. The steps will be essentially the same, but wewill load data from two different sources.1. Use the mouse to highlight the word “model” at the beginning of the model sectionfor model 3. Then select the “Model” menu and from it select “Specification” andthen “check model.” WinBUGS will warn you that this new model will replace themodel we were working with previously. This is fine.2. The data for this problem is in two parts – one in list format and one in table for-mat. First highlight the word “list” at the beginning of your data listing. From the“Specification tool” box select “load data.” Again check for a message confirming dataloading or errors.3. We are loading additional data from an external data file in table format. Highlightthe row of column headings, and again click “load data.”4. In the “Specification tool” box, change the number of chains from 1 to 3.5. From the “Specification tool” box select “Compile.”6. Highlight the word “list” at the beginning of your initial values section. Select the“Model” menu and from it select “load inits.” Again check for a message. You willget a message that some nodes are unitialized. Continue to load initial values for eachof the other 2 chains. Even after you load the initial values for the 3rd chain, you willget a message


View Full Document

UI STAT 5400 - Introduction to WinBUGS

Documents in this Course
Load more
Download Introduction to WinBUGS
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Introduction to WinBUGS and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Introduction to WinBUGS 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?