Running WinBugs and OpenBugs from R (and also some applied regression stuff)
The software on this page gets updated. Refresh to get latest versions. Last update: 27 Jan 2008.
The bugs() function takes data and starting values as input, calls a
Bugs model, summarizes inferences and convergence in a table and
graph, and saves the simulations in arrays for easy access in R. Here's an example of print() and plot() as applied to a bugs fit.
Setting up WinBUGS and OpenBUGS
- Follow the instructions on the WinBugs webpage: download the WinBugs14.exe file, install WinBugs14, and register and install the key so you can use the full version of the program.
- Once you have installed Bugs, it should be all in the directory, c:/Program Files/WINBUGS14/
- Download OpenBUGS and extract the zip file into "c:/Program Files/OpenBUGS". It will then be at "c:/Program Files/OpenBUGS/".
Setting up R
- Go to the R webpage and follow the
instructions to download and install it. (Click on CRAN, then pick a mirror site, then click for the precompiled Windows version, then click on "base", then click to download the latest .exe file.)
- Go into R and type install.packages("arm") and
install.packages("BRugs"). (If you are using Windows Vista, you need to set some permissions to install these packages. See the discussion here. Open R by right clicking and choosing "run as administrator." Then you should be able to install packages. If this doesn't work, lower Vista's security level and install packages again.)
- Installing arm (our "applied regression modeling" package, designed for our new book) should automatically also install the Matrix and lme4 packages (which are needed for the lmer() function, which quickly fits multilevel regressions), the R2WinBUGS package (for running WinBUGS from R), and the car and foreign packages (which have some convenient functions). But sometimes these packages don't all install automatically, in which case you can install them one at a time (install.packages("Matrix"), install.packages("lme4"), etc.).
- Sometimes because of firewalls, etc., the direct method of installing R packages doesn't work. If so, follow these instructions.
- Set up R in single window format: at the top of the R window, click on Edit, then GUI preferences. Then at the top, click SDI. It's also a good idea to add a couple of zeroes to the "buffer" and "lines" options near the middle of the screen. Then click Save and navigate to "Program Files", then "R", then the latest R (e.g., "R-2.6.1"), then "etc", then save the Rconsole file there.
Each time you run R
- Start your session by typing library("arm") into the R console.
- Now you're ready to go!