我在将arima预测存储到空向量时遇到了一些麻烦。问题是arima预测会给你预测和标准错误。有两列值。我似乎无法将值存储在空向量中。我试图创建两个空向量并将它们绑定在一起,但它没有解决问题。
我的意图是模拟1000次观察。使用前900个观察值进行100次预测。值列表必须更新。例如,使用900个观测值来预测第901次观测值。现在使用901个观测值,包括预测的第901个观测值,来预测第902个观测值。重复,直到您使用999个观察值来预测第1000次观察。我希望弄清楚如何将多个值存储到矢量中。
我希望包含100个预测的空向量称为Predictions1。
# Create Arima Series #
ArimaSeries1 = arima.sim(n=1000, list(ar=c(0.99), ma=c(0.1)))+50
ts.plot(ArimaSeries1)
acf(ArimaSeries1)
ArimaSeries2 = arima.sim(n=1000, list(ar=c(0.7,0.2), ma=c(0.1,0.1)))+50
ts.plot(ArimaSeries2)
acf(ArimaSeries2)
ArimaSeries3 = arima.sim(n=1000, list(ar=c(0.6,0.2,0.1), ma=c(0.1,0.1,0.1)))+50
ts.plot(ArimaSeries3)
acf(ArimaSeries3)
# Estimate Arima Coefficients using maximum likehood #
ARC1 = arima(ArimaSeries1, order = c(1,0,1))
ARC2 = arima(ArimaSeries2, order = c(2,0,2))
ARC3 = arima(ArimaSeries3, order = c(3,0,3))
# Estimate Arima Coefficients with 900 observations #
AR1 = arima(ArimaSeries1[1:900], order = c(1,0,1))
AR2 = arima(ArimaSeries2[1:900], order = c(2,0,2))
AR3 = arima(ArimaSeries3[1:900], order = c(3,0,3))
# Create for-loop to make one prediction ahead for 100 times #
PredictionsA = rep(0,100)
PredictionsB = rep(0,100)
Predictions1 = cbind(PredictionsA,PredictionsB)
for(a in 1:100){ Forcasting1 = predict(arima(ArimaSeries1[1:900+a], order=c(1,0,1)), n.ahead=1)}
Predictions1[a] = Forcasting1
R会给我这个错误信息:
警告消息:在Predictions1 [a] = Forcasting1:项目数 替换不是替换长度的倍数
如果有任何建议,我将不胜感激。关于我哪里出错的任何解释也表示赞赏。谢谢你的时间。
答案 0 :(得分:0)
也许是这样的:
Predictions1 <- array(NA, c(100,2))
for(a in 1:100){
Forcasting1 = predict(arima(ArimaSeries1[1:900+a], order=c(1,0,1)), n.ahead=1)
Predictions1[a,] = unlist(Forcasting1)
}