I am working on a project in Java that involves fitting a simple linear regression line through a rolling / sliding window of n data points. For each new point added the linear regression slope and intercept need to be re-calculated. We currently use org.apache.commons.math3.stat.regression.SimpleRegression
to do this calculation, but it is expensive to re-calculate the entire window each time.
So I have two questions.
- The
SimpleRegression
offered by apache commons has a removeData method for use in a "streaming mode". (See quotation below taken from API). However there is no other information on this "streaming mode"; proper implementation,accumulative error, etc... Does anyone have an example of how to use it properly in streaming mode? or can anyone point me to a better source of information?
"This method permits the use of SimpleRegression instances in streaming mode where the regression is applied to a sliding "window" of observations, however the caller is responsible for maintaining the set of observations in the window. "
- Are there any other libraries available that can do streaming linear regression in constant time? Surely Apache Commons SimpleRegression is not the only one... but that seems to be the only one I can find...
Thanks, g