rpurrrarimaforecastpmap

Using Arima forecast with possibly doesn't work


i have two pieces of code: one is working, another isn't. Maybe someone has any idea why it doesn't work.

PS. I know that it isn't full reproducible example, but if it be necessary I would provide one.

arima_cv = forecast_data_ini_split %>% 
  unnest(training_splits_for_cv_models) %>% 
  crossing(arima_models_for_cv %>% slice(17:18)) %>% 
  mutate(analysis_data = map(.x = splits, ~tk_analysis_fun(.x))) %>% 
  mutate(assessment_data = map(.x = splits, ~tk_assessment_fun(.x)))

This one works

good = arima_cv %>% 
  mutate(models = furrr::future_pmap(list(analysis_data, p, d, q, P, D, Q),
                                     .f = ~Arima(y = ..1, order = c(..2, ..3, ..4), seasonal = c(..5, ..6, ..7), xreg = NULL,
                                                          include.mean = TRUE, include.drift = FALSE, method ="CSS-ML"))) %>% 
  mutate(models_metrics_ass = map2(.x = models, .y = assessment_data,  ~accuracy_assessment_fun(.x, .y)))

This one doesn't

bad = arima_cv %>% 
  mutate(models = pmap(list(analysis_data, p, d, q, P, D, Q),
                                     ~possibly(Arima, otherwise = NULL )(y = ..1, order = c(..2, ..3, ..4), seasonal = c(..5, ..6, ..7), xreg = NULL,
                                                 include.mean = TRUE, include.drift = FALSE, method ="ML"))) %>% 
  mutate(models_metrics_ass = map2(.x = models, .y = assessment_data,  ~accuracy_assessment_fun(.x, .y)))

The error message is:

Error in eval(expr, p) : the ... list contains fewer than 4 elements

The problem is with last line of code:

mutate(models_metrics_ass = map2(.x = models, .y = assessment_data,  ~accuracy_assessment_fun(.x, .y)))

It seems that possibly somehow change an models output, and I can't make forecast and count accuracy.

Thanks in advance, Sewe


Solution

  • So, the problem was with Arima, not with possibly.
    I put a constant to include.drift parameter, whereas it should be a variable.
    Btw. there are very few examples with possibly and pmap, so if you would like and working example, please, write me PM.

      unnest(training_splits_for_cv_models) %>%
      left_join(arima_models_for_cv) %>% 
      # crossing(arima_models_for_cv %>% 
      # slice(17:19) %>%
      mutate(analysis_data = map(.x = splits, ~tk_analysis_fun(.x))) %>% 
      mutate(assessment_data = map(.x = splits, ~tk_assessment_fun(.x))) %>% 
      mutate(models = furrr::future_pmap(list(analysis_data, p, d, q, P, D, Q, include.drift),
                                           .f = ~possibly(Arima, otherwise = NULL)(y = ..1, 
                                                       order = c(..2, ..3, ..4), 
                                                       seasonal = c(..5, ..6, ..7), 
                                                       include.drift = ..8, method ="CSS-ML"))) %>%
        mutate(models_metrics_ass = map2(.x = models, .y = assessment_data,  ~accuracy_assessment_fun(.x, .y)))