[R] Rolling window linear regression

Bert Gunter gunter.berton at gene.com
Sat Oct 4 18:15:41 CEST 2014


Use ?loess instead.

-- Bert

Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
Clifford Stoll




On Sat, Oct 4, 2014 at 12:09 AM, Grace Shi <1104271103 at qq.com> wrote:
>
> I have to do roll regression based on the Daily data. I use the past three
> weeks of daily returns as the estimation window and the regression is
> estimated rolling forward one week at a time generating time series
> estimates of beta. I know I should use the rollapply in zoo package. but I
> am not sure how to  do.
>
> data example:
>
>  stock        day             week          y              x
>  "00001"      2009-01-02     2009-01      0.89          2.45
>  "00001"      2009-01-03     2009-01      1.21          1.90
>  "00001"      2009-01-04     2009-01      0.12          0.89
>  "00001"      2009-01-05     2009-01      1.45          2.78
>  "00001"      2009-01-06     2009-01      1.98          0.98
>  "00001"      2009-01-09     2009-02      3.34          1.23
>  "00001"      2009-01-10     2009-02      0.12          0.89
>  "00001"      2009-01-11     2009-02      1.45          2.78
>  "00001"      2009-01-13     2009-02      1.98          0.98
>  "00001"      2009-01-16     2009-03      3.38          0.93
>  "00001"      2009-01-17     2009-03      6.56          3.90
>  "00001"      2009-01-18     2009-03      5.09          3.45
>  "00001"      2009-01-19     2009-03      5.89          3.78
>
>
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> 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