JAGS and R online

06 Oct 2014

General information

You will need to use JAGS and other probabilistic software in this course. Here are the steps to do this:

  • Go to this: address http://tinyurl.com/oldrobot Make sure to use a standard laptop-sized screen and a relatively recent browser. Note: the website will open on Monday March 2nd, during the class time.
  • Create an account where your username should be your student id (if your student id is not in our database for some reason, send us a private message in Piazza). Note: do not use the same password as you use for important services, since it is not encrypted.
  • Once you are logged in, you can look at the tutorials to get familiar with JAGS and the online tool.
  • Then go in the assignment tab and start by clicking Take assignment.
  • Make sure you click on Commit often to save your work!

Quick reference

Some quick references for convenience (see the tutorials for more context and information). The notation in JAGS is fairly similar to standard mathematical notation, but with some slight differences.

Discrete distributions (PMFs)

  • Bernoulli: dbern(p)
  • Binomial: dbin(p, n)
  • Categorical: dcat(p)
  • Poisson: dpois(lambda)
  • Geometric: dnegbin(p, 1) support is $0, 1, 2, \dots$
  • Negative Binomial: dnegbin(p, r) support is $0, 1, 2, \dots$

Continuous distributions (PDFs)

  • Uniform: X ~ dunif(a, b)
  • Normal: X ~ dnorm(mu,1/sigma^2) uses the inverse of the variance, a parameter called the precision
  • Exponential: X ~ dexp(lambda) rate parameterization
  • Gamma: X ~ dgamma(alpha, lambda) shape-rate parameterization

Useful functions

  • Absolute value: abs(x)
  • Exponential: exp(x)
  • Conditional: ifelse(x,a,b)
  • Logarithm (base e): log(x)
  • Square root: sqrt(x)
  • Maximum: max(x, y) works on vectors and/or more than two arguments
  • Minimum: min(x, y)
  • Sum: sum(x) sums the elements in the vector x

Additional readings

To get detailed information:

  • Complete reference,
  • How it works under the hood: tutorial on MCMC,
  • A book on using JAGS to build Bayesian models: "Doing Bayesian Data Analysis: A Tutorial with R and BUGS", John Kruschke.