1

I have arrays of X and Y. Using Excel I was able to gain certain polynomial fit of orders 3-5. I decided to make a code that will select the lowest order of the fit in the way if GoodnessOfFit.RSquared(New)/GoodnessOfFit.RSquared(Previous)< 1.05 then I stop selecting orders choosing Previous model.

I got surprised that R^2 decreased from order 2 to order 3 (R^2 = 0.35 vs R^2 = 0.21). Checked coefficients and plot data to the same excel file. Was surprised how off the fit line is. Check "RosettaCode" solution for polyfit and also don't see that results are even close to what Excel predicts.

Any solution for the problem?

Example set of data:

double[] Y = new double[] { 0.1599, 0.1585, 0.1499, 0.1506, 0.1494, 0.1494, 0.1494, 0.1494, 0.1619, 0.1619, 0.1604, 0.1604, 0.1479, 0.1479, 0.1604, 0.1738, 0.1623, 0.1553, 0.1431, 0.126, 0.1259, 0.1259, 0.1254, 0.1436 };
double[] X = new double[] { 1495981908, 1495983810, 1495985705, 1495987307, 1495987689, 1495988066, 1495988452, 1495988820, 1495989206, 1495989589, 1495989972, 1495990357, 1495990747, 1495991122, 1495991499, 1495991876, 1495992255, 1495992629, 1495993009, 1495993378, 1495993758, 1495994134, 1495994533, 1495994913 };

1 Answers1

1

Solved. Math.Net calculate coefficients well, however in my case X should be transitioned from UnixTimeStamp to smaller number e.g.:

_Min = X.Min();
_X = new double[X.Length];
for (int i = 0; i < X.Length; i++)
    _X[i] = X[i] - _Min;