我正在尝试将外部回归器添加xreg
到hts
包中,但是尽管我的外部变量具有相同的编号,但我收到了关于行数 (140) 的错误。我检查了其他答案,但我的更简单:
这是可重现的示例
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)
x2 <- runif(n = 140, min = 1, max = 10) #External regressor with the same size
fcastsxreg <- forecast( data, h = 2, method = "comb", algorithms = "lu", fmethod = "arima", weights=, "wls", nonnegative=TRUE, xreg=x2)
accuracy(fcastsxreg, test, levels = 1)
错误消息是关于 abc 矩阵的 de 大小与 x2 向量之间的不匹配,尽管两者都有 140 行
Error in model.frame.default(formula = x ~ xregg, drop.unused.levels = TRUE) :
variable lengths differ (found for 'xregg')
In addition: Warning message:
In !is.na(x) & !is.na(rowSums(xregg)) :
longer object length is not a multiple of shorter object length
谢谢