[R] Time series misalignment

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Wed Apr 13 00:59:31 CEST 2005


On Tue, 12 Apr 2005 18:47:21 -0400 Fernando Saldanha wrote:

> Can one also predetermine a set and then estimate all the models one
> wants to compare using the zoo package?

Sure, you can merge() several series first and then pass this as the
data argument to lm(). See the vignette of the zoo package for more
examples.

> Or can that be done only with the tseries package?

Really, you are *not* using the tseries package here!

(In the old days, the class "ts" and its methods used to be in the
package ts, but this was merged into stats long ago. tseries is an
entirely different package.)
Z

> Thanks.
> 
> FS 
> 
> On 4/12/05, Achim Zeileis <Achim.Zeileis at wu-wien.ac.at> wrote:
> > Fernando:
> > 
> > > This maybe a basic question, but I have spent several hours
> > > researching and I could not get an answer, so please bear with me.
> > > The problem is with time series in the package tseries.
> > 
> > BTW: the `tseries' package is not involved here.
> > 
> > > As the example
> > > below shows, the time series can get misaligned, so that bad
> > > results are obtained when doing regressions.
> > 
> > lm() per se has only very limited support for time series
> > regression. Therefore, there are currently several tools under
> > development for addressing this issue. In particular, Gabor
> > Grothendieck and myself are working on different approaches to this
> > problem.
> > 
> > <snip>
> > 
> > > To fix this problem I did the following:
> > >
> > > > tsf <- ts.intersect(y1, x1, z1)
> > >
> > > Now I can do:
> > >
> > > > lm1 <- lm(tsf[,3] ~ tsf[,2])
> > 
> > It is probably simpler to just do
> >   lm1 <- lm(z1 ~ x1, data = tsf)
> > 
> > Another approach is implemented in the zoo package. This implements
> > an formula dispatch and you can do
> >   lm1 <- lm(I(z1 ~ x1))
> > *without* computing tsf first.
> > 
> > Depending on what you want to do with the fitted models, one of the
> > two approaches might be easier, currently. In particular, if you
> > want to fit and compare several models, then I would compute the
> > intersection first and fit all models of interest on this data set.
> > 
> > Furthermore, note that the dispatch implementation via I() in zoo is
> > still under development and likely to change in future versions.
> > (But this mainly means that improved implementations will become
> > available soon, stay tuned :-)
> > Z
> > 
> >
>




More information about the R-help mailing list