weightedLinearRegression
weightedLinearRegression(
data,weights):any
Defined in: src/weighted_linear_regression.js:22
Weighted least squares
fits a line through a set of coordinates in which some observations count
for more than others, which is what R’s lm() does when given a weights
argument. linearRegression is the special case where every weight is
equal.
A weight of zero drops its observation from the fit. Weights are relative, so scaling all of them by the same factor leaves the line unchanged.
Parameters
Section titled “Parameters”number[][]
an array of two-element arrays,
like [[0, 1], [2, 3]]
weights
Section titled “weights”number[]
weight for each coordinate
Returns
Section titled “Returns”any
object containing slope and intersect of regression line
Throws
Section titled “Throws”if data is empty, weights is a different length than data, all weights are zero, or a weight is negative
Example
Section titled “Example”weightedLinearRegression([[0, 0], [1, 1], [2, 2]], [1, 1, 1]); // => { m: 1, b: 0 }