Goal : I want to create a loop in R that takes every combination of an ARIMA model on my insample data to get the smallest RMSE when I compare it with the out-of-sample data.
What I have
This is what I have when I do it manually:
#Creating the insample and outsample data
insamp <- ts(y[1:48], frequency = 12)
outsamp <- y[49:60]
#Createing the ARIMA model
fit <- Arima(insamp, order = c(1,0,0), include.drift = TRUE)
#forecasting the length of the out of sample data
fcast2 <- forecast(fit, h=length(outsamp))
#concluding from the RMSE how my model is performing with the out-of-sample data
accuracy(fcast, outsamp)
ME RMSE MAE MPE MAPE MASE ACF1
Training set 0.2536812 9.158607 6.86326 0.05216278 2.932405 0.3324541 0.01516999
Test set 8.4465515 26.409409 20.54116 1.20298077 4.552727 0.9950071 NA
What i need
I need a loop that takes every combination of Arima(i,j,k) and compares it to RMSE which the accuracy function outputs. It should provide the outputs of the (i, j, k) that minimize the RMSE.