=LINEST()
The LINEST function calculates the statistics for a line by using the "least squares" method to calculate a straight line that best fits your data, and then returns an array that describes the line. You can also combine LINEST with other functions to calculate the statistics for other types of models that are linear in the unknown parameters, including polynomial, logarithmic, exponential, and power series. Because this function returns an array of values, it must be entered as an array formula. Instructions follow the examples in this article. The equation for the line is: y = mx + b –or– y = m1x1 + m2x2 + ... + b if there are multiple ranges of x-values, where the dependent y-values are a function of the independent x-values. The m-values are coefficients corresponding to each x-value, and b is a constant value. Note that y, x, and m can be vectors. The array that the LINEST function returns is {mn,mn-1,...,m1,b}. LINEST can also return additional regression statistics.
=LINEST(known_y's, [known_x's], [const], [stats])
⬇ Download Sample Workbook
A dedicated .xlsx for =LINEST() with Persian sample data & live formulas — open in Excel and practice.
- Sheet “Sample” — data table + formula in place
- Sheet “Guide” — syntax, arguments & tips from this page
- Instant & secure (token + rate limit)
Quiz this function
%d questions — syntax, example & errors — test yourself!
◧ Arguments
| Argument | Type | Required | Description |
|---|---|---|---|
known_y's |
Range | Required | The set of y-values that you already know in the relationship y = mx + b. If the range of known_y's is in a single column, each column of known_x's is interpreted as a separate variable. If the range of known_y's is contained in a single row, each row of known_x's is interpreted as a separate variable. |
known_x's |
Range | Optional | A set of x-values that you may already know in the relationship y = mx + b. The range of known_x's can include one or more sets of variables. If only one variable is used, known_y's and known_x's can be ranges of any shape, as long as they have equal dimensions. If more than one variable is used, known_y's must be a vector (that is, a range with a height of one row or a width of one column). If known_x's is omitted, it is assumed to be the array {1,2,3,...} that is the same size as known_y's. |
const |
Logical | Optional | A logical value specifying whether to force the constant b to equal 0. If const is TRUE or omitted, b is calculated normally. If const is FALSE, b is set equal to 0 and the m-values are adjusted to fit y = mx. |
stats |
Logical | Optional | A logical value specifying whether to return additional regression statistics. If stats is TRUE, LINEST returns the additional regression statistics; as a result, the returned array is {mn,mn-1,...,m1,b;sen,sen-1,...,se1,seb;r2,sey;F,df;ssreg,ssresid}. If stats is FALSE or omitted, LINEST returns only the m-coefficients and the constant b. The additional regression statistics are as follows. |
▣ Examples
| Cell | Value |
|---|---|
A2 |
Known y |
B2 |
Known x |
A3 |
1 |
B3 |
0 |
A4 |
9 |
B4 |
4 |
A5 |
5 |
B5 |
2 |
A6 |
7 |
B6 |
3 |
A7 |
Result (slope) |
B7 |
Result (y-intercept) |
A8 |
2 |
B8 |
1 |
A9 |
=LINEST(A2:A5,B2:B5,,FALSE) |
A10 |
Month |
B10 |
Sales |
A11 |
1 |
B11 |
$3,100 |
A12 |
2 |
B12 |
$4,500 |
A13 |
3 |
B13 |
$4,400 |
A14 |
4 |
B14 |
$5,400 |
A15 |
5 |
B15 |
$7,500 |
A16 |
6 |
B16 |
$8,100 |
A17 |
Floor space (x1) |
B17 |
Offices (x2) |
C17 |
Entrances (x3) |
D17 |
Age (x4) |
E17 |
Assessed value (y) |
A18 |
2310 |
B18 |
2 |
C18 |
2 |
D18 |
20 |
E18 |
$142,000 |
A19 |
2333 |
B19 |
2 |
C19 |
2 |
D19 |
12 |
E19 |
$144,000 |
A20 |
2356 |
B20 |
3 |
C20 |
1.5 |
D20 |
33 |
E20 |
$151,000 |
A21 |
2379 |
B21 |
3 |
C21 |
2 |
D21 |
43 |
E21 |
$150,000 |
A22 |
2402 |
B22 |
2 |
C22 |
3 |
D22 |
53 |
E22 |
$139,000 |
A23 |
2425 |
B23 |
4 |
C23 |
2 |
D23 |
23 |
E23 |
$169,000 |
A24 |
2448 |
B24 |
2 |
C24 |
1.5 |
D24 |
99 |
E24 |
$126,000 |
A25 |
2471 |
B25 |
2 |
C25 |
2 |
D25 |
34 |
E25 |
$142,900 |
A26 |
2494 |
B26 |
3 |
C26 |
3 |
D26 |
23 |
E26 |
$163,000 |
A27 |
2517 |
B27 |
4 |
C27 |
4 |
D27 |
55 |
E27 |
$169,000 |
A28 |
2540 |
B28 |
2 |
C28 |
3 |
D28 |
22 |
E28 |
$149,000 |
A29 |
-234.2371645 |
A30 |
13.26801148 |
A31 |
0.996747993 |
A32 |
459.7536742 |
A33 |
1732393319 |
A34 |
=LINEST(E2:E12,A2:D12,TRUE,TRUE) |
A35 |
Variable |
B35 |
t-observed value |
A36 |
Floor space |
B36 |
5.1 |
A37 |
Number of offices |
B37 |
31.3 |
A38 |
Number of entrances |
B38 |
4.8 |
A39 |
Age |
B39 |
17.7 |
A40 |
Known y |
B40 |
Known x |
A41 |
1 |
B41 |
0 |
A42 |
9 |
B42 |
4 |
A43 |
5 |
B43 |
2 |
A44 |
7 |
B44 |
3 |
A45 |
Result (slope) |
B45 |
Result (y-intercept) |
A46 |
2 |
B46 |
1 |
A47 |
=LINEST(A2:A5,B2:B5,,FALSE) |
A48 |
Month |
B48 |
Sales |
A49 |
1 |
B49 |
$3,100 |
A50 |
2 |
B50 |
$4,500 |
A51 |
3 |
B51 |
$4,400 |
A52 |
4 |
B52 |
$5,400 |
A53 |
5 |
B53 |
$7,500 |
A54 |
6 |
B54 |
$8,100 |
A55 |
Floor space (x1) |
B55 |
Offices (x2) |
C55 |
Entrances (x3) |
D55 |
Age (x4) |
E55 |
Assessed value (y) |
A56 |
2310 |
B56 |
2 |
C56 |
2 |
D56 |
20 |
E56 |
$142,000 |
A57 |
2333 |
B57 |
2 |
C57 |
2 |
D57 |
12 |
E57 |
$144,000 |
A58 |
2356 |
B58 |
3 |
C58 |
1.5 |
D58 |
33 |
E58 |
$151,000 |
A59 |
2379 |
B59 |
3 |
C59 |
2 |
D59 |
43 |
E59 |
$150,000 |
A60 |
2402 |
B60 |
2 |
C60 |
3 |
D60 |
53 |
E60 |
$139,000 |
A61 |
2425 |
B61 |
4 |
C61 |
2 |
D61 |
23 |
E61 |
$169,000 |
A62 |
2448 |
B62 |
2 |
C62 |
1.5 |
D62 |
99 |
E62 |
$126,000 |
A63 |
2471 |
B63 |
2 |
C63 |
2 |
D63 |
34 |
E63 |
$142,900 |
A64 |
2494 |
B64 |
3 |
C64 |
3 |
D64 |
23 |
E64 |
$163,000 |
A65 |
2517 |
B65 |
4 |
C65 |
4 |
D65 |
55 |
E65 |
$169,000 |
A66 |
2540 |
B66 |
2 |
C66 |
3 |
D66 |
22 |
E66 |
$149,000 |
A67 |
-234.2371645 |
A68 |
13.26801148 |
A69 |
0.996747993 |
A70 |
459.7536742 |
A71 |
1732393319 |
A72 |
=LINEST(E2:E12,A2:D12,TRUE,TRUE) |
A73 |
Variable |
B73 |
t-observed value |
A74 |
Floor space |
B74 |
5.1 |
A75 |
Number of offices |
B75 |
31.3 |
A76 |
Number of entrances |
B76 |
4.8 |
A77 |
Age |
B77 |
17.7 |
=SUM(LINEST(B1:B6, A1:A6)*{9,1})
§ Remarks
- You can describe any straight line with the slope and the y-intercept: Slope (m): To find the slope of a line, often written as m, take two points on the line, (x1,y1) and (x2,y2); the slope is equal to (y2 - y1)/(x2 - x1). Y-intercept (b): The y-intercept of a line, often written as b, is the value of y at the point where the line crosses the y-axis. The equation of a straight line is y = mx + b. Once you know the values of m and b, you can calculate any point on the line by plugging the y- or x-value into that equation. You can also use the TREND function.
- When you have only one independent x-variable, you can obtain the slope and y-intercept values directly by using the following formulas: Slope: =INDEX(LINEST(known_y's,known_x's),1) Y-intercept: =INDEX(LINEST(known_y's,known_x's),2)
- The accuracy of the line calculated by the LINEST function depends on the degree of scatter in your data. The more linear the data, the more accurate the LINEST model. LINEST uses the method of least squares for determining the best fit for the data. When you have only one independent x-variable, the calculations for m and b are based on the following formulas: where x and y are sample means; that is, x = AVERAGE(known x's) and y = AVERAGE(known_y's).
- The line- and curve-fitting functions LINEST and LOGEST can calculate the best straight line or exponential curve that fits your data. However, you have to decide which of the two results best fits your data. You can calculate TREND(known_y's,known_x's) for a straight line, or GROWTH(known_y's, known_x's) for an exponential curve. These functions, without the new_x's argument, return an array of y-values predicted along that line or curve at your actual data points. You can then compare the predicted values with the actual values. You may want to chart them both for a visual comparison.
- In regression analysis, Excel calculates for each point the squared difference between the y-value estimated for that point and its actual y-value. The sum of these squared differences is called the residual sum of squares, ssresid. Excel then calculates the total sum of squares, sstotal. When the const argument = TRUE or is omitted, the total sum of squares is the sum of the squared differences between the actual y-values and the average of the y-values. When the const argument = FALSE, the total sum of squares is the sum of the squares of the actual y-values (without subtracting the average y-value from each individual y-value). Then regression sum of squares, ssreg, can be found from: ssreg = sstotal - ssresid. The smaller the residual sum of squares is, compared with the total sum of squares, the larger the value of the coefficient of determination, r2, which is an indicator of how well the equation resulting from the regression analysis explains the relationship among the variables. The value of r2 equals ssreg/sstotal.
- In some cases, one or more of the X columns (assume that Y’s and X’s are in columns) may have no additional predictive value in the presence of the other X columns. In other words, eliminating one or more X columns might lead to predicted Y values that are equally accurate. In that case these redundant X columns should be omitted from the regression model. This phenomenon is called “collinearity” because any redundant X column can be expressed as a sum of multiples of the non-redundant X columns. The LINEST function checks for collinearity and removes any redundant X columns from the regression model when it identifies them. Removed X columns can be recognized in LINEST output as having 0 coefficients in addition to 0 se values. If one or more columns are removed as redundant, df is affected because df depends on the number of X columns actually used for predictive purposes. For details on the computation of df, see Example 4. If df is changed because redundant X columns are removed, values of sey and F are also affected. Collinearity should be relatively rare in practice. However, one case where it is more likely to arise is when some X columns contain only 0 and 1 values as indicators of whether a subject in an experiment is or is not a member of a particular group. If const = TRUE or is omitted, the LINEST function effectively inserts an additional X column of all 1 values to model the intercept. If you have a column with a 1 for each subject if male, or 0 if not, and you also have a column with a 1 for each subject if female, or 0 if not, this latter column is redundant because entries in it can be obtained from subtracting the entry in the “male indicator” column from the entry in the additional column of all 1 values added by the LINEST function.
- The value of df is calculated as follows, when no X columns are removed from the model due to collinearity: if there are k columns of known_x’s and const = TRUE or is omitted, df = n – k – 1. If const = FALSE, df = n - k. In both cases, each X column that was removed due to collinearity increases the value of df by 1.
- When entering an array constant (such as known_x's) as an argument, use commas to separate values that are contained in the same row and semicolons to separate rows. Separator characters may be different depending on your regional settings.
- Note that the y-values predicted by the regression equation may not be valid if they are outside the range of the y-values you used to determine the equation.
- The underlying algorithm used in the LINEST function is different than the underlying algorithm used in the SLOPE and INTERCEPT functions. The difference between these algorithms can lead to different results when data is undetermined and collinear. For example, if the data points of the known_y's argument are 0 and the data points of the known_x's argument are 1: LINEST returns a value of 0. The algorithm of the LINEST function is designed to return reasonable results for collinear data and, in this case, at least one answer can be found. SLOPE and INTERCEPT return a #DIV/0! error. The algorithm of the SLOPE and INTERCEPT functions is designed to look for only one answer, and in this case there can be more than one answer.
- In addition to using LOGEST to calculate statistics for other regression types, you can use LINEST to calculate a range of other regression types by entering functions of the x and y variables as the x and y series for LINEST. For example, the following formula: =LINEST(yvalues, xvalues^COLUMN($A:$C)) works when you have a single column of y-values and a single column of x-values to calculate the cubic (polynomial of order 3) approximation of the form: y = m1*x + m2*x^2 + m3*x^3 + b You can adjust this formula to calculate other types of regression, but in some cases it requires the adjustment of the output values and other statistics.
- The F-test value that is returned by the LINEST function differs from the F-test value that is returned by the FTEST function. LINEST returns the F statistic, whereas FTEST returns the probability.
✦ Tips
- You can describe any straight line with the slope and the y-intercept: Slope (m): To find the slope of a line, often written as m, take two points on the line, (x1,y1) and (x2,y2); the slope is equal to (y2 - y1)/(x2 - x1). Y-intercept (b): The y-intercept of a line, often written as b, is the value of y at the point where the line crosses the y-axis. The equation of a straight line is y = mx + b. Once you know the values of m and b, you can calculate any point on the line by plugging the y- or x-value into that equation. You can also use the TREND function.
- When you have only one independent x-variable, you can obtain the slope and y-intercept values directly by using the following formulas: Slope: =INDEX(LINEST(known_y's,known_x's),1) Y-intercept: =INDEX(LINEST(known_y's,known_x's),2)
- The accuracy of the line calculated by the LINEST function depends on the degree of scatter in your data. The more linear the data, the more accurate the LINEST model. LINEST uses the method of least squares for determining the best fit for the data. When you have only one independent x-variable, the calculations for m and b are based on the following formulas: where x and y are sample means; that is, x = AVERAGE(known x's) and y = AVERAGE(known_y's).
- The line- and curve-fitting functions LINEST and LOGEST can calculate the best straight line or exponential curve that fits your data. However, you have to decide which of the two results best fits your data. You can calculate TREND(known_y's,known_x's) for a straight line, or GROWTH(known_y's, known_x's) for an exponential curve. These functions, without the new_x's argument, return an array of y-values predicted along that line or curve at your actual data points. You can then compare the predicted values with the actual values. You may want to chart them both for a visual comparison.
- In regression analysis, Excel calculates for each point the squared difference between the y-value estimated for that point and its actual y-value. The sum of these squared differences is called the residual sum of squares, ssresid. Excel then calculates the total sum of squares, sstotal. When the const argument = TRUE or is omitted, the total sum of squares is the sum of the squared differences between the actual y-values and the average of the y-values. When the const argument = FALSE, the total sum of squares is the sum of the squares of the actual y-values (without subtracting the average y-value from each individual y-value). Then regression sum of squares, ssreg, can be found from: ssreg = sstotal - ssresid. The smaller the residual sum of squares is, compared with the total sum of squares, the larger the value of the coefficient of determination, r2, which is an indicator of how well the equation resulting from the regression analysis explains the relationship among the variables. The value of r2 equals ssreg/sstotal.
- In some cases, one or more of the X columns (assume that Y’s and X’s are in columns) may have no additional predictive value in the presence of the other X columns. In other words, eliminating one or more X columns might lead to predicted Y values that are equally accurate. In that case these redundant X columns should be omitted from the regression model. This phenomenon is called “collinearity” because any redundant X column can be expressed as a sum of multiples of the non-redundant X columns. The LINEST function checks for collinearity and removes any redundant X columns from the regression model when it identifies them. Removed X columns can be recognized in LINEST output as having 0 coefficients in addition to 0 se values. If one or more columns are removed as redundant, df is affected because df depends on the number of X columns actually used for predictive purposes. For details on the computation of df, see Example 4. If df is changed because redundant X columns are removed, values of sey and F are also affected. Collinearity should be relatively rare in practice. However, one case where it is more likely to arise is when some X columns contain only 0 and 1 values as indicators of whether a subject in an experiment is or is not a member of a particular group. If const = TRUE or is omitted, the LINEST function effectively inserts an additional X column of all 1 values to model the intercept. If you have a column with a 1 for each subject if male, or 0 if not, and you also have a column with a 1 for each subject if female, or 0 if not, this latter column is redundant because entries in it can be obtained from subtracting the entry in the “male indicator” column from the entry in the additional column of all 1 values added by the LINEST function.
- When entering an array constant (such as known_x's) as an argument, use commas to separate values that are contained in the same row and semicolons to separate rows. Separator characters may be different depending on your regional settings.
- Note that the y-values predicted by the regression equation may not be valid if they are outside the range of the y-values you used to determine the equation.
- In addition to using LOGEST to calculate statistics for other regression types, you can use LINEST to calculate a range of other regression types by entering functions of the x and y variables as the x and y series for LINEST. For example, the following formula: =LINEST(yvalues, xvalues^COLUMN($A:$C)) works when you have a single column of y-values and a single column of x-values to calculate the cubic (polynomial of order 3) approximation of the form: y = m1*x + m2*x^2 + m3*x^3 + b You can adjust this formula to calculate other types of regression, but in some cases it requires the adjustment of the output values and other statistics.
- The F-test value that is returned by the LINEST function differs from the F-test value that is returned by the FTEST function. LINEST returns the F statistic, whereas FTEST returns the probability.
⚠ Common Errors
💬 Comments & Q&A 0 approved
🔒 Your comment will be published after review.Share your thoughts — visible after admin approval