Download JAGS Version 3.3.0 user manual
Transcript
Chapter 2
Running a model in JAGS
JAGS is designed for inference on Bayesian models using Markov Chain Monte Carlo (MCMC)
simulation. Running a model refers to generating samples from the posterior distribution of
the model parameters. This takes place in five steps:
1. Definition of the model
2. Compilation
3. Initialization
4. Adaptation and burn-in
5. Monitoring
The next stages of analysis are done outside of JAGS: convergence diagnostics, model criticism,
and summarizing the samples must be done using other packages more suited to this task.
There are several R packages designed for analyzing MCMC output, and JAGS can be used
from within R using the rjags package.
2.1
Definition
There are two parts to the definition of a model in JAGS: a description of the model and the
definition of the data.
2.1.1
Model definition
The model is defined in a text file using a dialect of the BUGS language. The model definition
consists of a series of relations inside a block delimited by curly brackets { and } and preceded
by the keyword model. Here is the standard linear regression example:
model {
for (i in 1:N) {
Y[i]
~ dnorm(mu[i], tau)
mu[i] <- alpha + beta * (x[i] - x.bar)
}
x.bar
<- mean(x)
4