title: i am confused with the R implementation of lag in Regression analysis
body: <p>look at this linear regression: Y ~ X + lag(X,1) ,the meaning is very clear that it is trying to do a linear regression. and the lag(X,1) means the first lag of X. What confuse me is the R implementation of lag function. In R the lag(X, 1) moves X to the prior time, for example </p>
  
  <pre><code>&gt;library(zoo) 
  &gt;
  &gt;str(zoo(x))
  ‘zoo’ series from 1 to 4 
  Data: num [1:4] 11 12 13 14
  Index:int [1:4] 1 2 3 4
  &gt;lag(zoo(x))
  1  2  3
  12 13 14
  </code></pre>
  
  <p>when you regress, which value does the R use exactly at time 2? I guess R use the data like this:</p>
  
  <pre><code>time 1   2   3   4
   Y      anything
   X   11  12  13  14
  lagX 12  13  14
  </code></pre>
  
  <p>But this is nonsense！ Because we are supposed to use the fisrt lag of X and the current X at time 2 (or any specific time ), that is 11 and 12 , not 13 12 as above! The fisrt lag of X should be the prior X , isn't it? I am so confused! Please explain to me, thanks a lot.</p>