Hello everybody,
I am fairly new to R and have encountered a number of issues during my work. I hope you can help me. I want to do a regression with ARIMA errors.
1.) Is my approach to variable selection so correct? Does auto.arima()
only use additive regression?
To do this, I first examine my time series with the tso ()
function and then read in various outliers as variables. I also have a lot of dummy variables. Which will be taken into consideration as well.
In a next step, I investigate displacements with the ccf ()
function. Here it is necessary to differentiate my data series. If necessary, the variables are also differentiated before use. After moving I have 135 variables available.
With the alias ()
function and the vif ()
function, I delete different variables that correlate with each other.
Then I use the forward selection while minimizing the AIC. A relatively large number of variables are selected here. When using these variables on my training set, the model performs relatively well.
Whereas I often have problems when looking for the right variables the residuals are sometimes not normalized etc. why is that and are these tests even necessary?
2.) Have I programmed something wrong for my forecasting?
However, if I apply the variables to my test set with a loop (see below), this method performs significantly worse than stlf ()
or ets ()
(MAPE: 30 vs. 28 vs. 27). In my opinion, however, this method should work better.
# "ts" is my timeseries
total_reg <- as.matrix(complete.regression_data.ts[,c("LS39", "F32_1", "AO63", "F33_0", "F4_3",
"TC102", "F35__1", "F45_8", "F5_1", "AO71", "F65__4", "F66_3",
"F51_1", "F63_0", "F37_2", "F34__7", "F13__5")])
# Forecast
mlr.arima_mat <- matrix(0, nrow = n, ncol = h)
for (i in 1:n)
{
x <- window(ts, end=c(2018, 52) + (i-1)/52)
xregs <- window(total_reg, end = c(2018, 52) + (i-1) / 52)
xregs2 <- window(total_reg, end = c(2019, 1) + (i-1) / 52)
xreg3 <- xregs2[1,, drop=FALSE]
refit.arima <- auto.arima(x,
xreg=xregs,
d=1, D=0,
ic=c("aic"),
stepwise = FALSE,
approximation = TRUE)
mlr.arima_mat[i,] <- forecast(refit.arima,
h=h,
xreg=xreg3)$mean
}
Because I always get that error message:
Error:
In window.default(x, ...) : 'end' value didn't change
To summarize again:
1.) Is my procedure for selecting variables for the ARIMA model correct, or do I have to select my variables according to other criteria?
2.) Have I created the loop correctly so that it predicts a period at a time?
Thanks already for your help
Fitch