How to grid search ARIMA Model with forecast libary in R?

63 Views Asked by At

I am trying to tune the ARIMA Model using Arima() function with Box-Cox Transformation using grid search and I need a help.

Here is my code:

library(tidyverse)
library(fpp2)
library(lubridate)
library(tsibble)
data("AirPassengers")
arima_gridsearch <- function(data,p,d,q,lambda=1){
  order_list = list(seq(0, p),
                    seq(0, d),
                    seq(0, q)) %>%
    purrr::cross() %>%
    purrr::map(purrr::lift(c))
  orderdf = tibble("order" = order_list)
  
  models_df = orderdf %>%
    dplyr::mutate(models = purrr::map(.x=order,.y=lambda, 
                                      ~possibly(arima, 
                                                       otherwise = NULL)(x = data, 
                                                                         order = .x,lambda=.y))) %>% 
    dplyr::filter(models != 'NULL') %>% 
    dplyr::mutate(aic = purrr::map_dbl(models, "aic"))
  best_model = models_df %>%
    dplyr::filter(aic == min(models_df$aic, na.rm = TRUE))
  return(best_model)
}
arima_gridsearch(data = AirPassengers,p = 10,d = 10,q = 10,lambda = "auto")

But here's what I got:

# A tibble: 0 x 3 with 3 variables: order , models , aic Use colnames() to see all variable names

Warning message: In min(models_df$aic, na.rm = TRUE) : no non-missing arguments to min; returning Inf

I also wanted to add the seasonal component when the data has strong seasonal pattern with the lowest RMSE in both training and test set in tuning the ARIMA model.

0

There are 0 best solutions below