tidyverts / feasts

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

X_13ARIMA_SEATS() when specifying seats #130

Closed EconProf closed 3 years ago

EconProf commented 3 years ago

I followed the example in Section 3.5 of fpp3 to specify seats as a special, but using aus_production data for beer instead of us_retail_employment. It did not remove the seasonality (QS is very high) and reports that it was not a decomposition. Leaving out the seas special it worked, but with a note I do not understand.

library(fpp3)      

fitseats <- aus_production %>%
  model(X_13ARIMA_SEATS(Beer ~ seats()))   
report(fitseats)
#> Series: Beer 
#> Model: X-13ARIMA-SEATS 
#> 
#> Coefficients:
#>                   Estimate Std. Error z value Pr(>|z|)    
#> MA-Nonseasonal-01  0.96503    0.06307  15.301  < 2e-16 ***
#> MA-Nonseasonal-02 -0.34106    0.06362  -5.361 8.26e-08 ***
#> MA-Seasonal-04     0.77186    0.04380  17.621  < 2e-16 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> SEATS adj.  ARIMA: (0 1 2)(0 1 1)  Obs.: 0  Transform: log
#> AICc:  1748, BIC:  1761  QS (no seasonality in final):157.3 ***
#> Box-Ljung (no autocorr.): 16.09   Shapiro (normality): 0.994
components(fitseats)
#> Error: Problem with `mutate()` input `cmp`.
#> x The X-13ARIMA-SEATS model does not contain a decomposition, are you missing a seasonal component?
#> ℹ Input `cmp` is `map(.fit, components)`.

fit <- aus_production %>% 
  model(X_13ARIMA_SEATS(Beer))   
report(fit)
#> Series: Beer 
#> Model: X-13ARIMA-SEATS 
#> 
#> Coefficients:
#>                   Estimate Std. Error z value Pr(>|z|)    
#> MA-Nonseasonal-01  0.96503    0.06307  15.301  < 2e-16 ***
#> MA-Nonseasonal-02 -0.34106    0.06362  -5.361 8.26e-08 ***
#> MA-Seasonal-04     0.77186    0.04380  17.621  < 2e-16 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> SEATS adj.  ARIMA: (0 1 2)(0 1 1)  Obs.: 218  Transform: log
#> AICc:  1748, BIC:  1761  QS (no seasonality in final):    0  
#> Box-Ljung (no autocorr.): 16.09   Shapiro (normality): 0.994  
#> Messages generated by X-13:
#> Notes:
#> - Model used for SEATS decomposition is different from the model
#>   estimated in the regARIMA modeling module of X-13ARIMA-SEATS.
components(fit)
#> # A dable: 218 x 7 [1Q]
#> # Key:     .model [1]
#> # :        Beer = f(trend, seasonal, irregular)
#>    .model                Quarter  Beer trend seasonal irregular season_adjust
#>    <chr>                   <qtr> <dbl> <dbl>    <dbl>     <dbl>         <dbl>
#>  1 X_13ARIMA_SEATS(Beer) 1956 Q1   284  255.    1.05      1.06           271.
#>  2 X_13ARIMA_SEATS(Beer) 1956 Q2   213  255.    0.860     0.970          248.
#>  3 X_13ARIMA_SEATS(Beer) 1956 Q3   227  256.    0.912     0.973          249.
#>  4 X_13ARIMA_SEATS(Beer) 1956 Q4   308  257.    1.19      1.01           258.
#>  5 X_13ARIMA_SEATS(Beer) 1957 Q1   262  258.    1.04      0.976          251.
#>  6 X_13ARIMA_SEATS(Beer) 1957 Q2   228  259.    0.863     1.02           264.
#>  7 X_13ARIMA_SEATS(Beer) 1957 Q3   236  260.    0.915     0.992          258.
#>  8 X_13ARIMA_SEATS(Beer) 1957 Q4   320  261.    1.19      1.03           268.
#>  9 X_13ARIMA_SEATS(Beer) 1958 Q1   272  262.    1.04      1.00           262.
#> 10 X_13ARIMA_SEATS(Beer) 1958 Q2   233  262.    0.864     1.03           270.
#> # … with 208 more rows

Created on 2021-03-25 by the reprex package (v1.0.0)

mitchelloharawild commented 3 years ago

That's odd, I had thought that specifying X_13ARIMA_SEATS(y~seats()) would give the same results as X_13ARIMA_SEATS(y), as seats() is the default. Investigating.

mitchelloharawild commented 3 years ago

Looks like specifying seats = "" overwrites the seats.noadmiss = "yes" default option.

library(seasonal)
library(tsibble)
#> 
#> Attaching package: 'tsibble'
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, union
library(magrittr)
as.ts(tsibbledata::aus_production)[,"Beer"] %>% 
  seas(seats = "") %>% 
  final()
#> Error: X-13 run failed
#> 
#> Errors:
#> - Available options for noadmiss are yes or no.
#> 
#> Notes:
#> - Correct input errors in the order they are detected since the
#>   first one or two may be responsible for the others (especially
#>   if there are errors in the SERIES or COMPOSITE spec).

Created on 2021-03-26 by the reprex package (v1.0.0)

mitchelloharawild commented 3 years ago

Oh, it actually is partial argument matching seats="" to seats.noadmiss="" in the above reprex. :vomiting_face:

mitchelloharawild commented 3 years ago

Fixed, thanks as always. I think this is more of a bug in the {seasonal} package, but it can be fixed in {feasts}.

The issue was that the default seas.noadmiss= "yes" argument was dropped when list = list(seas = "") is provided to seasonal::seas(). If we also pass seas.noadmiss into the list(), it works without issue.