Skip to content

Loess.Function.calculateLocalLinearRegression

Christian d'Heureuse edited this page Sep 25, 2026 · 1 revision

commons-math-interpolation / Loess / calculateLocalLinearRegression

Function: calculateLocalLinearRegression()

function calculateLocalLinearRegression(
   xVals, 
   yVals, 
   weights, 
   x, 
   iLeft, 
   iRight, 
   accuracy
): number;

Defined in: Loess.ts:367

Calculates the weighted least-squares linear fit at position x over the points iLeft ... iRight.

The points are weighted by the product of the passed weights and the tri-cube function of their x distance from x, relative to the largest x distance within the interval.

Parameters

xVals

ArrayLike<number>

The x values of the points, in monotonically increasing order.

yVals

ArrayLike<number>

The y values of the points.

weights

ArrayLike<number> | undefined

The weights of the points, or undefined for the weight 1 for all points.

x

number

The x position at which the regression line is evaluated.

iLeft

number

The index of the first point of the bandwidth interval.

iRight

number

The index of the last point of the bandwidth interval (inclusive).

accuracy

number

If the weighted standard deviation of the x values is less than this value, the slope of the regression line is assumed to be 0.

Returns

number

The value of the regression line at x, or NaN if the sum of the weights is 0.

Throws

Error If the interval iLeft ... iRight is inconsistent.

Clone this wiki locally