[R] true time series lags behind fitted values in arima model
Benedikt Gehr
benedikt.gehr at ieu.uzh.ch
Fri Oct 29 13:12:31 CEST 2010
Hi
I am fitting an arima model to some time series X. When I was comparing
the fitted values of the model to the true time series I realized that
the true time series lags one time step behind the fitted values of the
arima model. And this is the case for any model. When I did a simple
linear regression using lm to check, I also find the same results, that
the true series lags behind the fitted values. I don't understand this,
what am I doing wrong? Below I copied some of the code to demonstrate
the issue.
## Analysis using arima()
X<-c(6.841067, 6.978443, 6.984755, 7.007225, 7.161198, 7.169790,
7.251534, # the true time series
7.336429, 7.356600, 7.413271, 7.404165, 7.480869, 7.498686, 7.429809,
7.302747, 7.168251, 7.124798, 7.094881, 7.119132, 7.049250, 6.961049,
7.013442, 6.915243, 6.758036, 6.665078, 6.730523, 6.702005, 6.905522,
7.005191, 7.308986)
model100<-arima(X,order=c(1,0,0),include.mean=T,method="ML") # the
arima model
resid100<-residuals(model100)
Xfit100<-X-resid100 # the fitted values
ts.plot(cbind(Xfit100,X),col=c(2,4),main="ARIMA(1,0,0)") # plot the
true ts vs the fitted values
legend(20,7.5,c("true values","fitted
values"),pch=c(16,16),col=c("blue","red"))
## Same analysis using lm()
Y<-X[2:30] # create X(t)-> a time series without the first value
X1<-X[1:29] # create the X(t-1)
time<-seq(1978,2006)
model1<-lm(Y~X1)
summary(model1)
arima.intercept<-model1[[1]][[1]]/(1-model1[[1]][[2]]);arima.intercept
model100[[1]][[2]]
plot(Y~time,type="b") # plot the two series
points(fitted(model1)~time,type="b",col="green")
legend(1995,7.5,c("true values","fitted
values"),pch=c(16,16),col=c("black","green"))
Thank you very much for the help
best wishes
Benedikt
More information about the R-help
mailing list