Excel Linest Function

Related Function:
LOGEST function

Equation for a Straight Line

The Excel Linest Function uses the least squares method to calculate the line of best fit for a supplied set of y- and x- values.

If there is a single range of x-values, the calculated line satisfies the simple straight line equation:

y = mx + b

where,
- x is the independent variable
- y is the dependent variable
- m is the slope (gradient) of the line
- b is a constant which is the value of y when x = 0

If there are multiple ranges of x-values, the line of best fit satisfies the following equation:

y = m1x1 + m2x2 + ... + b

where,
- the x's are the independent variable ranges
- y is the dependent variable
- the m's are constant multipliers for each x range
- b is a constant


Basic Description

The Excel LINEST function returns statistical information on the line of best fit, through a supplied set of x- and y- values.

The basic statistical information returned is the array of constants, mn, mn-1, ... , b (or m and b) for the straight line equation. However, you can also request that additional regression statistics be returned.

The format of the Linest function is :

LINEST( known_y's, [known_x's], [const], [stats] )

Where the function arguments are listed in the table below:


known_y's - An array known y-values
[known_x's] -

An optional argument, providing an array of known x-values

(If provided the [known_x's] array should have the same length as the known_y's array;
If omitted, the [known_x's] array takes on the default value {1, 2, 3, ...})
[const] - An optional logical argument that determines how the constant 'b' is treated in the straight-line equation y = mx + b. This argument can have the value TRUE or FALSE, meaning:
TRUE (or omitted) - the constant b is treated normally
FALSE - the constant b is set to 0 in the equation y = mx + b
[stats] - An optional logical argument which specifies whether or not you want the function to return additional regression statistics on the line of best fit. This argument can have the value TRUE or FALSE, meaning:
FALSE (or omitted) - Do NOT return additional regression statistics
i.e. just return the array of values mn, mn-1, ... , b
TRUE - DO return additional regression statistics
i.e. Return the array of values mn, mn-1, ... , b and also return
the additional regression statistics listed in the table below

The array of statistics returned from the Excel Linest function has the following form:

mn mn-1 ... m1 b
sen sen-1 ... se1 seb
r2 sey      
F df      
ssreg ssresid      

where the statistics returned are:

mi - The array of constant multipliers for the straight line equation
b - The constant value of y when x=0
sei - The standard error values for the coefficients, mi
seb - The standard error value for the constant b
(returns the #N/A error if the [const] argument is FALSE)
r2 - The coefficient of determination
sey - The standard error for the y estimate
F - The F statistic, or the F-observed value
df - The number of degrees of freedom
ssreg - The regression sum of squares
ssresid - The residual sum of squares
Inputting an Array Formula

To input an array formula, you need to first highlight the range of cells for the function result. Type your function into the first cell of the range, and press CTRL-SHIFT-Enter.

Go to the Excel array formulas page for more details.

As the Linest function returns an array of values, it must be entered as an array formula. If the function is not entered as an array formula, only the first 'm' value in the calculated array of statistical information is returned.

You can see if a function has been input as an array formula, curly brackets will be inserted around the formula, as it is viewed in the formula bar. This can be seen in the examples below.


Linest Function Example 1

Cells A2 - A10 and B2 - B10 of the spreadsheet below list a number of known x and known y values, and also shows these points, plotted on a chart. Cells D1 - E5 of the spreadsheet show the Excel Linest function, used to return statistical information relating to the line of best fit through these points.

The format of the Linest function is seen in the formula bar. The curly brackets around this function show that it has been entered as an array formula.

Example of use of the Excel Linest Function

Cells D1 and E1 give the values of the slope, m as 1.88452381, and the y-intercept, b as 2.419642857. Therefore, the equation for the line of best fit through the given points is:

y = 1.88452381 x + 2.419642857

The remaining cells in the range D1 - E5 give the following additional statistics for this curve:



Linest Function Example 2

Cells A2 - A11, B2 - B11 and C2 - C11 of the spreadsheet below contain three different sets of independent variables (known x values), and cells D2 - D11 of the spreadsheet contain the associated known y-values. Cells F1 - H3 of the spreadsheet show the Excel Linest function, used to return statistical information relating to the line of best fit through these points.

Again, the format of the Linest function is seen in the formula bar and it can be seen, (from the curly brackets), that the function has been entered as an array formula.

Example of use of the Excel Linest Function with multiple independant variables

Cells F1 - I1 give the values of the coefficents, m3, m2 and m1 as 3.874869212, 2.027512015 and 4.049870099, respectively and the y-intercept, b as 5.710012148. Therefore, the equation for the line of best fit through the given points is:

y = 4.049870099 x1 + 2.027512015 x2 + 3.874869212 x3 + 5.710012148

The remaining cells in the range F1 - I5 give the following additional statistics for this curve:

and the unused cells show the #N/A error.


Further information and examples of the Excel Linest function can be found on the Microsoft Office website.


Linest Function Errors

If you get an error from the Excel Linest function this is likely to be one of the following:

Common Errors
#REF! - Occurs if the array of [known_x's] is not the same length as the array of known_y's
#VALUE! -

Occurs if any values in the supplied [known_x's] or known_y's arrays are not numeric values

(this may include text representations of numbers, as the Linest function does not recognise these as numbers)
Return to the Excel Statistical Functions Page

Return to the List of All Built-In Excel Functions

Valid XHTML 1.0 Transitional Valid CSS!
Disclaimer   Privacy Policy
Copyright © 2008-2014 ExcelFunctions.net