FoReco-thief: Simple examples to compare 'FoReco' and 'thief' packages

Description References Examples

Description

The dataset in the thief package is used to show how to get the same results with the FoReco package. In particular, we take the weekly data of Accident and Emergency demand in the UK, AEdemand, from 1 January 2011 to 31 December 2014.

References

Hyndman, R. J., Kourentzes, N. (2018), thief: Temporal HIErarchical Forecasting, R package version 0.3, https://cran.r-project.org/package=thief.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
## Not run: 
library(thief)
require(FoReco)
dataset <- window(AEdemand[, 12], start = c(2011, 1), end = c(2014, 52))
data <- tsaggregates(dataset)
# Base forecasts
base <- list()
for (i in 1:5) {
  base[[i]] <- forecast(auto.arima(data[[i]]))
}
base[[6]] <- forecast(auto.arima(data[[6]]), h = 2)
# Base forecasts vector
base_vec <- NULL
for (i in 6:1) {
  base_vec <- c(base_vec, base[[i]]$mean)
}
# Residual vector
res <- NULL
for (i in 6:1) {
  res <- c(res, base[[i]]$residuals)
}

# OLS
# two commands in thief...
obj_thief <- thief(dataset, m = 52, h = 2 * 52, comb = "ols", usemodel = "arima")
obj_thief <- tsaggregates(obj_thief$mean)
y_thief <- NULL
for (i in 6:1) {
  y_thief <- c(y_thief, obj_thief[[i]])
}
obj_thief_ols <- reconcilethief(base, comb="ols")
y_thief_ols <- NULL
for (i in 6:1) {
  y_thief_ols <- c(y_thief_ols, obj_thief_ols[[i]]$mean)
}
# ...with the same results:
sum(abs(y_thief_ols - y_thief) > 1e-10)

y_FoReco_ols <- thfrec(base_vec, 52, comb = "ols")$recf
sum(abs(y_FoReco_ols - y_thief_ols) > 1e-10)

# STRUC
obj_thief_struc <- reconcilethief(base, comb="struc")
y_thief_struc <- NULL
for (i in 6:1) {
  y_thief_struc <- c(y_thief_struc, obj_thief_struc[[i]]$mean)
}
y_FoReco_struc <- thfrec(base_vec, 52, comb = "struc")$recf
sum(abs(y_FoReco_struc - y_thief_struc) > 1e-10)

# BU
obj_thief_bu <- reconcilethief(base, comb="bu")
y_thief_bu <- NULL
for (i in 6:1) {
  y_thief_bu <- c(y_thief_bu, obj_thief_bu[[i]]$mean)
}
y_FoReco_bu <- thfrec(base_vec, 52, comb = "bu")$recf
sum(abs(y_FoReco_bu - y_thief_bu) > 1e-10)

# SHR
obj_thief_shr <- reconcilethief(base, comb="shr")
y_thief_shr <- NULL
for (i in 6:1) {
  y_thief_shr <- c(y_thief_shr, obj_thief_shr[[i]]$mean)
}
y_FoReco_shr <- thfrec(base_vec, 52, comb = "shr", res = res)$recf
sum(abs(y_FoReco_shr - y_thief_shr) > 1e-10)

## End(Not run)

FoReco documentation built on July 23, 2021, 5:06 p.m.