tidyverts / fabletools

General fable features useful for extension packages
http://fabletools.tidyverts.org/
89 stars 31 forks source link

decomposition_model error #288

Closed robjhyndman closed 3 years ago

robjhyndman commented 3 years ago

To replicate this, you will need the latest dev version of the fpp3 package.

library(fpp3)

calls <- bank_calls %>% 
  mutate(t = row_number()) %>%
  update_tsibble(index = t, regular = TRUE) 

calls %>%
  model(
    stl = STL(Calls ~ season(period=169) + season(period=5*169))
  ) %>%
  components() %>%
  autoplot()

my_dcmp_spec <- decomposition_model(
  stl = STL(Calls ~ season(period=169) + season(period=5*169)),
  ETS(season_adjust ~ season("N"))
)

calls %>% 
  model(my_dcmp_spec) %>%
  forecast(h = 5*169) %>%
  autoplot() + xlab("Week")
#> Error in FUN(X[[i]], ...): object 'season_adjust' not found

Created on 2020-11-18 by the reprex package (v0.3.0)

mitchelloharawild commented 3 years ago

Naming the STL decomposition in decomposition_model() passes it to ..., rather than the decomposition specification argument, dcmp:

library(fpp3)
#> ── Attaching packages ────────────────────────────────────────────── fpp3 0.3 ──
#> ✓ tibble      3.0.4          ✓ tsibble     0.9.3.9000
#> ✓ dplyr       1.0.2          ✓ tsibbledata 0.2.0     
#> ✓ tidyr       1.1.2          ✓ feasts      0.1.5.9000
#> ✓ lubridate   1.7.9.2        ✓ fable       0.2.1.9000
#> ✓ ggplot2     3.3.2
#> ── Conflicts ───────────────────────────────────────────────── fpp3_conflicts ──
#> x lubridate::date()   masks base::date()
#> x dplyr::filter()     masks stats::filter()
#> x tsibble::interval() masks lubridate::interval()
#> x dplyr::lag()        masks stats::lag()

calls <- bank_calls %>% 
  mutate(t = row_number()) %>%
  update_tsibble(index = t, regular = TRUE) 

calls %>%
  model(
    stl = STL(Calls ~ season(period=169) + season(period=5*169))
  ) %>%
  components() %>%
  autoplot()
#> Loading required namespace: moment

my_dcmp_spec <- decomposition_model(
  dcmp = STL(Calls ~ season(period=169) + season(period=5*169)),
  ETS(season_adjust ~ season("N"))
)

calls %>% 
  model(my_dcmp_spec) %>%
  forecast(h = 5*169) %>%
  autoplot(tail(calls, 10*169)) + xlab("Week")

Created on 2020-11-18 by the reprex package (v0.3.0)

mitchelloharawild commented 3 years ago

The ETS() model is being used for the decomposition, which does not provide season_adjust (I guess it could provide season_adjust if we wanted it to).

robjhyndman commented 3 years ago

Sorry. Dumb mistake