0
require(dplyr)
require(fable)
require(tsibble)

Build a simple tsibble object

d <- tibble(
   t = c(1:15, 1:15),
   f = rep (letters[1:2] , each = 15),
   x = c(rpois(15, 10), rpois(15, 1)))

d <- as_tsibble(d, index = t, key = f)

Provide the tsibble with an aggregation_key

d <- d %>% aggregate_key(f , x = mean(x))

Check results and it works

autoplot(d)

enter image description here

Split trn and tst

trn <- d %>% filter_index (.~10)
tst <- d %>% filter_index (11~.)

Fit simple average model

fm <- trn %>% model ( mean = MEAN(x))

Reconcile

fm <- fm %>% reconcile( mean = bottom_up(mean))

Forecast

fc <- forecast ( fm, h=5)

Plot Forecast

autoplot(fc, d, level = NULL, color = 'red')

enter image description here

It seems that forecast uses sum as aggregation function rather than mean.

Am I missing something? Any help would be very much appreciated!

phiver
  • 23,048
  • 14
  • 44
  • 56
Andrea
  • 593
  • 2
  • 8
  • `reconcile()` is designed to work with additive hierarchies. The ability to compute non-additive summaries (such as the `mean()`, or `any()`), is useful for computing aggregates of exogenous regressors. – Mitchell O'Hara-Wild May 19 '22 at 12:01

1 Answers1

0

Do you need the bottom-up? Without it it's forecasting the aggregated mean per below:

suppressPackageStartupMessages(library(dplyr))
suppressPackageStartupMessages(library(fable))
suppressPackageStartupMessages(library(tsibble))

d <- tibble(
  t = c(1:15, 1:15),
  f = rep (letters[1:2] , each = 15),
  x = c(rpois(15, 10), rpois(15, 1)))

d <- as_tsibble(d, index = t, key = f)

d <- d %>% aggregate_key(f , x = mean(x))

# autoplot(d)

trn <- d %>% filter_index(.~10)
tst <- d %>% filter_index(11~.)

fm <- trn %>% model(mean = MEAN(x))

# fm <- fm %>% reconcile(mean = bottom_up(mean))

fc <- forecast (fm, h = 5)

autoplot(fc, d, level = NULL, color = 'red')

Created on 2022-05-19 by the reprex package (v2.0.1)

Carl
  • 4,232
  • 2
  • 12
  • 24