我一直在进行一些练习,以获得AR(1)过程的前2个预测点。我希望使用以下三种形式的预测字体:我正在接受这个pdf http://www.le.ac.uk/users/dsgp1/COURSES/BANKERS/BANKERS6.PDF
差分方程形式,移动Aerage形式和Auroregressive形式:
我在前两种表格中做得很好:
library(forecast)
set.seed(20141221)
x <- arima.sim(n=108, list(ar=0.5))
data.ts <- ts(x, start=c(1999,01), freq=12)
time = window(data.ts, start=c(1999,01),end=c(2007,12))
inflarima1 <- arima( x,order = c(1, 0, 0))
inflarima1$coef
# ar1 intercept
#0.4945659 0.2069526
predict(inflarima,2)$pred
#Jan Feb
#2008 0.1147776 0.1613660
第一种形式:差异方程式
# c^= INTERCEPT*(1-phi)
#h=1 -> yt+1 = c^ + phi*Yt
0.2069526*(1-0.4945659) + 0.4945659*x[108]
0.1147776
#h=2 -> yt+1 = c^ + phi*Yt+1 = c^ + phi*[c^ + phi*Yt]= c^+phi*c^+ phi^2*Yt
0.2069526*(1-0.4945659) + 0.2069526*(1-0.4945659)*0.4945659
+ 0.4945659^2*x[108]
0.1613660
第二种形式:移动平均值
#Forecasting h=1;
#Yt+h = mu + phi*et + phi^(2)*et-1 +... + phi^(108)*et-107
#residuals<-inflarima1$residuals
MatrizFIrstForecasting<-matrix(NA,108,1)
for (i in 108:1) {
MatrizFIrstForecasting[i]<-residuals[i]*0.4945659^(108-(i-1) )
}
#Yt+1 = mu + phi*et + phi^2*et-1 + ... + phi^108*et-107
0.2069526 + sum(Matrizphie) #0.1147776
#Forecasting h=2;
#Yt+h = mu + phi^2*et + phi^(3)*et-1 +... + phi^(109)*et-107
MatrizSECONDForecasting<-matrix(NA,108,1)
for (i in 108:1) {
MatrizSECONDForecasting[i]<-residuals[i]*0.4945659^(108-(i-2) )
}
#Yt+2 = mu + phi^2*et + phi^3*et-1 + ... + phi^109*et-107
0.2069526 + sum(MatrizSECONDForecasting) #0.161366
到目前为止它有效......问题是我无法实现第三种形式。我相信我的代码是错误的。
你帮我找错了吗?第三种形式:自回归
Y^_t+1|t = pi_1*yt + pi2*yt-1 + ... + pi_108*yt-107... CORRECT?
PI的系数是这样得到的?
pi_1 = (-phi_1) ; pi_2 = (-phi_1)^2 ; pi_3= (-phi_1)^3; ...;pi_108 = (-phi_1)^108
因此,
我为第一次预测构建了一个代码:
MATRIZpi<-matrix(,108,1)
for (i in 108:1) {
MATRIZpi[i]<-x[108-(108-i)]*(0.4945659)^(108-(i-1))
}
和i求和MATRIZpi矩阵的每一行,得到:
Y^_t+1|t = pi_1*yt + pi2*yt-1 + ... + pi_108*yt-107
sum(MATRIZpi)
The value is 0.2099202
显然这是错的。我已经修改了几次代码而无法修复。
你能给我一些建议吗?