Tuning the parameters (II): We create the arima_search2 function which trains in the training partition SARIMA models with different parameters combinations and returns us the model's parameters and its respective AIC score (we filter those models with k <= 6). Then we select the 3 best models.
arima_search2 <- function(x){
for(i in 1:nrow(x)){
md <- NULL
md <- arima(train, order = c(x$p[i], 1, x$q[i]),
seasonal = list(order = c(x$P[i], 1, x$Q[i])))
x$AIC[i] <- md$aic
x <- x %>% arrange(AIC)
}
x
}
best_arima_models <- arima_search2(arima_grid)
best_arima_models <- best_arima_models[1:3,]
best_arima_models
## p d q P D Q k AIC
## 1 1 1 1 0 1 2 6 2568.698
## 2 1 1 1 0 1 1 5 2568.944
## 3 1 1 1 1 1 1 6 2569.577
The best models are (from best to worst) SARIMA(1,1,1)(0,1,2), SARIMA(1,1,1)(0,1,1), SARIMA(1,1,1)(1,1,1)