tidyverts / feasts

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

specifying "mode" argument in X_13ARIMA_SEATS using x11() #147

Closed juan-g-p closed 2 years ago

juan-g-p commented 2 years ago

I am trying to get x11 to perform an additive rather than a multiplicative decomposition. The us_retail_employment series in Hyndman's fpp3 (section 3.5) is clearly additive, nonetheless the x11 decomposition performed on the book is multiplicative (below the code of the book)

x11_dcmp <- us_retail_employment %>% model(x11 = X_13ARIMA_SEATS(Employed ~ x11())) %>% components() autoplot(x11_dcmp) + labs(title = "Decomposition of total US retail employment using X-11.")

Checking the manual (https://www2.census.gov/software/x-13arima-seats/x-13-data/documentation/docx13as.pdf), it says that x11 uses by default multiplicative, but that this can be changed to additive specifying mode = add. I have tried this and multiple variations, could you please provide some insight as to how to properly specify the formula?

x11_dcmp <- us_retail_employment %>% model(x11 = X_13ARIMA_SEATS(Employed ~ transform(func = "none"), x11(mode = "add")))

mitchelloharawild commented 2 years ago

Each of the 'specials' in the model should be added to the formula.

So instead of X_13ARIMA_SEATS(Employed ~ transform(func = "none"), x11(mode = "add")), it should be X_13ARIMA_SEATS(Employed ~ transform(func = "none") + x11(mode = "add")). You also need to match the reference manuals argument names exactly, so it should be transform(`function` = "none").

@robjhyndman Do you think the fpp3 should be updated to use an additive decomposition in X11 example?

juan-g-p commented 2 years ago

Thank you for the great and prompt answer, as well as for the great materials you provide.

I was missing the backticks in one of my attempts.

If there is any way to contribute to your project I would be happy to.

mitchelloharawild commented 2 years ago

You're welcome. The backticks are tricky for this, because of course function has special parsing for creating functions in R. However I do think it is important to match the reference manual as close as possible.

More than happy for you to contribute to the package if you would like to. Plenty of work to be done for the function help docs, writing vignettes & package tests. If you're working with X_13ARIMA_SEATS and into coding, adding refit() support would be really nice and hopefully not too challenging to wrap around seasonal::update.seas() (https://github.com/tidyverts/feasts/issues/140)

robjhyndman commented 2 years ago

I think it would be better if the help showed an additive model for X_13ARIMA_SEATS. I'll update the book to state that the default is a multiplicative decomposition. For the example shown, it doesn't make much difference whether an additive or multiplicative decomposition is used, and I'd like to keep the code as simple as possible.