# Why Linear regression using Numworks calculator doest give exact result

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

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]


• it's just how floating point arithmetic works, unfortunately Commented Aug 11, 2023 at 3:40
• I understand that because of float calculation dont have perfect precision. But other calculator seem to get the perfect answer. Commented Aug 11, 2023 at 7:20

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.