Forecast in R - mobile window -

2

I have the following process: yt = 2 + 0.7yt-1 + Et. I want to make pseudo predictions out of the sample, through rolling regressions and with moving window containing 50 observations. The prediction must be performed using the true coefficients: y ^ t + 1 = 2 + 0.7yt and compare with the random walk forecast, that is, y ^ t + 1 = yt. If it was a RA (1) any, compared to a random walk, I can do it like this:

set.seed(1) 
T=100             
e=rnorm(T)
rt(100,5)                      #Para gerar distribuição Student com 10 graus de liberdade                             
mu=2
phi=0.7 
y=matrix(0,T,1)                   
y[1]=mu+e[1]                   
year_start=1
year_end=100
first_date=c(year_start)
final_date=c(year_end)
x=ts(e,start=first_date,frequency=1)  
T=length(x)
R=round(T/2)    

f=ts(0*1:(T-R-1),start=c(year_start+R+1),frequency=1)                  
frw=ts(0*1:(T-R-1),start=c(year_start+R+1),end=final_date,frequency=1)

Rolling Forecast:

ar=1
for (i in 1:length(f)) {
    xt=window(x,start=c(year_start+i),end=c(year_start,R+i))
        xt1=window(x,start=c(year_start+i-1),end=c(year_start,R+i-1))
    for(p in 1:ar){xt1=cbind(xt1,lag(xt,-p))}
    y=na.omit(xt1)
    reg=lm(y[,1]~y[,2])
    cond.x=rev(tail(xt,ar))
    far1[i]=reg$coefficients%*%c(1,cond.x)                  frw[i]=tail(xt,1)               
}
far1    #valores previstos pelo AR(1)   
frw     #valores previstos pelo RW

But I am not able to perform this procedure by incorporating the true coefficients (mu = 2 and phi = 0.7), using for example for (i in 2:R){y[i+1]=mu+phi*y[i]} .

    
asked by anonymous 12.05.2016 / 21:20

0 answers