tsCV()返回的可疑错误很高

时间:2019-04-22 08:48:49

标签: r forecast

我正在使用预测包和fpp2包中的某些数据。

我试图使用tsCV函数在austa时间序列上对ARIMA模型进行交叉验证。 错误之一是可疑的,可能是我可能不了解该功能的工作原理。

library(forecast)
library(fpp2)

data(austa)

farimaboxcox <- function(x, h) {
  lambda <- BoxCox.lambda(x)
  forecast(auto.arima(x, stepwise=FALSE, lambda = lambda), h = h)
}

e <- tsCV(austa, farimaboxcox, h = 5)
e[7:9, 4]
#[1]        NA -366.4481        NA

#Try to replicate the results above

austa_training <- subset(austa, start = 1, end = 7)
austa_test <- subset(austa, start = 8, end = 12)
lambda <- BoxCox.lambda(austa_training)
fit <- forecast(auto.arima(austa_training, stepwise=FALSE, lambda = lambda), h = 5)
e <- austa_test[5] - fit$mean[5]
#[1] NA

austa_training <- subset(austa, start = 1, end = 8)
austa_test <- subset(austa, start = 9, end = 13)
lambda <- BoxCox.lambda(austa_training)
fit <- forecast(auto.arima(austa_training, stepwise=FALSE, lambda = lambda), h = 5)
e <- austa_test[5] - fit$mean[5]
#[1] NA

austa_training <- subset(austa, start = 1, end = 9)
austa_test <- subset(austa, start = 10, end = 14)
lambda <- BoxCox.lambda(austa_training)
fit <- forecast(auto.arima(austa_training, stepwise=FALSE, lambda = lambda), h = 5)
e <- austa_test[5] - fit$mean[5]
#[1] NA

为什么我从tsCV函数中收到-366.4481错误?不应该是NA吗?

0 个答案:

没有答案