February 5, 2012

(This article was first published on Rrasch, and kindly contributed to R-bloggers)

Running 64 bit R, JAGS and rjags on EC2

Winbugs and Jags free Item Response Theory from the dot matrix plots of proprietary software and open up a multicoloured world of posterior predictive model checking. Fitting IRT models using brute force is not for the impatient, however. That’s why, just as early psychometricians shipped off their calculations to teams of monks. I’ve shipped off my model fitting to the West Coast of Ireland (seems apt considering the number of monasteries there) so that I can use my computer to do more important things. Like write about why I’ve shipped off my model fitting to the West Coast of Ireland.

Configuration of rjags for 64-bit R is a little tricky – so here’s how I did it.

Warning 1!

If you want to run JAGS in the cloud it’ll probably cost you a few bob. That’s because on the EC2 micro instances JAGS models tend to trigger the CPU limit and grind to a halt. If you want to run odd jobs then I’d suggest setting up JAGS on an official Ubuntu EC2 Large image, shutting it down, saving the image, then running it at a spot price. That means for a you’ll be paying about $0.38 during set up and $0.144 per hour when it is running. If you want an image that is always running I’d suggest you check out monthly hosting rates with other cloud services which can be cheaper than EC2. If you don’t want to use R or JAGS then heroku is tremendous for ease of deployment of web projects.

Warning 2!

Don’t try and set this up on ubuntu’s new image Precise unless you want to haunt the LAPACK and BLAS message boards for the next six months…

Warning 3!

If none of this means anything to you I’d recommend playing about with EC2 micro instances and ensuring you can get into and out of them using SSH. As my main computer is Windows based I use putty and FileZilla. FileZilla allows you to configure a default text editor so it is fine for writing most programming languages.

A useful guide on setting yourself up on EC2 with ubuntu

Setting up ftp on ubuntu

I like ubuntu – it makes life easy and the documentation is usually helpful.

Step 0:

Start up your soundtrack!

Step 1: Install ubuntu:

Current Time 09:32

Soundtrack: Ligeti, Atmospheres

Official ubuntu AMIS are here.
Enter region and ubuntu builds into the filter. I chose an oneiric image on a 64 bit platform with ebs:

eu-west-1 oneiric amd64 ebs 20120108 ami-09e3dc7d

For the initial set up I chose Large as the installation is much quicker… Again a few dimes involved…

So, here goes. Choose defaults, your SSH security group which I assume you’ve set up, and away we go…

Step 2: Install R

Current Time 09:44

Soundtrack: Study for Player Piano Number 9

sudo nano /etc/apt/sources.list

deb http://<my.favorite.cran.mirror>/bin/linux/ubuntu oneiric/
deb http://www.stats.bris.ac.uk/R/bin/linux/ubuntu oneiric/

sudo apt-get update
sudo apt-get install r-base
sudo apt-get install r-base-dev

Step 3: Coda package and JAGS
Current Time: 10:02

Soundtrack: Treeline

sudo R

wget http://downloads.sourceforge.net/project/mcmc-jags/JAGS/3.x/Source/JAGS-3.2.0.tar.gz
tar xf JAGS-3.2.0.tar.gz
cd JAGS-3.2.0
./configure --libdir=/usr/local/lib64
sudo make install
cd ~

Step 4: RJAGS
Current Time: 10:13

Soundtrack: De Staat

The final hurdle, one on which many eyeballs have bled. Configuring RJAGS for 64 bit R. Pity poor Martyn Plummer who is doomed to wandering the bulletin boards helping lost souls in search of their .so

Luckily, I wrote down how to do this the last time I was in purgatory. Now, let me see… Where is it… Please… No… Oh, the horror…

Found it!

wget http://cran.r-project.org/src/contrib/Archive/rjags/rjags_3-4.tar.gz
sudo R CMD INSTALL --configure-args='--with-jags-include=/usr/local/include/JAGS --with-jags-lib=/usr/local/lib64 --enable-rpath' rjags_3-4.tar.gz

Step 5: Test it!
Current Time: 10:23

Soundtrack: De Staat

Try, for example: www.johnmyleswhite.com

Step 6: Stop the instance and save the image on AWS. Then, when you are ready to run your job you can request a spot instance and pay for only the time it takes to run your job.

Current Time: 10:32

Soundtrack: De Staat

Total Time: 1 hour (including at least ten minutes interrogating my fish as to where I had saved my instructions for configuring RJAGS)

Total Cost: $0.38

Final warning: If you are SSHing into your instance don’t forget to set your analysis going using the nohup command, otherwise your analysis will be terminated as soon as you log out.

To leave a comment for the author, please follow the link and comment on their blog: Rrasch.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)