Skip to content

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.

number[][]

an array of two-element arrays, like [[0, 1], [2, 3]]

number[]

weight for each coordinate

any

object containing slope and intersect of regression line

if data is empty, weights is a different length than data, all weights are zero, or a weight is negative

weightedLinearRegression([[0, 0], [1, 1], [2, 2]], [1, 1, 1]); // => { m: 1, b: 0 }