How to make pseudo predictions out of the sample, through rolling regressions and with moving window containing 50 observations, for t = 51 to 100? One of the forecasts should be made from an AR (1). Another will be made from a random walk, that is, yt + 1 (estimated) = yt. Finally, another forecast will be made using the true coefficients: yt + 1 (estimated) = 2 + 0.7yt. Store the forecasts of each model in arrays (or vectors). Estimate the AR (1) through MQO (lm (y ~ x)).
A prediction for the model with the true coefficients would be as follows, (With mu = 2 and phi = 0.7, previously defined):
for (i in 1:R){
y[i+1]=mu+phi*y[i]
}
reg=lm(y[i+1]~y[i])
But I can not figure out how to incorporate this model into the actual coefficients when rolling forecast, since it regresses the forecast windows (xt and xt1).
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))
f[i]=reg$coefficients%*%c(1,cond.x)
frw[i]=tail(xt,1)
}
I tried to include the true template loop within the rolling forecast loop, but it is not coming out. I was able to do with an AR (1) any, but not incorporating the true coefficients. Would anyone have a hint?