[Rd] lag (PR#491)

Prof Brian D Ripley ripley@stats.ox.ac.uk
Fri, 17 Mar 2000 09:38:18 +0000 (GMT)


On Fri, 17 Mar 2000 kthaka@uta.fi wrote:

> Full_Name: Hannu Kahra
> Version: 1.0.0
> OS: Windows
> Submission from: (NULL) (153.1.50.127)
> 
> 
> x1 <- lag(x, k=1) returns the original series x. The time series is not
> shiftet at all. Only the time is shiftet: for x1 new start = old start -1 
> and new end = old end -1. When I run, e.g. lm(x~x1) the result is not what

So that is _not_ the original series!

> I expect. Both x and x1 are time series. Is this a bug or am I forgetting
> something?

Your description is exactly as documented:

Lag a Time Series

Description:

     Computed a lagged version of a time series, shifting the time base
     back by `k' observations.

[Please read the documentation before submitting a bug report. The FAQ
tells you what a bug is.]

Don't apply regression (a non-time-series technique) to time series, and
expect the implicit conversion to vectors to preserve the time alignment.
Do something like

library(ts)
data(lh)
df <- cbind(x=lh, x1 =lag(lh, 1))
lm(x ~ x1, data=df)

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._