LINEST
Returns linear-regression coefficients and optional fit statistics.
LINEST fits y = m1*x1 + ... + mk*xk + b by least squares and returns either
{mk, ..., m1, b} or that row followed by the regression statistics.
The Formualizer engine in this repository at 0.15.0 plus unreleased changes computes the example results. Known differences from Excel are listed on this page.
Syntax
=LINEST(known_ys, [known_xs], [const], [stats])
Arguments
| Argument | Type | Required | Default |
|---|---|---|---|
known_ys | number (range) | Required | — |
known_xs | number (range) | Optional | — |
const | number (range) | Optional | — |
stats | number (range) | Optional | — |
Remarks
known_yis required;known_xdefaults to1..nwhen omitted.- When
known_yis a column, each column ofknown_xis a variable; when it is a row, each row is. With one variable the two ranges only need equal dimensions. - Coefficients are returned in reverse order of the variables, then
b. constcontrols whether an intercept is fitted (TRUEby default); withFALSE,b = 0.stats=TRUEreturns 5 rows: coefficients, standard errors (se_bis#N/Awithout a constant),r2/sey,F/df, andssreg/ssresid, padded with#N/A.- A variable that is a linear combination of the others is removed: its coefficient and
standard error are
0anddfgrows by one.
Error cases
- Returns
#VALUE!for non-numeric data and#REF!for incompatible shapes.
Examples
Fit coefficients using three observations and their known x values.
Formula =LINEST({2;4;8},{1;2;3})
Expected result {3, -1.33333333333333}
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Request the additional regression statistics.
Formula =LINEST({2;4;8},{1;2;3},TRUE,TRUE)
Expected result {3, -1.33333333333333; 0.577350269189626, 1.24721912892465; 0.964285714285714, 0.816496580927726; 27, 1; 18, 0.666666666666667}
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Use two observations with distinct x values.
Formula =LINEST({2;4},{1;2})
Expected result {2, 0}
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
The independent and dependent observations do not align.
Formula =LINEST({2;4;8},{1;2})
Expected result #REF!
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Slope and intercept only
Formula =LINEST({2,4,6},{1,2,3})
Expected result {2, 0}
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Linear fit with non-zero intercept
Formula =LINEST({3,5,7},{1,2,3})
Expected result {2, 1}
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.