[R語言]forecast.Arima中使用xreg報錯


問題:

使用forecast.Arima對帶xreg的arima模型進行預測,報xreg Error

1 pre.m4x <- forecast.Arima(m4x, h = 20, xreg = seq(429,448,by = 1))

報錯:

Error in if (ncol(xreg) != ncol(object$call$xreg)) stop("Number of regressors does not match fitted model") : 
  argument is of length zero

原因:

R語言的基礎包stats中包含arima函數,擬合模型時,使用的是stats包中的arima函數。

應該是forecast包對stats中的arima函數支持不夠,所以使用forecast包進行預測會報錯。

正確的做法:

使用Arima函數擬合模型。

Arima()是forecast包中的函數,生成的帶xreg的模型能夠使用forecast.Arima函數進行預測。

 

參考:http://stackoverflow.com/questions/20086487/error-with-forecast-arima-with-xreg


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM