tidyverts / fabletools

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

forecast with reconciliation does not work in time series with only one non-zero observation #309

Open bahmanrostamitabar opened 3 years ago

bahmanrostamitabar commented 3 years ago

I am trying to run an experiment where I have time series that contains only one non-zero observation.

Th experiment runs for the following example where I have two non-zero observations:

library(fpp3)
tibble(
  y = c(3,rep(0,198),1),
  key = c(rep("A",100),rep("B",100)),
  t = c(seq(100),seq(100))
) %>%
  as_tsibble(key=key, index=t) %>%
  aggregate_key(key, y=sum(y)) %>%
  model(ets=ETS(y)) %>%
  reconcile(mint = min_trace(ets, method="mint_shrink")) %>% 
  forecast(h=7)

The following example contains a time series with only one non-zero observation, when I run the experiment I get an error:

library(fpp3)
tibble(
  y = c(3,rep(0,198),0),
  key = c(rep("A",100),rep("B",100)),
  t = c(seq(100),seq(100))
) %>%
  as_tsibble(key=key, index=t) %>%
  aggregate_key(key, y=sum(y)) %>%
  model(ets=ETS(y)) %>%
  reconcile(mint = min_trace(ets, method="mint_shrink")) %>% 
  forecast(h=7)
mitchelloharawild commented 3 years ago

The issue here is that the second ("B") ETS model is fitted to a dataset with 0 non-zero observations. As a result, the residuals of this series are 0 and subsequently the MinT shrink weights for this series are invalid. In this case it is most appropriate to use alternative reconciliation weights such as "wls_struct".