Let us implement a code to calculate slope of regression line. Let us see the formula for calculating m (slope) and c (intercept).
Jeff Meyer is a statistical consultant with The Analysis Factor, a stats mentor for Statistically Speaking membership, and a workshop instructor. How to calculate slope and intercept of regression line. The fitted line of the model estimated the intercept passes through most of the actual data while the fitted line for the unestimated intercept model does not.įorcing the intercept to equal 0 forces the line through the origin, which will never fit as well as a line whose intercept is estimated from the data.
When you remove an intercept from a regression model, you’re setting it equal to 0 rather than estimating it from the data.
Instead you’re telling your software that rather than estimate it from the data, assign it a value of 0. When you eliminate an intercept from a regression model, it doesn’t go away. Remember, residual variance is unexplained and we want to minimize it.Īdditionally, the mean of the residuals will not equal zero, which is a requirement for an OLS model. The standard deviation of the residuals from the without-intercept model will never be as low as those from the with-intercept model. The table below is a summary of the residuals with (labelled wc) and without (nc) the intercept. It’s the estimate of the relationship between length and weight of the cars we’re interested in and we’ve biased it. Example 1: Repeat Example 2 of Multiple Regression Analysis in Excel using a linear regression model without intercept (see Figure 1 for a copy of the data) Enter Ctrl-m and select Multiple Linear Regression from the Reg tab (or double-click on the Regression option and select Linear Regression if using the original user interface). Notice the slope of length has dropped from 33 to 16. For example, the slope is 2.6290.085 and the intercept is -3.33 0.41. If we exclude the intercept, we get this: The Excel spreadsheet function linest is a complete linear least squares. Using the same data, if we regress weight on the continuous variable length (in inches) and include the intercept (labeled _cons), we get the following results: Let’s go back to the cars we talked about earlier. The Excel INTERCEPT function returns the point at which a regression line will intersect the y-axis based on known x and y values. Spoiler alert: You should never remove the intercept when a predictor variable is continuous. This month we’re going to talk about removing the intercept when the predictor variable is continuous.
In a recent article, we reviewed the impact of removing the intercept from a regression model when the predictor variable is categorical.