Chapter 6 Univariate state-space models

This chapter will show you how to fit some basic univariate state-space models using the MARSS package, the StructTS() function, and JAGS code. This chapter will also introduce you to the idea of writing AR(1) models in state-space form.

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

All the data used in the chapter are in the MARSS package. The other required packages are stats (normally loaded by default when starting R), datasets and forecast. Install the packages, if needed, and load:

library(stats)
library(MARSS)
library(forecast)
library(datasets)

To run the JAGS code example (optional), you will also need JAGS installed and the R2jags, rjags and coda R packages. To run the Stan code example (optional), you will need the rstan package.