AN INTRODUCTION TO WinBUGS

Instructor: Dr Gavin Shaddick
Date: Saturday, October 18th, 2008
Location: Department of Statistics, University of British Columbia.


Welcome to the workshop webpage! Here are links to the notes, code and data that will be used on the day. You don't need to print them out as you will be provided with hardcopies during the workshop, but you might like to see what will be happening ahead of time.

Notes

1. Overall introduction, schedule and notes on installing WinBUGS (pdf file).
2. Introduction to WinBUGs and Bayesian analysis lecture notes (pdf file).  Also, a version with 4 per page (pdf file).
3. WinBUGS practicals (pdf file).

4. Hints on using WinBUGS (pdf file).

Code & Data

A zipped archive of the code and data used in the practicals (zip file)
This should be saved and unzipped on your computer, for example in c:/data.



The day will be split into a series of lectures and practicals, separated by well earned coffee breaks! Lunch is provided.

Schedule

0930-1030 Lecture 1: Introduction to Bayesian analysis, MCMC and WinBUGS

1030- 1130 Practical 1: Getting started with WinBUGS (including coffee break at 1100)

1130-1230 Lecture 2: Introduction to Bayesian inference

1230-1330 Lunch

1330-1430 Practical 2: Using WinBUGS for conjugate analysis of binary, Poisson and Normal data

1430-1500 Lecture 3: An introduction to MCMC

1500- 1645 Lecture and  Practical 3: Bayesian linear regression modelling using WinBUGS (including coffee break at 1530)

1645-1700 Wrap up (we need to leave the building by 5, otherwise we will get locked in!)

I must give many many thanks and acknowledge the enormous contribution of others in providing me with notes and examples which are included in todays workshop, in particular Prof. Nicky Best of Imperial College, London and all the members of the WinBUGS development team.

I hope you all enjoy the day.
GS
gavin@stat.ubc.ca




INSTALLATION
Although we will be running through how to obtain and install the software during the workshop, it would be very useful if participants could try and install the software before the day.



INSTALLING WinBUGS IN WINDOWS
(from the WinBUGS website: http://www.mrc-bsu.cam.ac.uk/bugs/winbugs/contents.shtml)

1. Download and install WinBUGS14.exe
2. Download and install the patch for 1.4.3
3. Get the free key for unrestricted use by filling in the registration form - the same key can be used for multiple installations.
4. For installation, run the file WinBUGS14.exe. One way to do this is as follows:

    Exit all other programs currently running (particularly if using Windows XP)
    Copy WinBUGS14.exe to your computer
    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
    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.
    If you have problems after installation, check again that you did not have programs running. You could also try disabling any virus checker.

    Note: There appears to be a problem with installing WinBUGS and/or various patches in Windows Vista. Vista doesn't seem to like anyone overwriting files in the         "C:\Program Files" directory (regardless of permissions). Hence we recommend that WinBUGS be installed elsewhere, e.g. "C:\".

If all else fails (for example with a 64-bit machine), you can download a zipped version of the whole file structure and unzip it into Program Files or wherever you want it. WinBUGS makes no changes to the Registry.

5. Obtaining the key for unrestricted use - WinBUGS is free, but has absorbed a lot of time and grant money over the last 15 years or so. It helps the developers if they can keep track of how many people are downloading it and where they come from. It is also very helpful to have an idea of what it is being used for. Fill in the registration form and return it to the developers. They will then e-mail you the key which will remove the restrictions in WinBUGS 1.4. After following the instructions given in the key, check that the Keys.ocf file in ..\WinBUGS14\Bugs\Code\ has been updated. (Some people have found they need to re-boot the machine to complete installation of the key.)


INSTALLING WinBUGS ON A MAC
Thanks to Christian Reuten for working out how to do this.

Installing WinBUGS under Mac OS 10.5;

1. WinBUGS is a Windows application, but it requires no registry changes and therefore seems to run just fine in an environment that can run .exe files.  Wine is such an environment.  For Mac it's called Darwine. Download the 'unstable 1.1.5' version of Darwine from: http://www.kronenberg.org/darwine/

2. Darwine runs under X11.  X11 may be installed by default under Leopard but not under Tiger.  Check for 'X11.app' in the Applications folder.  If you do not find X11 you must install it from the Tiger or Leopard CD before installing Darwine.

3. The installation of Darwine is standard: pull 'Darwine' and 'TriX' to the application folder.  This installs a 'Darwine' folder without any Darwine application file and 'TriX.app'.  When you start 'TriX.app' it allows you to install additional items.  It seems that installing items related to  graphics and fonts seems enough. The installations may not be  entirely successful but it does not seem to matter.

4. Download the zipped version of the whole file structure for WinBUGS. Unzip the file into the 'Applications' folder, it should make a directory called WinBUGS14.  Double click on the file 'WinBUGS14.exe' in this folder. That will automatically start WinBUGS under the X11 application (you won't really see Darwine).  Since 'WinBUGS14.exe' is not recognized as an application by OS X it seems not possible to place a shortcut to the menu; you will therefore have to start WinBUGS through the Finder.

5. Now obtain the patch and the key as in points 2 and 5 above (as with a Windows installation)

You should be all set.  Check the 'User Manual' under 'Help' if all updates are installed.   One note:  To follow  links in the documents, you may have to click both right and left mouse buttons at the same time.  Close to the bottom of the first page of the 'User Manual' there is a link 'Tutorial'. It is worth trying some of the examples and following the tutorial  to make sure that everything works fine.

INSTALLING WinBUGS in Ubuntu (and other Linux distributions)
Again, thanks to Christian.

1. WinBUGS is a Windows application, but it requires no registry changes and therefore seems to run just fine in an environment that can run .exe files.  Wine is such an environment that seems to be preinstalled at least in Ubuntu and possibly other Linux distributions, but you need to activate Wine.  Go to: http://www.winehq.org/site/download
and click on the link for Ubuntu.  If you are running another Linux distribution you can hopefully find something that works for you.  Simply follow the instructions which will activate Wine under Ubuntu.

2. Download the zipped version of the whole file structure for WinBUGS. Unzip the file into your folder of choice (you need to have write access).  Double click on the file 'WinBUGS14.exe' in the new folder 'WinBUGS14'.  That will automatically start WinBUGS.

3. Now obtain the patch and the key as in points 2 and 5 from the Windows installation above.

You should be all set.  Check the 'User Manual' under 'Help' if all updates are installed.  Close to the bottom of the first page of the 'User Manual' there is a link 'Tutorial'. It is worth trying some of the examples and following the tutorial  to make sure that everything works fine.