title: Recursive regression in R
body: <p>Say I have a data frame in R as follows:</p>
  
  <pre><code>&gt; set.seed(1)
  &gt; X &lt;- runif(50, 0, 1)
  &gt; Y &lt;- runif(50, 0, 1)
  &gt; df &lt;- data.frame(X,Y)
  &gt; head(df)
  
            X          Y
  1 0.2655087 0.47761962
  2 0.3721239 0.86120948
  3 0.5728534 0.43809711
  4 0.9082078 0.24479728
  5 0.2016819 0.07067905
  6 0.8983897 0.09946616
  </code></pre>
  
  <p>How do I perform a recursive regression of Y on X, starting at say the first 20 observations and increasing the regression window by one observation at a time until it covers the full sample? </p>
  
  <p>There is a lot of information out there on how to perform a rolling regression of fixed window length (e.g. using <code>rollapply</code> in the <code>zoo</code> package). However, my search efforts have come up in vain when it comes to finding a simple recursive option, where the starting point is instead fixed and the window size increases. An exception is the <code>lm.fit.recursive</code> function from the <code>quantreg</code>package (<a href="http://www.inside-r.org/packages/cran/quantreg/docs/lm.fit.recursive" rel="noreferrer">here</a>). This works perfectly... but for the fact that it doesn't record any information about standard errors, which I need for a constructing recursive confidence intervals.</p>
  
  <p>I can of course use a loop to achieve this. However, my actual data frame is very large and also grouped by id, which causes complications. So I'm hoping to find a more efficient option. Basically, I'm looking for the R equivalent of the "rolling [...], recursive" command in Stata.</p>