I need to calculate the R-squared value (Least Squares Method) for my regression model. How can I do this in JavaScript?
For example I have this data:
x = [5, 7, 8, 7, 2, 17, 2, 9, 4, 11, 12, 9, 6]
y = [99, 86, 87, 88, 111, 86, 103, 87, 94, 78, 77, 85, 86]
After doing my regression math I got the these coefficients (format: a + bx) [103.10596026, -1.75128771]
representing the line y = 103.10596026 - 1.75128771x.
Now I want to calculate the R-squared value but don't know how... an example function template would look like this:
function rSquared(xData, yData, modelCoefficients) {
// Do stuff here...
return rSquaredValue
}
Thanks!