Re: [R] C/C++/Fortran Rolling Window Regressions

2016-08-19 Thread Jason Foster
I looked into why the coefficients differ in Gabor's example and it's because the example mistakenly switched the order of x and y. The syntax is roll::roll_lm(x, y), which is the same as fastLm, but the example accidentally switched them. After correcting the example, the coefficients are all e

Re: [R] C/C++/Fortran Rolling Window Regressions

2016-07-21 Thread Martin Maechler
> jeremiah rounds > on Thu, 21 Jul 2016 13:56:17 -0700 writes: > I appreciate the timing, so much so I changed the code to show the issue. > It is a problem of scale. > roll_lm probably has a heavy start-up cost but otherwise completely > out-performs those other vers

Re: [R] C/C++/Fortran Rolling Window Regressions

2016-07-21 Thread Mark Leeds
Hi Jeremiah: I think I wasn't that clear. I'm not suggesting the kalman filter to deal with time varying coefficients. As Roy pointed out, one can use the kalman filter to do regular regression where one "sees" a new data point as each time unit passes. It can be assumed that the coefficients do n

Re: [R] C/C++/Fortran Rolling Window Regressions

2016-07-21 Thread Jean-Claude Arbaut
This may be useful: Sven Hammarling and Craig Lucas "Updating the QR factorization and the least squares problem" http://eprints.ma.man.ac.uk/1192/01/covered/MIMS_ep2008_111.pdf http://www.maths.manchester.ac.uk/~clucas/updating/ 2016-07-21 20:02 GMT+02:00 jeremiah rounds : > Hi, > > A not unusua

Re: [R] C/C++/Fortran Rolling Window Regressions

2016-07-21 Thread jeremiah rounds
I agree that when appropriate Kalman Filter/Smoothing the higher-quality way to go about estimating a time-varying coefficient (given that is what they do), and I have noted that both the R package "dlm" and the function "StructTS" handle these problems quickly. I am working on that in parallel.

Re: [R] C/C++/Fortran Rolling Window Regressions

2016-07-21 Thread Roy Mendelssohn - NOAA Federal
I have no idea which method produces the fastest results, but the package KFAS has a function to do recursive regressions using the Kalman filter. One difference is that it is not, as far as a I can telll, a moving window (so past data are being dropped), just a recursively computed regressio

Re: [R] C/C++/Fortran Rolling Window Regressions

2016-07-21 Thread Mark Leeds
Hi Jermiah: another possibly faster way would be to use a kalman filtering framework. I forget the details but duncan and horne have a paper which shows how a regression can be re-computed each time a new data point is added .I forget if they handle taking one off of the back also which is what you

Re: [R] C/C++/Fortran Rolling Window Regressions

2016-07-21 Thread jeremiah rounds
I appreciate the timing, so much so I changed the code to show the issue. It is a problem of scale. roll_lm probably has a heavy start-up cost but otherwise completely out-performs those other versions at scale. I suspect you are timing the nearly constant time start-up cost in small data. I

Re: [R] C/C++/Fortran Rolling Window Regressions

2016-07-21 Thread Gabor Grothendieck
I would be careful about making assumptions regarding what is faster. Performance tends to be nonintuitive. When I ran rollapply/lm, rollapply/fastLm and roll_lm on the example you provided rollapply/fastLm was three times faster than roll_lm. Of course this could change with data of different di

Re: [R] C/C++/Fortran Rolling Window Regressions

2016-07-21 Thread jeremiah rounds
Thanks all. roll::roll_lm was essentially what I wanted. I think maybe I would prefer it to have options to return a few more things, but it is the coefficients, and the remaining statistics you might want can be calculated fast enough from there. On Thu, Jul 21, 2016 at 12:36 PM, Achim Zeile

Re: [R] C/C++/Fortran Rolling Window Regressions

2016-07-21 Thread Achim Zeileis
Jeremiah, for this purpose there are the "roll" and "RcppRoll" packages. Both use Rcpp and the former also provides rolling lm models. The latter has a generic interface that let's you define your own function. One thing to pay attention to, though, is the numerical reliability. Especially o

Re: [R] C/C++/Fortran Rolling Window Regressions

2016-07-21 Thread Gabor Grothendieck
Just replacing lm with a faster version would speed it up. Try lm.fit or even faster is fastLm in the RcppArmadillo package. On Thu, Jul 21, 2016 at 2:02 PM, jeremiah rounds wrote: > Hi, > > A not unusual task is performing a multiple regression in a rolling window > on a time-series.A stand

[R] C/C++/Fortran Rolling Window Regressions

2016-07-21 Thread jeremiah rounds
Hi, A not unusual task is performing a multiple regression in a rolling window on a time-series.A standard piece of advice for doing in R is something like the code that follows at the end of the email. I am currently using an "embed" variant of that code and that piece of advice is out there