Formualizer Docs

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

ArgumentTypeRequiredDefault
known_ysnumber (range)Required—
known_xsnumber (range)Optional—
constnumber (range)Optional—
statsnumber (range)Optional—

Remarks

  • known_y is required; known_x defaults to 1..n when omitted.
  • When known_y is a column, each column of known_x is 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.
  • const controls whether an intercept is fitted (TRUE by default); with FALSE, b = 0.
  • stats=TRUE returns 5 rows: coefficients, standard errors (se_b is #N/A without a constant), r2/sey, F/df, and ssreg/ssresid, padded with #N/A.
  • A variable that is a linear combination of the others is removed: its coefficient and standard error are 0 and df grows 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?.

Implementation

Engine source

On this page