Site icon R-bloggers

Getting Started with JAGS, rjags, and Bayesian Modelling

[This article was first published on Jeromy Anglim's Blog: Psychology and Statistics, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

This post provides links to various resources on getting started with Bayesian modelling using JAGS and R. It discusses: (1) what is JAGS; (2) why you might want to perform Bayesian modelling using JAGS; (3) how to install JAGS; (4) where to find further information on JAGS; (5) where to find examples of JAGS scripts in action; (6) where to ask questions; and (7) some interesting psychological applications of Bayesian modelling.

What is JAGS?

JAGS stands for Just Another Gibbs Sampler. To quote the program author, Martyn Plummer, “It is a program for analysis of Bayesian hierarchical models using Markov Chain Monte Carlo (MCMC) simulation…” It uses a dialect of the BUGS language, similar but a little different to OpenBUGS and WinBUGS.

Why JAGS?

The question of why you might want to use JAGS can be approached in several different ways:

http://stats.stackexchange.com/questions/9202/openbugs-vs-jags

More than anything I found that JAGS provided a useful entry point into the world of Bayesian modelling. This in turn appealed to me for several reasons:

  1. Even when I perform analyses using an NHST approach I often intuitively think of empirical research questions in terms of probability densities on a parameter of interest that changes as empirical and theoretical evidence is accumulated. See for example Thompson’s (2002) concept of meta-analytic thinking. Bayesian analysis provides tools for formalising this orientation.
  2. More broadly, I appreciate the explicitness that a Bayesian approach requires and encourages. E.g., specifying the distribution of the error term, specifying a prior, specifying the distribution of parameters in a mixed effects model, and so on.
  3. There are several modelling challenges that I’m currently working through where a Bayesian approach offers substantial flexibility and applicability. In particular, I’m interested in modelling individual differences in the effect of practice on strategy use and task performance and then relating these individual differences to factors like intelligence, prior experience, and personality.

JAGS Installation

JAGS runs on Linux, Mac, and Windows. I run JAGS on Ubuntu through an interface with R called rjags.

The following sets out a basic installation process:

  1. If necessary Download and install R and potentially a user interface to R like R Studio (see here for tips on getting started with R).
  2. Download and install JAGS as per operating system requriements.
  3. Install additional R packages: e.g., in R install.packages("rjags") . In particular, I use the packages rjags to interface with JAGS and coda to process MCMC output.

Information on JAGS

http://cran.r-project.org/web/views/Bayesian.html http://www.stat.columbia.edu/~gelman/bayescomputation/lunnbugswithcomments.pdf

Examples JAGS Scripts

I find it easier to pick up a new language by playing with examples. The following provides links to example JAGS code, often with accompanying explanations:

More broadly, examples and tutorials designed for WinBUGS can generally be adapted to be useful for JAGS. So for example, you can explore these WinBUGS examples:

Asking questions

There are several places to ask questions about JAGS, R, and Bayesian statistics.

In general, I prefer the Stack Exchange model for asking and answering questions on the internet, although the most important issue is typically where the experts are located.

Interesting Psychological Applications of Bayesian Modelling

If you want to see some examples of Bayesian modelling applied to psychological data, I found the following articles quite interesting. PDFs are available online.

If you know of any other interesting JAGS resources or have any comments about my choice of software for Bayesian data analysis, feel free to post a comment.

To leave a comment for the author, please follow the link and comment on their blog: Jeromy Anglim's Blog: Psychology and Statistics.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.