This page will show you how to make a quick (I hope!) start with JAGS and rjags.
Installation involves just two steps:
rjags
package.
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!