[R] time series analysis with covariates

Daniel Malter daniel at umd.edu
Sun Nov 25 05:10:57 CET 2007


Hi, I am trying to analyze a time series with covariates. Since I have
basically no prior experience with time series modeling, I followed a
procedure suggested by Wooldridge, but I slightly changed the procedure and
wanted to ask whether it is sound or flawed in your opinion.

Wooldridge suggests fitting a time trend to the dependent variable and then
regressing the residuals on both a time trend and the explanatory variables.
Therefore, I did the following:

- I regressed the dependent variable on a time trend using gam().

reg=gam(dependent~s(time))

- Then I inspected and analyzed the residuals of the gam()-fit for
autocorrelation (with acf-plots and the ar() function). This suggested an
autocorrelation of 4 lags of the residuals even after fitting the time trend
(indicating a second-order time trend).

ar(reg$res)
acf(reg$res,type="partial",lag=20)

- Then I extracted for each time period the lagged residuals for t-1, t-2,
t-3, and t-4 (L1res, L2res, L3res, L4res).

- Finally, I ran a gam() on both the residuals of the gam()-fit and the
dependent variable, including a time trend and the lagged residuals
t-1...t-4 from the gam()-fit. The regression on the residuals basically
implies doubly fitting the time trend (as suggested by Wooldridge) whereas
the regression of the dependent variable only implies fitting the time trend
in the final regression only, but still using the lagged residuals of the
first regression. Again, in both regressions I use the lagged residuals from
the initial time trend fit. The results of the two regressions are almost
identical, but the 

reg2=gam(reg$res~s(time)+L1res+L2res+L3res+L4res+independents)
reg3=gam(dependent~s(time)+L1res+L2res+L3res+L4res+independents)

Is it sound to fit a time series model with covariates in this way? Is it
sound to use the 4 period lagged residuals in the later regressions? If not,
could you please point me to the package and functions that I can to this
with.

Thanks so much,
Daniel



More information about the R-help mailing list