0

I'm new to time series work. I'm going back and forth between the fable and modeltime family of packages. One feature that is easy to get from fable is the fitted values so you can see how the model fitted visually. I have found several question/answers on stackoverflow, in package documentation, etc. about extracting residuals when working with modeltime, but I haven't seen a way and can't figure out how to extract residuals and specifically the model fitted values when working with nested data of many time series.

Here are the basic chunks of my code (starting at modeling):

nested_modeltime_tbl <- nested_data_tbl_extended %>%
    modeltime_nested_fit(
         wflw_ets
        ,wflw_prophet_additive_linear
        ,wflw_prophet_multiplicative_linear
        ,wflw_prophetxgb1
        ,wflw_prophetxgb2
        ,wflw_autoarima
        ,wflw_arimaxgb1
        ,wflw_arimaxgb2
        ,wflw_ets_stlm
        ,wflw_arima_stlm
        ,wflw_autoadam
        ,wflw_tbats
        ,wflw_nnetar
        ,wflw_rf
        ,conf_interval = c(0.95)
        ,metric_set = default_forecast_accuracy_metric_set()
        ,control = control_nested_fit(allow_par = TRUE, verbose = FALSE)
    )
accuracy <- nested_modeltime_tbl %>%
  extract_nested_test_accuracy() 
best_models <- nested_modeltime_tbl %>%
  collect() %>%
  modeltime_nested_select_best(metric = "rmse",
                              minimize = TRUE,
                              filter_test_forecasts = TRUE)
best_models2 <- best_models %>% extract_nested_best_model_report() 
forecasts <- best_models2 %>%
  extract_nested_test_forecast()
nested_modeltime_refit_tbl <- best_models %>%
     modeltime_nested_refit(
        control = control_nested_refit(allow_par = TRUE, verbose = FALSE))
nested_modeltime_future_forecast <- nested_modeltime_refit_tbl %>%
  extract_nested_future_forecast(.include_actual= TRUE) 

I've tried several functions like: modeltime_calibrate modeltime_residuals

I've also dug into the objects where I can find the calibration data, but it is only for test data and while it includes the residuals, it doesn't include the .fitted values (I'm looking for fitted as noted on page 48 of https://cran.r-project.org/web/packages/modeltime/modeltime.pdf). For example,

best_models$.modeltime_tables[[1]]$.calibration_data & nested_modeltime_refit_tbl$.modeltime_tables[[1]]$.calibration_data

Any help appreciated.

Thank you,

Brian

Brian Head
  • 57
  • 4

0 Answers0