Why Linear regression using Numworks calculator doest give exact result

60 Views Asked by At

I tried to do a simple linear regression using the "Numworks" calculator and unless I add many more data points or add a point where x=0 it doesn't give me the correct equation.

Could someone explain why is the equation

y = 2*x -1.776356839e-15

instead of

y = 2*x + 0

Is it because of the linear regression algorithm they use.

If this is the case shouldn't it still work for such a simple equation ?

I found the c++ code the calculator is using for linear model https://github.com/numworks/epsilon/blob/master/apps/shared/linear_regression_store.cpp#L87

The code seem to do the following steps:

x = {1, 2, 3}
y = {2, 4, 6}
slope = Covariance[x, y]  / Variance[x]
intercept = Mean[y] - slope * Mean[x]

enter image description here enter image description here

1

There are 1 best solutions below

2
On

That term, 1.776356839e-15, is almost exactly $2^{-49}$. This suggests roundoff error.

If you can look at the statistics for the regression calculation ($\sum x, \sum y, \sum xy$), and compare the results to the exact result, perhaps you can see where the roundoff occurs.