DLM out of sample errors

I'm using the DLM package to estimate a multivariate time series, I wanna check the out of sample forecasting, by estimating the residuals for 1, 6, 12 months ahead forecast? How can I calculate the 6 and 12 months ahead forcast like the kalman filter does for 1 month ahead forecast?

Thanks

Since this question is too general I update it.

My question was: I have a times series which go from 1970 to 1990, and I want to check if my model gives a good out of sample fit. In order to do so I divide my dataset in two parts and starting from January 1980 I calculate 1 month ahead forecast errors, by dlm (f). Than I want to calculate 12 months ahead forecast errors, so once my t is january 1980 then february 1980, and so on. I would like to know if there's a way to do so?

Thanks

Maybe is better to specify my question a little more, because I did a mistake, sorry. I estimate the model recursevely from 1970:1 to 1980:1 (dlm), , at t=1980:1 I estimate y(t+12) and I compare it with the real y(t+12), then I estimate y(t+12) but t=1980:2, and so on. I would like to know which is the way to do it automically? Cause I thought that i can ran a dlm and use the dlmForecast and change every time the dataset through the window command, but I don't think it's the right way. Maybe for (i in 1:10){ fit = dlmFilter((window(data, start=1, end=12+i),mod), dlmForcast(FIT, nahed=12)

• You need to provide a bit more detail. You can obviously forecast 12 months worth and then calculate residuals, so I'm guessing there's more to your request than that. – Wayne Dec 23 '11 at 14:44
• My question was: I have a times series which go from 1980 to 1990, and I want to check if my model gives a good out of sample fit. In order to do so I divide my dataset in two parts and starting from January 1980 I calculate 1 month ahead forecast errors, by dlm (f). Than I want to calculate 12 months ahead forecast errors, so once my t is january 1980 then february 1980, and so on. I would like to know if there's a way to do so? – Frank Jan 2 '12 at 12:02
• You divide your data into two parts, let's say 1980-1987, on which you train your DLM, and then 1988-1990 on which you test. From your trained DLM, you predict 24 months (1988-1990), then simply compare that data to the actual 1988-1990. That gives you 12-month-ahead forecast errors for a year (1989). If you want to modify your DLM to actually take a year's worth of data at a time and predict a year out, that's more complicated. – Wayne Jan 2 '12 at 14:49

2 Answers

If you have data up to and including $t$ and you want to forecast time $t+12$, you might add NA values from $t+1$ to $t+12$; see also this question.

• It isn't clear from the original question whether they're trying to directly calculate $t+12$, which is possible if you structure the problem correctly, or whether they have a DLM that won't forecast with the default procedure because it's variable. – Wayne Dec 23 '11 at 15:04
• My question was: I have a times series which go from 1980 to 1990, and I want to check if my model gives a good out of sample fit. In order to do so I divide my dataset in two parts and starting from January 1980 I calculate 1 month ahead forecast errors, by dlm (f). Than I want to calculate 12 months ahead forecast errors, so once my t is january 1980 then february 1980, and so on. I would like to know if there's a way to do so? – Frank Jan 2 '12 at 12:01
• So, did you estimate your model with data prior to January 1980? Otherwise, what I understand from what you write would not be an out of sample forecast. – F. Tusell Jan 2 '12 at 13:56
• no I wrote my question wrong, for example data 1970-1990 2 parts 1970-1980 and 1980-1990. – Frank Jan 3 '12 at 22:06

Before checking forecast accuracy did you check to see if the parameters had changed over time or of the variance of the errors changed over time ? Or if there were omitted deterministic input series that would be suggested by Intervention Detection procedures ala R. Tsay and others. Try Googling "automatic intervention detection" and similar searches for help on this.