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). Mac users: As of May 07, 2014, it seems that rjags (step 4 below) only works for the Snow Leopard build of R3.1.0, not the Mavericks build of R3.1.0. So, use the Snow Leopard build.
  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 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.


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}

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

install.packages('rjags', type='source', dependencies=c('Depends','Suggests'))

Can Candan said...

Can not install rjags

Is there an up to date information on how to install.

I'm using osx 10.9.2
r version 3.1

Tried the instructions of the above comment.

Warning: namespace ‘rjags’ is not available and has been replaced
by .GlobalEnv when processing object ‘LINE’
** testing if installed package can be loaded
Error : .onLoad failed in loadNamespace() for 'rjags', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/rjags/libs/':
dlopen(/Library/Frameworks/R.framework/Versions/3.1/Resources/library/rjags/libs/, 10): Symbol not found: __ZN5RangeC1ERKNSt3__16vectorIiNS0_9allocatorIiEEEES6_
Referenced from: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rjags/libs/
Expected in: flat namespace
in /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rjags/libs/
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/Library/Frameworks/R.framework/Versions/3.1/Resources/library/rjags’
Warning in install.packages :
installation of package ‘rjags’ had non-zero exit status

John K. Kruschke said...

Dear Can Candan:

Did you see in Step 1: "Mac users: As of May 07, 2014, it seems that rjags (step 4 below) only works for the Snow Leopard build of R3.1.0, not the Mavericks build of R3.1.0. So, use the Snow Leopard build."

I am told that if you use the Snow Leopard build of R, then the ordinary install.packages(rjags) command should work.

Please let me know if you've tried that and it does not work (and do provide details). I will forward your question to the JAGS blog (Martyn Plummer), as I do not use a Mac myself.

John K. Kruschke said...

At the JAGS discussion/help thread (here), Martyn Plummer said: "I have been in contact with Bill [NorthCott]. It will be June before he is able to make a Mavericks build, I'm afraid, so you will need to be patient. The Snow Leopard build does work on Mavericks so you will need to use this workaround until then. Sorry for the inconvenience."

Can Candan said...

Thanks Mr John,
it works as you have said :)

Jeremy Bray said...

Hi, I am running R Studio on Mac OSX Version 10.9.3 to input the programmes and do the exercises in the textbook.

When running programmes, R Studio is having trouble sourcing the 'embedded' programmes, such as plotPost.R, which is used in chapter 7, as well as openGraph.R and saveGraph.R. I just get error messages, rather than have them working.

I have followed the instructions to 'point' the default working directory to the folder where these programmes are stored, but I still can't get them to work.

Grateful for somebody giving me an idea of what I've done wrong, and how I can rectify the problem.

And many thanks for the book! What a great, comprehensible and comprehensive intro to Bayesian Data Analysis!

John K. Kruschke said...

Dear Jeremy:

The easiest way to get RStudio (or R) to use the proper working directory is to open RStudio via the file itself. That is, start with RStudio closed, then find the file (i.e., script or program) you want to open. Double-click (or equivalent in MacOS) and open the file in RStudio. When RStudio opens, it knows to use the file's folder as the working directory.

For more details, check out this video:
at 4:00 minutes and 5:30 minutes.

The above assumes that you have left all the programs together in the same folder. It also assumes that you have unzipped (a.k.a. extracted) the folder after you downloaded it.

Let me know how it goes, and thanks for your interest in the book!