# dlmForecast function in dlm R package forecasting constant values for seasonal series

I have a question regarding the use of the dlm CRAN package for forecasting values of a seasonal time series.

I've built a dlm model combining a stochastic local level model with a stochastic trigonometric (Fourier representation) seasonal component of period 96 (measurements every 15 mins with a daily cycle).

I used dlmMLE to estimate the parameters for my data and filtered and smoothed the series which all seems to be working fine.

However, when I try to use the dlmForecast function to predict out-of-sample observations, the predictions stay constant. The value of all "predictions" are equal to the sum of the filtered level and filtered seasonal components for the final observation in the series.

I have used dlmForecast with several other models including a model with a seasonal factor component but never before with a trigonometric seasonal component.

I notice in the documentation for dlmForecast it says "Currently, only constant models are allowed" so I wonder if this applies to trigonometric seasonal models.

I can give you two hints.

First, if you are using the standard recursive form (e.g. from Harvey) of the trigonometric seasonal components then your model is probably considered constant. Constant refers to the transition, observation matrices, not the state itself. In dlm terms, you have a constant model if you are not using the "J" components like JGG or JFF (if I remember correctly).

Second, when you say the filtering and smoothing are working out OK are you looking at the unobserved state and making sure that the periodic component (\psi) and trend (\mu) are independently sensible-looking?

• I see what you mean about the J components. I'm not using them so yes it's a constant model. Thanks for clarifying. As for your second comment, I have plotted the smoothed and filtered level and seasonal components and they look as expected. It's just that when I use forecasting, the level component stays constant throughout the forecast (as expected) but the periodic component also stays constant. Jun 3 '14 at 8:36
• Ok, one more shot in the dark ... are you using a dampening factor (often the notation is \rho)? What is it? Jun 4 '14 at 3:13
• No I'm not using any dampening factor. I don't think the dlm package actually provides for dampening factors in the dlmModTrig function and I haven't worked it in myself. Thanks anyway. Jun 9 '14 at 13:17

Here is an example which may help for you.

I used bivariate time series here from the NelPlo dataset (i used only first two ) and the modeling is done using dlm package in R

1. I build the dlm model

2. Estimate the dlm model parameter using dlmmle

3. Use estimated parameters to forecast

data(NelPlo)

# 1 build the dlm model
buildSu <- function(x) {
Vsd <- exp(x[1:2])
Vcorr <- tanh(x[3])
V <- Vsd %o% Vsd
V[1,2] <- V[2,1] <- V[1,2] * Vcorr
Wsd <- exp(x[4:5])
Wcorr <- tanh(x[6])
W <- Wsd %o% Wsd
W[1,2] <- W[2,1] <- W[1,2] * Wcorr
return(list(
m0 = rep(0,2),
C0 = 1e7 * diag(2),
FF = diag(2),
GG = diag(2),
V = V,
W = W))
}

# 2. Estimate the dlm model parameter using dlmMLE
suMLE <- dlmMLE(NelPlo[,1:2], rep(0,6), buildSu); suMLE
buildSu(suMLE$par)[c("V","W")] StructTS(NelPlo[,1], type="level") ## compare with W[1,1] and V[1,1] StructTS(NelPlo[,2], type="level") ## compare with W[2,2] and V[2,2] # 3. Use estimated parameters to forecast model.fit <- buildSu(suMLE$par)
model.filtered <- dlmFilter(NelPlo[,1:2], model.fit)