[R] How to use "lag"?
    Gabor Grothendieck 
    ggrothendieck at myway.com
       
    Sat Mar  5 19:58:50 CET 2005
    
    
  
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] ) )
    
    
More information about the R-help
mailing list