WinBUGS and R on Mac OS X

While JAGS is an excellent native alternative to WinBUGS, some features (like geospatial models) are still unique to WinBUGS. This describes how to run WinBUGS from R using R2WinBUGS on Mac OS X.

Install Wine

We will run WinBUGS using Wine, a windows emulator for *nix systems. There are different ways to installing wine on OS X and you are free too use different variants side by side. Here, we use DARWINE a precompiled version, which I found to work best with WinBUGS. Download version 1.0.1 here (be sure to use exactly that version, newer ones will not display WinBUGS's help files). Install it by dragging both Darwine and TriX to your Applications folder.

Note: In order to run Wine on OS X you need to have X11 installed. You can find X11 on your install disc, or you can download it as part of Apples developer tools here.

Darwine can be started like any other OS X app. To be able to use if from the command line as well add the following to lines to your .profile (or .bash_profile)
alias wine='/Applications/Darwine/Wine.bundle/Contents/bin/wine'
alias winepath='/Applications/Darwine/Wine.bundle/Contents/bin/winepath'

Install Microsoft fonts

Start TriX and select Microsoft's corefonts (Arial etc.) for installation.

Install WinBUGS

Download WinBUGS (link), the latest patch (link), and the keyfile link). Go to /Applications/Darwine/ and start WineHelper. Select Application/Open... and navigate to your downloaded WinBUGS installer. Install with standard options. Your WinBUGS folder will end up in
~/.wine/drive_c/Program Files/WinBUGS14
You can leave it there, or copy it to a more accessible location like your /Applications folder. Now you can simply start WinBUGS by opening it with WineHelper.

Call WinBUGS from R

To run WinBUGS from within R, you need Andrew Gelman's R2WinBUGS package (CRAN link). All we need to do now is to add some paths. Using the 8 schools example, the correct bugs() call includes the location of the WinBUGS executable (here /Applications/WinBUGS14), your current working directory (which you can abbreviate with .), and the full path to both wine and winepath executables:
bugs(data, inits, model.file = "schools.bug", parameters = params,
n.chains = 3, n.iter = 1000, useWINE=TRUE,
bugs.directory = "/Applications/WinBUGS14",
working.directory = ".",
WINE="/Applications/Darwine/Wine.bundle/Contents/bin/wine",
WINEPATH="/Applications/Darwine/Wine.bundle/Contents/bin/winepath")