MCPcopy
hub / github.com/microsoft/SandDance / linear

Function linear

docs/app/js/sanddance-app.js:119679–119694  ·  view source on GitHub ↗
(data, x1, y)

Source from the content-addressed store, hash-verified

119677}
119678// License: https://github.com/HarryStevens/d3-regression/blob/master/LICENSE
119679function linear(data, x1, y) {
119680 let X = 0, Y = 0, XY = 0, X2 = 0, n = 0;
119681 visitPoints(data, x1, y, (dx, dy)=>{
119682 ++n;
119683 X += (dx - X) / n;
119684 Y += (dy - Y) / n;
119685 XY += (dx * dy - XY) / n;
119686 X2 += (dx * dx - X2) / n;
119687 });
119688 const coef = ols(X, Y, XY, X2), predict = (x)=>coef[0] + coef[1] * x;
119689 return {
119690 coef: coef,
119691 predict: predict,
119692 rSquared: rSquared(data, x1, y, Y, predict)
119693 };
119694}
119695// License: https://github.com/HarryStevens/d3-regression/blob/master/LICENSE
119696function log(data, x2, y) {
119697 let X = 0, Y = 0, XY = 0, X2 = 0, n = 0;

Callers 3

polyFunction · 0.70
hueFunction · 0.70
nogammaFunction · 0.70

Calls 4

visitPointsFunction · 0.70
olsFunction · 0.70
rSquaredFunction · 0.70
linearishFunction · 0.70

Tested by

no test coverage detected