Chapter 12 JAGS for Bayesian time series analysis

In this lab, we will illustrate how to use JAGS to fit time series models with Bayesian methods. The purpose of this chapter is to teach you some basic JAGS models. To go beyond these basics, study the wide variety of software tools to do time series analysis using Bayesian methods, e.g. packages listed on the R Cran TimeSeries task view.

A script with all the R code in the chapter can be downloaded here. The Rmd for this chapter can be downloaded here.

Data and packages

For data for this lab, we will use a dataset on air quality in New York. For the majority of our models, we are going to treat wind speed as the response variable for our time series models.

data(airquality, package = "datasets")
Wind <- airquality$Wind  # wind speed
Temp <- airquality$Temp  # air temperature
N <- dim(airquality)[1]  # number of data points

To run this code, you will need to install JAGS for your operating platform using the instructions here. Click on JAGS, then the most recent folder, then the platform of your machine. You will also need the coda, rjags and R2jags packages.

library(coda)
library(rjags)
library(R2jags)