This page will show you how to make a quick (I hope!) start with JAGS and rjags.

Installation involves just two steps:

  1. Go to this page: http://sourceforge.net/projects/mcmc-jags/files/
    • At this point I think you can simply click on “Download Latest Version” and install it (if that doesn’t work for you, you can go into the JAGS folder and find the specific version for your operating system).
  2. Then go to R and install the rjags package.
    • It is easy to install R packages from inside R Studio. You just need to be connected to the web. See the pane where your plots come out? In that same location you should be able to select a tab called “Packages.” From there click “Install” and write the name of the package you want to install (that is, rjags).

If the above steps went smoothly, everything should be installed.

To test to make sure it is working you can run the following 12 lines of code in R. You could just copy those 12 lines out of this web page, paste them into your R console, and hit enter. (We’ll understand the code shortly; for now we’re just trying to get JAGS and rjags up and running, and test the installation.)

library(rjags)
x <- 56  # data
mymodel <- "
  model{
    x ~ dbin(p, 100)
    p ~ dunif(0,1)
  }
"
m1 <- jags.model(textConnection(mymodel), data=list(x=x))
cs <- coda.samples(m1, c('p'), 10000)
s <- data.frame(cs[[1]])
hist(s$p, xlim=c(0,1))

If you get a histogram that looks roughly like the one below, it’s working!