-
Notifications
You must be signed in to change notification settings - Fork 34
Reconciling error #267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Fixed, thanks. Issue was sparse matrix structure being dropped to numeric when the hierarchy contains only a single leaf node. |
Regarding https://stackoverflow.com/q/64012331/144157 from a code standpoint, the latest version of fabletools supports unbalanced hierarchies, which allows them to fix their variance issue by removing the redundant aggregations. For now this is done with Your probably better suited to answering the change in variance, so I'll leave answering that to you. Code for unbalanced hierarchies to follow. |
Here's an unbalanced hierarchy for this example. You can take any nodes out of the hierarchy so long as it doesn't produce a disjoint hierarchy (until #106 is done), and the appropriate S matrix will be computed. library(fpp3)
#> ── Attaching packages ────────────────────────────────────────────────────────────────────────────── fpp3 0.3 ──
#> ✓ tibble 3.0.3 ✓ tsibble 0.9.2.9000
#> ✓ dplyr 1.0.2 ✓ tsibbledata 0.2.0
#> ✓ tidyr 1.1.2 ✓ feasts 0.1.5
#> ✓ lubridate 1.7.9 ✓ fable 0.2.1.9000
#> ✓ ggplot2 3.3.2
#> ── Conflicts ───────────────────────────────────────────────────────────────────────────────── fpp3_conflicts ──
#> x lubridate::date() masks base::date()
#> x dplyr::filter() masks stats::filter()
#> x tsibble::interval() masks lubridate::interval()
#> x dplyr::lag() masks stats::lag()
B1 <- rnorm(12, mean = 5) + (1:12)
B2 <- rnorm(12, mean = 5)
M2 <- rnorm(12, mean = 25)
ts_data <- tibble(value = c(B1, B2, M2),
month = rep(yearmonth(paste("2020", 1:12, sep="-")), 3),
B = c(rep("B1", 12), rep("B2", 12), rep("B3", 12)),
M = c(rep("M1", 24), rep("M2", 12))) %>%
as_tsibble(key = c("B", "M"), index = month)
ts_data %>%
# Specify hierarchy
aggregate_key(M / B, value = sum(value)) %>%
# Remove redundant nodes from hierarchy (#226)
filter(!(B == "B3")) %>%
# Fit models
model(arima = ARIMA(value)) %>%
# Set up reconciliation
mutate(mint = min_trace(arima)) %>%
# Produce the forecasts
forecast(h = 1)
#> # A fable: 10 x 6 [1M]
#> # Key: M, B, .model [10]
#> M B .model month value .mean
#> <chr> <chr> <chr> <mth> <dist> <dbl>
#> 1 M1 B1 arima 2021 Jan N(19, 1.9) 18.5
#> 2 M1 B1 mint 2021 Jan N(18, 1.2) 17.6
#> 3 M1 B2 arima 2021 Jan N(4.9, 1) 4.86
#> 4 M1 B2 mint 2021 Jan N(4.3, 0.81) 4.26
#> 5 M1 <aggregated> arima 2021 Jan N(20, 3.6) 20.4
#> 6 M1 <aggregated> mint 2021 Jan N(22, 1.2) 21.9
#> 7 M2 <aggregated> arima 2021 Jan N(25, 0.62) 24.8
#> 8 M2 <aggregated> mint 2021 Jan N(25, 0.56) 24.7
#> 9 <aggregated> <aggregated> arima 2021 Jan N(46, 4) 45.8
#> 10 <aggregated> <aggregated> mint 2021 Jan N(47, 1.4) 46.6 Created on 2020-09-23 by the reprex package (v0.3.0) |
Trying to replicate https://stackoverflow.com/q/64012331/144157 created a different problem from that reported:
Created on 2020-09-23 by the reprex package (v0.3.0)
Session info
The text was updated successfully, but these errors were encountered: