Reputation: 3387
In my spare time I try to sharpen my skills a bit on forecasting techniques and today's issue focused on forecasting with multiple regressors. I have created a time series that is influenced by two regressors, but wondering how forecast with them.
library(forecast)
I tried the following:
First my time series:
ts.series3 <- structure(c(313, 253, 230, 258, 261, 303, 266, 269, 245, 274,
346, 252, 283, 286, 260, 365, 295, 268, 301, 304, 353, 310, 313,
285, 319, 403, 294, 330, 333, 303, 425, 343, 312, 350, 354, 411,
361, 366, 333, 469, 380, 346, 487, 394, 359, 404, 511, 372, 418
), .Tsp = c(2003.08333333333, 2007.08333333333, 12), class = "ts")
The time series above is based on the trend show in ts.trend
(below) and is modified by the modifiers. In case the first modifiers is relevant the value is increased by 25%, and in case of the second then the value is decreased with 10%. When both are applicable then they are increased by 15%.
ts.trend <- structure(c(250, 253, 255, 258, 261, 264, 266, 269, 272, 274,
277, 280, 283, 286, 289, 292, 295, 298, 301, 304, 307, 310, 313,
316, 319, 323, 326, 330, 333, 337, 340, 343, 347, 350, 354, 357,
361, 366, 370, 375, 380, 385, 390, 394, 399, 404, 409, 414, 418
), .Tsp = c(2003.08333333333, 2007.08333333333, 12), class = "ts")
A multivariate time series with the two regressors:
modifiers <- structure(c(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0,
0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0,
0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0,
1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0,
1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), .Dim = c(60L,
2L), .Dimnames = list(NULL, c("Adjust1", "Adjust2")), .Tsp = c(2003.08333333333,
2008, 12), class = c("mts", "ts"))
Then I try to make the following model:
fit.series3 <- auto.arima(ts.series3,xreg=window(modifiers,end=2007.16))
fcast.series3 <- forecast(fit.series3,xreg=window(modifiers,start=2007.161))
The code seems to be working fine, but the plot (see below) doesn't really make sense as there are no regressors identified you would expect that the forecast would more or less follow the trend line. Is there somebody who can provide some insights into what is happening here?
plot(fcast.series3)
The forecast plot looks as following when I am not using any regressor variables. I am more confident about this forecast than about the one in the plot above. I used the following lines of code to produce the chart:
fit.series3clean <- auto.arima(ts.series3)
fcast.series3clean <- forecast(fit.series3clean)
plot(fcast.series3clean)
I am wondering whether somebody understand what is happening with my forecast with multivariate xreg values. Also, I am curious to hear about other approaches to forecasting with multivariate regressors.
Upvotes: 3
Views: 5327
Reputation: 31800
Take a look at your fitted model:
> fit.series3
Series: ts.series3
ARIMA(0,1,1)(0,1,0)[12]
Coefficients:
ma1 Adjust1 Adjust2
-0.7586 80.1919 285.6239
s.e. 0.0832 0.0842 NaN
sigma^2 estimated as 71.55: log likelihood=-128.38
AIC=264.76 AICc=266.05 BIC=271.09
Warning message:
In sqrt(diag(x$var.coef)) : NaNs produced
There is a problem with the coefficient of Adjust2
as the standard error is NaN
.
The following code shows the problem:
> window(diff(diff(modifiers[,2],12)),end=2007.16)
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2004 0 0 0 0 0 0 0 0 0 0
2005 0 0 0 0 0 0 0 0 0 0 0 0
2006 0 0 0 0 0 0 0 0 0 0 0 0
2007 0 0
During the fitting period the twice differenced Adjust2
is always zero making the coefficient essentially undefined (and with infinite variance).
Upvotes: 2