hts 不合格阵列预测

hts non-conformable arrays forecast

大家好我正在尝试使用 hts 包计算分层时间序列的准确度统计数据,但我收到一条错误消息“x - fcasts 错误:不一致的数组”。

library(hts)
abc <- matrix(sample(1:100, 32*140, replace=TRUE), ncol=32)
colnames(abc) <- c(
  paste0("A0",1:5), 
  paste0("B0",1:9),"B10",
  paste0("C0",1:8),
  paste0("D0",1:5),
  paste0("E0",1:4)
)
abc <- ts(abc, start=2019, frequency=365.25/7)
x <- hts(abc, characters = c(1,2))

data <- window(x, start = 2019.000, end = 2021.166)
test <- window(x, start = 2021.185)
fcasts <- forecast(data, h = 20, method = "bu")
accuracy(fcasts, test)
accuracy(fcasts test, levels = 1)

那么报错信息是:

> data <- window(x, start = 2019.000, end = 2021.166)
> test <- window(x, start = 2021.185)
> fcasts <- forecast(data, h = 20, method = "bu")
There were 32 warnings (use warnings() to see them)
> accuracy(fcasts, test)
Error in x - fcasts : non-conformable arrays
> accuracy(fcasts, test, levels = 1)
Error in x - fcasts : non-conformable arrays

谢谢

我认为问题的发生是因为 fcaststest.

的列表对象

试试这个:

accuracy(fcasts$bts, test$bts)
accuracy(fcasts$bts, test$bts, levels = 1)

这是 hts 包中的一个错误,我现在已经在开发版本 (https://github.com/earowang/hts/commit/3f444cf6d6aca23a3a7f2d482df2e33bb078dc55) 中修复了它。

使用CRAN版本,通过使用与测试集长度相同的预测范围(h)避免了这个问题。

accuracy() 中还有另一个由每周数据触发的错误,我也已修复。