[R] Aligning time series

Matthew Johnson mcooganj at gmail.com
Mon May 14 11:09:01 CEST 2012


Sir,

I have large data sets of economic indicators and would like to align
them to a reference series - say the unemployment rate or industrial
production.

Is there a canned routine that returns the optimal lead / lag
according to some (or a variety) of algorithims? not all series will
be of the same length, however i would like to constrain the matching
such that each element in the reference series matches to only one
element in the comparison series.

I do not mind if some data extend forward (in the case of series that
lead the reference series), or back (in the case of laggers or series
that are longer than the reference series).

As a toy example, say my data set is constructed as follows:

Index <- seq(0, 2*pi, length=100)

With the reference series:

S1 <- sin(index)

And the series that i want to align to S1 are:

S2 <- 2(cos(index) + runif(10)/100)
S3 <- 0.5(sin(index +pi/4) + runif(10)/100)
S4 <- sin(index + pi/3) + runif(10)/100
S4[1:25] <- NA

In this case, I am looking for a function that tells me by how many
periods i ought to advance the three series (S2, S3 and S4) to
maximise their relationship with S1 - though it is not always the case
that the reference series will lead.

Thanks and best regards

mj



More information about the R-help mailing list