Problems with hierarchical modelling/reconciliation in tidyverts
Asked Answered
G

1

8

I'm trying to do hierarchical forecasting after the fashion of Rob Hyndman's Rstudio.conf workshop, and running into some problems. Here is my code:

library(dplyr)
library(tsibbledata)
library(tsibble)
library(fable)

aus_retail_2013_tr <- aus_retail %>%
    filter(Month <= yearmonth("2013 Dec"))
aus_retail_2013_vl <- aus_retail %>%
    filter(Month > yearmonth("2013 Dec"))

hmod <- aus_retail_2013_tr %>%
    aggregate_key(State*Industry, Turnover=sum(Turnover)) %>%
    model(ar=ARIMA(log(Turnover))) %>%
    reconcile(ar_adj=min_trace(ar))

fcasts_hmod <- forecast(hmod, aus_retail_2013_vl)

fcasts_hmod %>%
    filter(is_aggregated(Industry), State == "Victoria") %>%
    autoplot()

The output of the plot is below.

enter image description here

My main problems are:

  • The reconciliation doesn't actually seem to have changed the forecasts at all. The picture indicates that the ar and ar_adj lines are identical.
  • The forecast is only for the time period 2014 to 2015, whereas I know that the full dataset goes to 2018.

How can I fix these? The latter one is probably because not all the time series cover the entire period, but how can I get reconcile to not skip over missing periods?

This is with dplyr 0.8.5, fable 0.2.0, fabletools 0.1.3 and tsibble 0.8.6. I get the same results on both Ubuntu/R 3.6.3 and Windows 10/R 4.0.0.

PS. Trying to forecast for a fixed horizon results in an error:

> fcasts_hmod <- forecast(hmod, h="5 years")
Error: Reconciliation of non-normal forecasts is not yet supported.
Run `rlang::last_error()` to see where the error occurred.
Gravitative answered 23/5, 2020 at 5:41 Comment(3)
Using the dev versions of fable/fabletools/etc now results in an error in the forecast call: Reconciliation of temporal hierarchies is not yet supported.Gravitative
To be honest, the tidyverse dialect reduces my enthusiasm very much. I find it a slog to wade through, although I could presumably figure it out. (I have expressed my reservations about moving to tidy to Rob Hyndman, to no avail.) If you are not wedded to this framework, have you tried base R with the hts package?Ignitron
@StephanKolassa I'm not a tidyverse superfan myself but it gets the job done. I haven't tried with hts as it's been soft-deprecated in favour of the fabletools version, but that may be the only way.Gravitative
T
2

These issues are bugs (or more-so out of scope for the current reconciliation implementation). You can report these via the package's BugReports URL (https://github.com/tidyverts/fabletools/issues).

My main problems are:

The reconciliation doesn't actually seem to have changed the forecasts at all. The picture indicates that the ar and ar_adj lines are identical.

The forecast is only for the time period 2014 to 2015, whereas I know that the full dataset goes to 2018.

The forecasts for the reconciled models should have errored, which is the current behaviour in the development version. Note that your forecast() new_data argument contains 148 time series, but you're producing forecasts from 181 models. This is because the requested forecasts are for bottom level series only (aus_retail_2013_vl has not been aggregated).

PS. Trying to forecast for a fixed horizon results in an error:

Error: Reconciliation of non-normal forecasts is not yet supported.
Run `rlang::last_error()` to see where the error occurred.```

This is because your model has a log transformed response variable, which when backtransformed produces forecasts that have a logNormal distribution. Probabilistic forecast reconciliation is difficult, and is currently only implemented for normal distributions. I will add reconciliation on point forecasts as a fall back (https://github.com/tidyverts/fabletools/issues/216).

Terryn answered 11/6, 2020 at 14:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.