rollapply

the rolling regression in R using roll apply

拥有回忆 提交于 2019-11-30 03:28:26
问题 My imported data contains 7 variables: Y and X1 , X2 , X3 , X4 , X5 , X6 . I tried applying the rollapply function in zoo in order to run a rolling regression within an in-sample with a window of 262 obs. (work days in a year). date Y X1 X2 1 10/1/07 -0.0080321720 4.690734e-03 3.333770e-03 2 10/2/07 0.0000000000 -2.818413e-03 5.418223e-03 3 10/3/07 0.0023158650 -4.178744e-03 -3.821100e-04 4 10/4/07 -0.0057491710 -5.071030e-03 -8.321550e-04 5 10/5/07 0.0073570500 3.065045e-03 5.179574e-03 6 10

sum over past window-size dates per group

▼魔方 西西 提交于 2019-11-29 15:41:13
The problem is similar to How do I do a conditional sum which only looks between certain date criteria but slightly different and the answer from that does not fit into current problem. The main difference is that the date column based on each group may not necessarily be complete (i.e., certain date may be missing) Input: input <- read.table(text=" 2017-04-01 A 1 2017-04-02 B 2 2017-04-02 B 2 2017-04-02 C 2 2017-04-02 A 2 2017-04-03 C 3 2017-04-04 A 4 2017-04-05 B 5 2017-04-06 C 6 2017-04-07 A 7 2017-04-08 B 8 2017-04-09 C 9") colnames(input) <- c("Date","Group","Score") Rule: for each group

sum over past window-size dates per group

偶尔善良 提交于 2019-11-28 09:45:10
问题 The problem is similar to How do I do a conditional sum which only looks between certain date criteria but slightly different and the answer from that does not fit into current problem. The main difference is that the date column based on each group may not necessarily be complete (i.e., certain date may be missing) Input: input <- read.table(text=" 2017-04-01 A 1 2017-04-02 B 2 2017-04-02 B 2 2017-04-02 C 2 2017-04-02 A 2 2017-04-03 C 3 2017-04-04 A 4 2017-04-05 B 5 2017-04-06 C 6 2017-04-07

Adaptive moving average - top performance in R

拥有回忆 提交于 2019-11-26 05:24:48
问题 I am looking for some performance gains in terms of rolling/sliding window functions in R. It is quite common task which can be used in any ordered observations data set. I would like to share some of my findings, maybe somebody would be able to provide feedback to make it even faster. Important note is that I focus on the case align=\"right\" and adaptive rolling window, so width is a vector (same length as our observation vector). In case if we have width as scalar there are already very