[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