i would like to construct the following model in R
Yt = A+B*Xt+Nt
where Xt is time and B is the trend coefficient and Nt = φNt-1+et φ
first order auto-correlation of the residuals and et white noise.
I have tried to use the gls function as follow
fm <- gls(Y~1+T,correlation=corAR1(value=acf(Y,na.action=na.pass)$acf[2],form=~1),na.action=na.omit)
but i am not totally sure if it models the residuals the way i would like.
Furthermore, i would like to get in my results the time series of the Nt and et, so as to calculate the variance of Nt (σΝ). I would appreciate any help. Thank you
Use resid to get what you want. The complete code
et=rnorm(100)
tt=1:length(et)
Nt=et[1]
for (i in 2:length(et))Nt[i]=0.6*Nt[i-1]+et[i]
Yt=100+3*tt+Nt
fm <- gls(Yt~1+tt,correlation=corAR1(value=acf(Yt,na.action=na.pass)$acf[2],form=~1),na.action=na.omit)
summary(fm)
res=resid(fm)
plot(ts(res))
lines(ts(Nt),col=3)
acf(resid(fm))
acf(Nt)