r - 无法重现华宇所做的预测

标签 r time-series

我想手动检查函数 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

谁能告诉我如何“手动”获得相同的结果?

最佳答案

当然,问得好。基本问题是 R 的作者称为 “截距” 的系数将更准确地识别为 “均值”

这里是您可以手动执行计算的方法

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" 的作者提出的这个主题.

关于r - 无法重现华宇所做的预测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21146734/

相关文章:

java - 为什么 statet eclipse 插件在使用 java 1.7.0 更新环境索引时崩溃?

regex - 如何匹配所有国际化文本?

r - 遇到负面事件时间;考克斯家族不允许

r - 具有多个周期和非负值的时间序列

python - Rolling_mean 在特定时间段内使用 Pandas

machine-learning - 多个观测变量的隐马尔可夫模型

r - 如何替换列值以进行同类群组分析

r - 将数字变量转换为有序因子的最佳方法

r - Prophet模型中假期的不确定性很大

python - 如何结合 LSTM 和 CNN 进行时间序列分类