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)
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')
It seems that forecast uses sum
as aggregation function rather than mean
.
Am I missing something? Any help would be very much appreciated!