LINEST

function LINEST(arg1: ApiRange = null, arg2: ApiRange = null, arg3: boolean = null, arg4: boolean = null): number

Description

Returns statistics that describe a linear trend matching known data points, by fitting a straight line using the least squares method.

Parameters

arg1ApiRangedefault: null

The set of y-values from the y = mx + b equation.

arg2ApiRangedefault: null

An optional set of x-values from the y = mx + b equation.

arg3booleandefault: null

A logical value: the constant b is calculated normally if this parameter is set to true or omitted, and b is set equal to 0 if the parameter is false.

arg4booleandefault: null

A logical value: return additional regression statistics if this parameter is set to true, and return m-coefficients and the constant b if the parameter is false or omitted.

Returns

number

Try It



const oWorksheet = Api.GetActiveSheet();

//configure function parameters
var yValues = [1.5, 2, 3];
var xValues = [2, 3.1, 3.5];
var constant = true;
var stats = true;

//set values in cells
for (var i = 0; i < yValues.length; i++) {
 oWorksheet.GetRange("A" + (i + 1)).SetValue(yValues[i]);
}
for (var n = 0; n < xValues.length; n++) {
 oWorksheet.GetRange("B" + (n + 1)).SetValue(xValues[n]);
}

//get x and y ranges
var yRange = oWorksheet.GetRange("A1:A3");
var xRange = oWorksheet.GetRange("B1:B3");
var oFunction = Api.GetWorksheetFunction();

//invoke LINEST method
var ans = oFunction.LINEST(yRange, xRange, constant, stats);
console.log(ans)

//print answer 
oWorksheet.GetRange("D1").SetValue(ans);


Get Help

  • If you have any questions about ONLYOFFICE Docs, try the FAQ section first.
  • You can request a feature or report a bug by posting an issue on GitHub.
  • You can also ask our developers on ONLYOFFICE forum (registration required).