From Documentation
Revision as of 23:08, 1 November 2017 by Ppomorsk (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Instructions for usage on new Compute Canada clusters (cedar and graham)

Installation of OpenBUGS

Download the source code from the Downloads page and then copy it to graham or cedar.

tar xvfz OpenBUGS-3.2.3.tar.gz
cd OpenBUGS-3.2.3
./configure --prefix=/home/$USER/lib/openbugs-3.2.3
make
make install

If this fails because of missing gnu/stubs-32.h file, you must contact the system administrator to install that file.

Installation of R2OpenBUGS

First, load the R module. You can find out which are available by running:

module spider r

In this case we choose the latest (as of November, 2017):

module load r/3.4.0

Then start R:

R

and inside it run:

install.packages("R2OpenBUGS")

To make it able to find OpenBUGS at runtime, you need to set the variable that point it to the location where the binary is installed.

export OpenBUGS_PATH=$HOME/bin/OpenBUGS


Instructions for usage on older SHARCNET clusters (eg. orca)

Obtaining OpenBUGS

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

cd OpenBUGS

and run configuration first

./configure --prefix=$HOME/lib/openbugs-3.2.3

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

>install.packages("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

export OpenBUGS_PATH=$HOME/bin/OpenBUGS

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.