Re: [R] How to use "lag"?

From: Gabor Grothendieck <ggrothendieck_at_myway.com>
Date: Sun 06 Mar 2005 - 05:58:50 EST

Remigijus Lapinskas <remigijus.lapinskas <at> maf.vu.lt> writes:

:
: I use the following two function for a lagged regression:
:
: lm.lag=function(y,lag=1) summary(lm(embed(y,lag+1)[,1]~embed(y,lag+1)[,2:
(lag+1)]))
: lm.lag.x=function(y,x,lag=1) summary(lm(embed(y,lag+1)[,1]~embed(x,lag+1)[,2:
(lag+1)]))
:
: for, respectively,
:
: y_t=a+b_1*y_t-1+...+b_lag*y_t-lag
: y_t=a+b_1*x_t-1+...+b_lag*x_t-lag

One could combine these into one function like this:

lm.lag <- function(y, x = y, lag = 1)

   summary( lm( embed(y, lag+1)[,1] ~ embed(x, lag+1)[,-1] ) )



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sun Mar 06 06:12:12 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:41 EST