| 119677 | } |
| 119678 | // License: https://github.com/HarryStevens/d3-regression/blob/master/LICENSE |
| 119679 | function 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 |
| 119696 | function log(data, x2, y) { |
| 119697 | let X = 0, Y = 0, XY = 0, X2 = 0, n = 0; |