library(dyn) # this also pulls in zoo 
set.seed(1) 
x <- zoo(rnorm(50)) 
y <- 1 + x + rnorm(49) 
# regress y on x 
y.lm.1 <- dyn$lm(y ~ x) 
y.lm.1 
# regress y on x and lag of y. We use update to just add last term to model. 

y.lm.2 <- update(y.lm.1, . ~ . + lag(y, -1)) 

y.lm.2 


anova(y.lm.1, y.lm.2) # difference not significant. Use y.lm.1. 
# regress y on x and its lag and on lags 1 and 2 of y # this shows that in lag(x,k) that k may be a vector y.lm.3 <- dyn$lm(y ~ x + lag(x,-1) + lag(y, -seq(2))) y.lm.3 
