The linest function is a useful tool in Excel to fit a line (y= mx + b) to the data in order to identify the relationship between two variables (x and y). In addition to the fitted value, the linest function also produces uncertainty estimates for the fitted values, which we could not get from the trendline function. The linest function uses the least square procedure which fits a line to a set of data points by minimizing the sum of the squares of the residuals of the points from the curve. You can learn more about least square procedure here:http://mathworld.wolfram.com/LeastSquaresFitting.html
First of all, let us enter the data for which you want to calculate the linest function. Type your data in two columns, one for the x variables and one for the y.
Select the area that will hold the statistics of the fitted function. Unlike other Excel functions, the linest function has multiple outputs. Each output appears in a different cell. In order to see all of the outputs, you need to select the appropriate number of cells in the appropriate locations. You should drag the mouse to form a 5 row by 2 column area to hold the results, as shown below. (We will explain why and what each entry means)
Click Formulas in the Menu and select Insert at the very left. In the drop down list, select the category “Statistical”. And from that category, scroll down and select function “LINEST”.
Click on OK and you will see the function with the prompts for what parameters to put in.
Select the y and x values you want to fit with the linest function and type in “True” for [const] and [stats]. The first True indicates that you wish the line to be in the form y=mx+b with a non-zero intercept. The second True specifies that you wish the error estimates to be listed. The four parameters need to be separated by commas.
Then click Enter and you will see a number in the first box of your 5*2 matrix. This number is the coefficient m in the equation y=mx+b.
The next step will give you the error estimates and other information of your linear model. Select the 5*2 matrix for holding the results. Then highlight the entire formula in the formula bar for the cell containing the coefficient (in this example 2.628571), including the equal sign. Hold down Command and press Return. You will then get the error estimates.
Error estimates for slope and intercept are useful for analysis in a variety of subjects.
The next step, after getting all the estimates, would be to graph the data points and the fitted line. Notice that the fitted line plotted from the linest function will be the same line as the linear trendline. If you do not need the exact value of fitted y, you could skip the next step and simply add a trendline to the scatterplot of x and y.
We first calculate the fitted values. In the column after the y values, we created the fitted y values which are equal to x values * slope + intercept.
Since we are using the same slope (cell C11) and same intercept (cell B11) for all fitted values, we use absolute reference for the two cells. (Recall absolute reference here) Then we use auto fill to get all fitted y values. (Recall auto fill here)
Now we have all information and we are ready to graph the results. Select the x, y and fitted y values and make a scatter plot first. (Recall how to create a chart here)
You can add titles, axis names and edit legend. (To get help editing charts) Then we replace the plotting symbols for the fitted y values with connecting lines. In order to do this, we double click on one of the fitted y value data points. The Format Data Series dialogue box will pop up. Change the marker type to none and line color to be solid line.
Click on OK, and you will get the plot with fitted y values connected by a line.