1 | /**
|
2 | * Given the output of `linearRegression`: an object
|
3 | * with `m` and `b` values indicating slope and intercept,
|
4 | * respectively, generate a line function that translates
|
5 | * x values into y values.
|
6 | *
|
7 | * @param {Object} mb object with `m` and `b` members, representing
|
8 | * slope and intersect of desired line
|
9 | * @returns {Function} method that computes y-value at any given
|
10 | * x-value on the line.
|
11 | * @example
|
12 | * var l = linearRegressionLine(linearRegression([[0, 0], [1, 1]]));
|
13 | * l(0) // = 0
|
14 | * l(2) // = 2
|
15 | * linearRegressionLine({ b: 0, m: 1 })(1); // => 1
|
16 | * linearRegressionLine({ b: 1, m: 1 })(1); // => 2
|
17 | */
|
18 | function linearRegressionLine(mb /*: { b: number, m: number }*/) {
|
19 | // Return a function that computes a `y` value for each
|
20 | // x value it is given, based on the values of `b` and `a`
|
21 | // that we just computed.
|
22 | return function (x) {
|
23 | return mb.b + mb.m * x;
|
24 | };
|
25 | }
|
26 |
|
27 | export default linearRegressionLine;
|