mathnet / mathnet-numerics

Math.NET Numerics
http://numerics.mathdotnet.com
MIT License
3.5k stars 896 forks source link

Does the class library have the same calculation method as Excel's steyx () method #673

Open KobeJamse opened 4 years ago

diluculo commented 4 years ago

From this, the STEYX function is equivalent to the root mean square of the error (RMSE) of linear regression.

var x = new double[] { 6, 5, 11, 7, 5, 4, 4 }; // example data of the link
var y = new double[] { 2, 3, 9, 1, 8, 7, 5 };

var offsetAndSlope = MathNet.Numerics.LinearRegression.SimpleRegression.Fit(x, y);
var offset = offsetAndSlope.Item1; // 3.16667
var slope = offsetAndSlope.Item2; // 0.30556

var yBest = x.Select(p => offset + p * slope).ToArray(); // Best fitted y values

var RSS = MathNet.Numerics.Distance.SSD(y, yBest); // Residual sum of squares = 54.63889
var degreeOfFreedom = x.Length - 2; // Degree of freedom = 5
var RMSE = Math.Sqrt(RSS / degreeOfFreedom); // Root mean square of the error = 3.30572