# Gaussian state space forecasting with regression effects

The R package dlm implements filtering and smoothing (dlmFilter and dlmSmooth) for models with regression effects, but forecasting is not (yet) available for these models:

mod <- dlmModSeas(4)+dlmModReg(cbind(rnorm(100),rnorm(100)))
fi <- dlmFilter(rnorm(100),mod)
Error in dlmForecast(fi, nAhead = 12):
dlmForecast only works with constant models


How can I do this in R?

Here's the solution I came up with: The trick is to add NAs to the end of the observation data. When seeing NA as a response variable the Kalman filter algorithm will simply predict the next value and not update the state vector. This is exactly what we want to make our forecast.

nAhead <- 12


Is this correct?

• Good idea, and it basically works. I suspect that there's a tradeoff of some sort -- otherwise the dlm folks could simply use that solution to code dlmForecast -- but it does basically work. – Wayne Sep 2 '11 at 18:53
• How do I get updated forecast for dlmModReg with new data? If I re-run dlmFilter, it will re-estimate my model parameters. – user116555 May 23 '16 at 8:16