Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to extract Components from X13_ARIMA_SEATS model #161

Open
isachng93 opened this issue Oct 23, 2023 · 1 comment
Open

Unable to extract Components from X13_ARIMA_SEATS model #161

isachng93 opened this issue Oct 23, 2023 · 1 comment

Comments

@isachng93
Copy link

isachng93 commented Oct 23, 2023

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()
    

@rogerlop
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants