MCPcopy Create free account
hub / github.com/arguiot/TheoremJS / linreg

Method linreg

__test__/theorem.js:267–288  ·  view source on GitHub ↗
(array)

Source from the content-addressed store, hash-verified

265 }
266 }
267 linreg(array) {
268 const x = Object.keys(array)
269 const y = Object.values(array)
270 const n = y.length;
271 let sum_x = 0;
272 let sum_y = 0;
273 let sum_xy = 0;
274 let sum_xx = 0;
275 let sum_yy = 0;
276
277 for (let i = 0; i < y.length; i++) {
278 sum_x += parseFloat(x[i]);
279 sum_y += parseFloat(y[i]);
280 sum_xy += parseFloat(x[i] * y[i]);
281 sum_xx += parseFloat(x[i] * x[i]);
282 sum_yy += parseFloat(y[i] * y[i]);
283 }
284
285 const slope = (n * sum_xy - sum_x * sum_y) / (n * sum_xx - sum_x * sum_x);
286 const intercept = (sum_y - slope * sum_x) / n;
287 return this.polynomial(slope, intercept)
288 }
289 polyreg(data, deg) {
290 const x = Object.keys(data)
291 for (let i in x) {

Callers 2

regressionMethod · 0.95
regression.jsFile · 0.80

Calls 1

polynomialMethod · 0.95

Tested by

no test coverage detected