Incremental, or on-line, algorithms are increasingly popular as data set sizes explode and web enabled applications create environments where new data arrive continuously (that is, incrementally) from clients out on the internet.

Recently I have been doing some experiments with applying one of the *oldest* incremental algorithms to the task of rating predictions: computing a linear regression with a coefficient of correlation. The incremental formulae look like this:

As you can see from the formulae above, it is sufficient to maintain running sums

and so any new data can be included incrementally - that is, the model can be updated without revisiting any previous data.

Working with these models caused me to wonder if there was a way to generalize them to obtain incremental formulae for a quadratic predictor, or generalized polynomials. As it happens, there is. To show how, I’ll derive an incremental formula for the coefficients of the quadratic predictor:

Recall the matrix formula for polynomial regression:

And so now we can express the formula for our quadratic coefficients in this way:

Note that we now have a matrix formula that is expressed entirely in sums of various terms in x and y, which means that it can be maintained incrementally, as we desired. If you have access to a matrix math package, you might very well declare victory right here, as you can easily construct these matrices and do the matrix arithmetic at will to obtain the model coefficients. However, as an additional step I applied sage to do the symbolic matrix inversion and multiplication to give:

Inspecting the quadratic derivation above, it is now fairly easy to see that the general form of the incremental matrix formula for the coefficients of a degree-m polynomial looks like this:

Having an incremental formula for generalized polynomial regression leaves open the question of how one might generalize the correlation coefficient. There is such a generalization, called the coefficient of multiple determination, which is defined:

But we already have an incremental formula for any pairwise correlation coefficient, which is defined above. And so we can maintain the running sums needed to fill the matrix entries, and compute the coefficient of multiple determination for our polynomial model at any time.

So we now have incremental formulae to maintain any polynomial model in an on-line environment where we either can’t or prefer not to store the data history, and also incrementally evaluate the ‘generalized correlation coefficient’ for that model.

Readers familiar with linear regression may notice that there is also nothing special about polynomial regression, in the sense that powers of x may also be replaced with arbitrary functions of x, and the same regression equations hold. And so we might generalize the incremental matrix formulae further to replace products of powers of x with products of functions of x:

The coefficient of multiple determination generalizes in the analogous way.