我正在研究一个分层预测项目,我想在R中使用Fable使用中间出方法,以便在中间级别创建预测并使用预测比例向下分配它,然后简单地向上聚合。
但是,每当我尝试使用超过 2 个级别的层次结构时,都会遇到此错误:
Error: Problem with `mutate()` column `mo_ets`.
i `mo_ets = (function (object, ...) ...`.
x subscript out of bounds
我可以恢复为使用不超过 2 个层次结构级别,但这等于自上而下的方法,我想使用 Fable 中的一些功能,要求所有级别都到位。
我可以毫无问题地运行以下代码:
library(fpp3)
tourism <- tsibble::tourism %>%
mutate(State = recode(State,
`New South Wales` = "NSW",
`Northern Territory` = "NT",
`Queensland` = "QLD",
`South Australia` = "SA",
`Tasmania` = "TAS",
`Victoria` = "VIC",
`Western Australia` = "WA"
)) %>%
aggregate_key(State / Region, Trips = sum(Trips)) %>%
model(ets=ETS(Trips)) %>%
reconcile(mo_ets = middle_out(ets),
method = "forecast_proportions",
level=State) %>%
forecast(h=3)
但是添加第三个顶层,并从中间状态级别进行预测,分解到 Region 并聚合到NewCol,然后我得到上述错误:
library(fpp3)
tourism <- tsibble::tourism %>%
mutate(State = recode(State,
`New South Wales` = "NSW",
`Northern Territory` = "NT",
`Queensland` = "QLD",
`South Australia` = "SA",
`Tasmania` = "TAS",
`Victoria` = "VIC",
`Western Australia` = "WA"
)) %>%
mutate(NewCol = paste(State,"ABC",sep="")) %>%
aggregate_key(NewCol / State / Region, Trips = sum(Trips)) %>%
model(ets=ETS(Trips)) %>%
reconcile(mo_ets = middle_out(ets),
method = "forecast_proportions",
level=State) %>%
forecast(h=3)
有什么办法可以解决这个问题以便真正使用middle_out方法而不是top_down?