Skip to content

Unable to extract Components from X13_ARIMA_SEATS model #161

@isachng93

Description

@isachng93

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)
  10. │ └─dplyr (local) eval()
  11. ├─fabletools:::map(.fit, components)
  12. │ └─base::lapply(.x, .f, ...)
  13. │ ├─generics (local) FUN(X[[i]], ...)
  14. │ └─fabletools:::components.mdl_ts(X[[i]], ...)
  15. │ ├─generics::components(object$fit, ...)
  16. │ └─feasts:::components.feasts_x13arimaseats(object$fit, ...)
  17. │ └─.data %>% ...
  18. ├─dplyr::mutate(...)
  19. └─dplyr:::mutate.data.frame(...)
  20. └─dplyr:::mutate_cols(.data, dplyr_quosures(...), by)
  21. ├─base::withCallingHandlers(...)
    
  22. └─dplyr:::mutate_col(dots[[i]], data, mask, new_columns)
    
  23.   └─mask$eval_all_mutate(quo)
    
  24.     └─dplyr (local) eval()
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions