12.5 Forecasting with JAGS models
There are a number of different approaches to using Bayesian time series models to perform forecasting. One approach might be to fit a model, and use those posterior distributions to forecast as a secondary step (say within R). A more streamlined approach is to do this within the JAGS code itself. We can take advantage of the fact that JAGS allows you to include NAs in the response variable (but never in the predictors). Let’s use the same Wind dataset, and the univariate state-space model described above to forecast three time steps into the future. We can do this by including 3 more NAs in the dataset, and incrementing the variable N
by 3.
<- list(Y = c(Wind, NA, NA, NA), N = (N + 3), Y1 = Wind[1])
jags.data <- c("q", "r", "EY", "u")
jags.params <- ("ss_model.txt")
model.loc <- jags(jags.data, parameters.to.save = jags.params,
mod_ss_forecast model.file = model.loc, n.chains = 3, n.burnin = 5000, n.thin = 1,
n.iter = 10000, DIC = TRUE)
We can inspect the fitted model object, and see that EY
contains the 3 new predictions for the forecasts from this model.