[R] Rolling regressions with sample extended one period at a time

R. Michael Weylandt michael.weylandt at gmail.com
Fri Mar 16 22:05:40 CET 2012


You can use predict() just as you would anywhere else:

for(i in 80:100){
    predict(lm(y ~ x, data = dats[1:i, ]), newdata = ???)
}

Michael

On Fri, Mar 16, 2012 at 8:12 AM, pie' <tcpietro at yahoo.it> wrote:
> hey,
>
>
> thanks for the hint. I too figured I'd have to write a for-loop. I have the
> problem now of how to extract the single element of the fitted values
> vector. For example, run 1 of the regression generates 80 fitted values, run
> 2 generates 81 fitted values, run 3 produces 82 fitted values and so on. I
> need to extract the 80th, 81st, 82nd (all the last values generated at every
> run) value into a separate vector. I know that lm (and glm) provides a
> specific function for extracting  the predicted values but I don't know how
> to use it inside a loop. Can you suggest anything?
>
>
> P.
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Rolling-regressions-with-sample-extended-one-period-at-a-time-tp4470316p4478016.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list