Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems with hierarchical modelling/reconciliation in tidyverts

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.
like image 960
Hong Ooi Avatar asked May 23 '20 05:05

Hong Ooi


1 Answers

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).

like image 84
Mitchell O'Hara-Wild Avatar answered Oct 12 '22 23:10

Mitchell O'Hara-Wild