Saturday, January 28, 2012

Complete steps for installing software and programs

[Updated February 04, 2013]

To use the programs, there are six basic steps:
  1. Install the general programming language R. Go to the R web site and install the latest version of R appropriate for your computer (Windows, Mac, Linux).
  2. Install the R editor RStudio. R comes with its own built-in editor, but it is not very useful for dealing with long programs. Go to the RStudio web site and install the latest version of RStudio appropriate for your computer (Windows, Mac, Linux). This is optional, but highly recommended.
  3. Install the Bayesian sampling program JAGS. Go to the JAGS web site and install the latest version of JAGS appropriate for your computer (Windows, Mac, Linux).
  4. Install the package that lets R talk to JAGS. Invoke RStudio. Click the "Tools" menu and then "Install Packages." In the Packages slot type "rjags" without the quotes, or, if a menu of packages appears, select rjags. Then click install. (Alternatively, if working in R not RStudio, at the command line, type install.packages("rjags")  You may be prompted to select an internet archive to get the package from; select a site geographically near you.) Also install the package "runjags," although it is not presently used in any of the book's programs, future programs will use it.
  5. Get the programs used in the book. For a zip file (named ProgramsDoingBayesianDataAnalysis.zip) that contains all the programs in a single file, click HERE. Be sure to unzip (extract) the programs from the zip file.
  6. Read the important tips for running the programs, below! Really, read them. Remember them. It'll save you frustration later.
Important tips for running the programs:

• I now recommend using JAGS instead of BUGS, and that's why the installation instructions (above) only mention JAGS, not BUGS. Any program that had "Bugs" or "Brugs" in its file name now has a JAGS equivalent with "Jags" in its file name. More info is available at this blog post.
• Many of the programs call other programs when running, and write auxiliary files, so
      • put all the programs together in the same folder (they come together in one folder, so it's easiest to leave them there), 
      • put that folder under a writeable directory (not in a protected system folder), such as where you would store ordinary research data, and
      • be sure that R has that folder as its working directory. Set the working directory in RStudio from the menu: Tools -> Set Working Dir. Or, if you're using R's built-in editor, set the working directory in R's command console from the menu: File -> Change dir...Without setting the folder as R's working directory, you will get errors when programs try to find other files and can't find them.
Mac or Linux users: Having trouble with graphics when running the programs? I have begun modifying the graphics commands in the programs so that the same commands work on MacOS/Linux and Windows. If you are using MacOS/Linux and encounter graphics troubles, see this blog post for info on how to modify the graphics commands.
• Programs are updated occasionally. For a list of individually downloadable programs sorted by date modified, click HERE. You can check if you have the most recent version.


4 comments:

AndrewAcosta said...

I found the book to be an excellent way to get beyond the pages of proofs and theory, to explain Bayes in terms that can easily be related to!

I have a stack of Bayesian books I am citing for my PhD dissertation, and this one sits on the top (which is often unstable since it is larger than Zellner or Albert).

Now, I want to work through every R example, and learn what JAGS can do, which is not actually in my book.

isomorphisms said...

linux boxes may experience the same problem as Macs (which you described in step #2).

For me, using Ubuntu 10.04, it was necessary to use JAGS 2.*. Downloaded the binary from JAGS site, sudo dpkg -i ****.deb, and then a further step was necessary; gksudo synaptic and fix the broken package, because


jags depends on libatlas3gf-base; however:
Package libatlas3gf-base is not installed.



Luckily Synaptic took care of the problem.

isomorphisms said...

Thank you for posting these instructions. And thanks for all your other very accessible work on Bayesian stats!

Eric Brown said...

I was able to get rjags and JAGS 3 to work on Mac OS X Lion, provided that I compiled JAGS from source. I think that it is necessary to use PIC flags when compiling JAGS so that it works with R (e.g., from MacPorts):

Install R with:
port install R +gcc46 +recommended

Install JAGS from source:
export CC=gcc-mp-4.6 CFLAGS="-fPIC -O2 -g" CXX=g++-mp-4.6 CXXFLAGS="-fPIC -O2 -g" F77=gfortran-mp-4.6 FFLAGS="-fPIC -O2 -g" ./configure --with-pic --prefix=/opt/JAGS-3.2.0

(change prefix to wherever you want to install) and then in my .bashrc

export PATH=/opt/JAGS-3.2.0/bin:{$PATH}
export DYLD_LIBRARY_PATH=/opt/JAGS-3.2.0/lib:${DYLD_LIBRARY_PATH}

Close terminal window, open new window so that .bashrc is sourced. Then you should be able to install rjags with

/opt/local/bin/R
install.packages('rjags', type='source', dependencies=c('Depends','Suggests'))