tidyverts / feasts

Feature Extraction And Statistics for Time Series
https://feasts.tidyverts.org/
291 stars 23 forks source link

Unable to extract Components from X13_ARIMA_SEATS model #161

Open isachng93 opened 10 months ago

isachng93 commented 10 months ago

Dear community / @robjhyndman / @mitchelloharawild

I am attempting to perform seasonal adjustments on a grouped tsibble dataset using X13_ARIMA_SEATS. However, all went well until I attempted to extract the components from the mable.

This error does not occur when I attempt decomposition using STL or X11 The error also does not occur when I filter the mable to extract only a single row.

May I ask if anyone in the community is aware of a remedy to this issue?

Thanks much!

SCRIPT BELOW

Global Functions

singstat_to_tsibble_qtrly <- function(x) {x[["Data"]][["row"]] %>% tidyr::unnest(cols = columns) %>% dplyr::rename(Date = key) %>% dplyr::rename(GroupId = rowText) %>% dplyr::mutate(Date = tsibble::yearquarter(Date)) %>% dplyr::mutate(value = as.numeric(value)) %>% tsibble::tsibble(index = Date, key = GroupId, regular = TRUE) %>% tsibble::group_by_key() %>% dplyr::select(!c(seriesNo, uoM, footnote))}

Crawl Data from Singstat

VApW_Qtr_nonSA_set1_current_TS <- jsonlite::fromJSON("https://tablebuilder.singstat.gov.sg/api/table/tabledata/M015801?limit=2000") %>% singstat_to_tsibble_qtrly() VApW_Qtr_nonSA_set2_current_TS <- jsonlite::fromJSON("https://tablebuilder.singstat.gov.sg/api/table/tabledata/M015801?offset=2000&limit=2000") %>% singstat_to_tsibble_qtrly()

Combine dataset into 1 tsibble

VApW_Qtr_nonSA_current_TS <- dplyr::full_join(VApW_Qtr_nonSA_set1_current_TS, VApW_Qtr_nonSA_set2_current_TS) %>% dplyr::mutate(IndicatorType = "Performance", uoM = "Value-added Per Worker", Terms = "Nominal", AdjStatus = "nonSA", AdjMethod = "O")

fit X13_ARIMA_SEATS model

fit <- VApW_Qtr_nonSA_current_TS %>% fabletools::model(X13 = feasts::X_13ARIMA_SEATS(value ~ seats(), na.action = seasonal::na.x13, defaults = "seasonal"))

Extract Components

fit %>% components()


Error occurs when I attempt to extract components from the X13_ARIMA_SEATS model.

rlang::last_trace() <error/dplyr:::mutate_error> Error in transmute(): ℹ In argument: cmp = map(.fit, components). Caused by error in mutate(): ℹ In argument: seasonal = dcmp[, "adjustfac"]. Caused by error in dcmp[, "adjustfac"]: ! subscript out of bounds

Backtrace: ▆

  1. ├─VApW_Qtr_SA_current_TS_test %>% components()
  2. ├─generics::components(.)
  3. ├─fabletools:::components.mdl_df(.)
  4. │ ├─dplyr::transmute(...)
  5. │ └─dplyr:::transmute.data.frame(...)
  6. │ └─dplyr:::mutate_cols(.data, dots, by)
  7. │ ├─base::withCallingHandlers(...)
  8. │ └─dplyr:::mutate_col(dots[[i]], data, mask, new_columns)
  9. │ └─mask$eval_all_mutate(quo)
    1. │ └─dplyr (local) eval()
    2. ├─fabletools:::map(.fit, components)
    3. │ └─base::lapply(.x, .f, ...)
    4. │ ├─generics (local) FUN(X[[i]], ...)
    5. │ └─fabletools:::components.mdl_ts(X[[i]], ...)
    6. │ ├─generics::components(object$fit, ...)
    7. │ └─feasts:::components.feasts_x13arimaseats(object$fit, ...)
    8. │ └─.data %>% ...
    9. ├─dplyr::mutate(...)
    10. └─dplyr:::mutate.data.frame(...)
    11. └─dplyr:::mutate_cols(.data, dplyr_quosures(...), by)
    12. ├─base::withCallingHandlers(...)
    13. └─dplyr:::mutate_col(dots[[i]], data, mask, new_columns)
    14. └─mask$eval_all_mutate(quo)
    15. └─dplyr (local) eval()

rogerlop commented 1 week ago

Have the same issue. However, seats decomposition did work for most of the series but not for all of them. Has anyone found a way to get over this issue?