LINEST function
The LINEST function in Excel calculates the statistics for a linear regression and returns an array of values that describe the relationship between a set of independent (x) and dependent (y) variables. It provides the slope, intercept, and other statistical data that help assess the strength and nature of the linear relationship.
Syntax:
LINEST(known_y's, known_x's, [const], [stats])
Arguments:
- known_y’s: Required. The range or array of dependent values (y-values), which represent the output or outcome you’re trying to predict.
- known_x’s: Required. The range or array of independent values (x-values), which represent the predictor or input variable.
- const: Optional. A logical value (TRUE or FALSE) that specifies whether to force the intercept (b) to be 0.
- TRUE (or omitted): The function will calculate the intercept normally.
- FALSE: The function will force the intercept to be 0, and the line will pass through the origin.
- stats: Optional. A logical value (TRUE or FALSE) that specifies whether to return additional regression statistics.
- TRUE: Returns additional regression statistics.
- FALSE (or omitted): Only returns the slope and intercept.
Output:
- If
statsis set to FALSE (or omitted), the function returns an array containing:- Slope (m): The slope of the regression line.
- Intercept (b): The intercept of the regression line.
- If
statsis set to TRUE, the function returns an array containing:- Slope (m)
- Intercept (b)
- Standard error of the slope
- Standard error of the intercept
- R-squared value: The square of the correlation coefficient (a measure of how well the data fit the regression line).
- F-statistic: A measure of how well the model explains the data, used for testing the hypothesis about the slope.
- Degrees of freedom
- Regression sum of squares
- Residual sum of squares
How It Works:
The LINEST function performs a least-squares regression analysis, fitting a straight line to the data. The general form of the regression equation is:
Where:
- is the slope of the line (calculated by
LINEST). - is the intercept (calculated by
LINEST). - represents the independent variable, and represents the dependent variable.
Example:
- Example 1: Basic Linear Regression Suppose you have the following data:
- x-values: 1, 2, 3, 4, 5 (in cells A1:A5)
- y-values: 2, 4, 6, 8, 10 (in cells B1:B5)
To perform a linear regression and find the slope and intercept, use the following formula:
=LINEST(B1:B5, A1:A5)The result will return the slope (2) and intercept (0), showing that the regression line is .
- Example 2: Including Additional Statistics If you want to return additional statistics such as R-squared and standard errors, use:
=LINEST(B1:B5, A1:A5, TRUE, TRUE)This will return multiple values, including:
- The slope and intercept.
- The standard error of the slope and intercept.
- The R-squared value.
- The F-statistic, and more.
Key Points:
- Slope (m) indicates the change in for each unit change in . It shows how much increases (or decreases) as increases.
- Intercept (b) is the value of when . It represents the starting point of the regression line.
- R-squared value indicates how well the regression model fits the data. A value of 1 means a perfect fit, while a value close to 0 indicates a poor fit.
- The
LINESTfunction can handle multiple independent variables (multiple x-values) for multiple linear regression by specifying multiple columns forknown_x's.
Use Cases:
- Trend Analysis: In business and finance, you can use
LINESTto analyze trends, such as predicting future sales based on historical data. - Forecasting:
LINESTis useful for creating linear forecasting models by calculating the best-fit line through the data points. - Data Analysis: In scientific research, you can apply
LINESTto determine the relationship between two variables and assess the accuracy of the linear model. - Engineering: Engineers can use linear regression to model various relationships (e.g., stress vs. strain) and predict future outcomes.
Notes:
- Array Formula: The
LINESTfunction is an array function, which means you must press Ctrl+Shift+Enter (not just Enter) when entering it into a cell if you’re returning more than one value (like when you includestats). - If you use multiple independent variables (i.e., multiple columns of x-values),
LINESTperforms multiple linear regression.
Example of Multiple Linear Regression:
If you have data for two independent variables (e.g., columns A and B), you can calculate the slope and intercept of the regression line by using:
=LINEST(C1:C5, A1:B5, TRUE, TRUE)
This will return the slope for each of the two variables (A and B), along with the intercept and other statistics.