我想手动检查函数arima
所做的预测,并得到不同的结果。以下是一个简单的AR(1) - 示例:
set.seed(123)
D<-rnorm(7)
> D
[1] -0.56047565 -0.23017749 1.55870831 0.07050839 0.12928774 1.71506499 0.46091621
M<-arima(D,order=c(1,0,0))
predict(M)
> predict(M)$pred[1]
[1] 0.4748763
# So, the one-step-ahead prediction is: 0.4748763
# I tried to calculate this manually using the intercept:M$coef[2] and the slope multiplied with the last observation: M$coef[1]*( 0.46091621)
M$coef[2]+M$coef[1]*( 0.46091621)
0.3863168
# As can be seen, the result now is: 0.3863168
有人可以告诉我如何“手动”获得相同的结果吗?
答案 0 :(得分:1)
当然,好问题。基本问题是R的作者称之为"intercept"
的系数将更准确地标识为"mean"
。
以下是您可以手动执行计算的方法
b <- coef(M)
b[[2]] + b[[1]]*(D[7] - b[[2]])
# [1] 0.4748763
here is a nice discussion的作者对此主题的和"Time Series Analysis and Its Applications: With R Examples"。