(→Using OpenBUGS in R)
|Line 1:||Line 1:|
Revision as of 10:01, 7 January 2016
|This page is flagged as an 'ancient wiki page' and is under review in ticket .|
OpenBUGS is an open source project. It can be downloaded from here. Look for the package for Linux, it comes as gzipped Unix tar file, named as OpenBUGS-version.tar.gz, e.g. OpenBUGS-3.2.3.tar.gz.
Installing OpenBUGS for Linux
First, save it and copy it to your account, say, in folder Downloads. Then unpack it with command
tar zxvf OpenBUGS-3.2.3.tar.gz
This will extract the content from the tar file and put in folder OpenBUGS-3.2.3. Then go into that folder
and run configuration first
This sets where to install the package. In this case, it will be installed in /home/you/lib/openbugs-3.2.3. You may choose another location you like. By default the installation directory is /usr/local, which is not what you want.
Then compile and install it with commands
make make install
The compilation shouldn't take long to complete. It is likely, however, that the compilation may fail due to missing system files. specifically, gnu/stubs-32.h. If this is the case, you will need to ask the system administrators to install the missing system files.
Upon success, you should have three folders created in /home/your/lib/openbugs-3.2.3
bin lib share
In bin, there are two binaries: OpenBUGS and OpenBUGSCli. OpenBUGS is what you will need when you run R calling bugs.
Installing R2OpenBUGS for R
In order to user OpenBUGS in R, you need an R interface to BUGS. The package R2OpenBUGS is recommended. The package can be installed in user space. To install it, first, load R module. You might need to unload intel module on SHARCNET systems to avoid possible conflict
module unload intel
To see what releases of R are available, use command
module avail r
If you prefer a specific version, e.g. 3.1, then use command
module load r/3.1
Otherwise, the command
module load r
would just load the latest version by default.
Then run R from command line. At the R prompt, use R command install.packages() to install R2OpenBUGS
and follow the instructions.
Using OpenBUGS in R
The R2OpenBUGS is an interface to OpenBUGS. In order to use OpenBUGS in R, you need to tell where OpenBUGS resides. According to the help info, as you would get from R command
>library(R2OpenBUGS) >... ... >help(bugs)
there are two ways of telling bugs() where OpenBUGS is. First you may specify the path to OpenBUGS in the call to bugs() in your R code. Assume that OpenBUGS executable is installed in /home/you/bin (you need to change it to where you have put the binary OpenBUGS), the call to bugs() would like something like this
>schools.sim <- bugs(data, inits, parameters, OpenBUGS.pgm="/home/you/bin/OpenBUGS", model.file="/home/youschools.txt", n.chains = 3, n.iter = 1000, working.directory = NULL)
Note, this line has the paths to the OpenBUGS and the model file specific to the system you are using. To make your R code portable, you may simply set environment variable at the command line or put the following line in .bash_profile in your home directory
and also, set the working directory to the current folder (the last argument) as follows
>schools.sim <- bugs(data, inits, parameters, model.file="schools.txt", n.chains = 3, n.iter = 1000, working.directory = ".")
When working.directory is where the input and output are stored. By default, it is set to NULL and the location is unexpected from one system to another.