Login
📚 Mostly Harmless Statistics
Chapters ▾
⇩ Download ▾

12.4 Simple Linear Regression

A linear regression is a straight line that describes how the values of a response variable y change as the predictor variable x changes. The equation of a line, relating x to y uses the slope-intercept form of a line, but with different letters than what you may be used to in a math class. We let b0 represent the sample y-intercept (the value of y when x=0), b1 the sample slope (rise over run), and y^ the predicted value of y for a specific value of x. The equation is written as y^=b0+b1x.

Some textbooks and the TI calculators use the letter a to represent the y-intercept and b to represent the slope, and the equation is written as y^=a+bx. These letters are just symbols representing the placeholders for the numeric values for the y-intercept and slope.

If we were to fit the best line that was closest to all the points on the scatterplot we would get what we call the “line of best fit,” also known as the “regression equation” or “least squares regression line.” Figure 12-9 is a scatterplot with just five points.

A scatterplot containing 5 points.
Figure 12-9: A scatterplot.

Figure 12-10 shows the least-squares regression line of y on x, which is the line that minimizes the squared vertical distance from all of the data. If we were to fit the line that best fits through the points, we would get the line pictured below.

The scatterplot, containing an additional line that passes roughly an equal distance from each of the points.
Figure 12-10: Scatterplot with least-squares regression line.

What we want to look for is the minimum of the squared vertical distance between each point and the regression equation, called a residual. This is where the name of the least squares regression line comes from. Figure 12-11 shows the squared residuals.

Scatterplot with regression line and squared residuals. Residuals are represented by each point above the line being located at the top left corner of a square whose lower left corner rests on the line, and each point below the line being at the bottom left corner of a square whose upper left corner rests on the line.
Figure 12-11: Scatterplot with least-squares regression line and squared residuals.

To find the slope and y-intercept for the equation of the least-squares regression line y^=b0+b1x we use the following formulas: slope =b1=SSxySSxx, y-intercept: b0=y¯b1x¯.

To compute the least squares regression line, you will need to first find the slope. Then substitute the slope into the following equation of the y-intercept: b0=y¯b1x¯, where x¯ = the sample mean of the x’s and y¯ = the sample mean of the y’s.

Once we find the equation for the regression line, we can use it to estimate the response variable y for a specific value of the predictor variable x.

Note: we would only want to use the regression equation for prediction if we reject H0 and find that there is a significant correlation between x and y. Alternatively, we could start with the regression equation and then test to see if the slope is significantly different from zero.

Adapted from Mostly Harmless Statistics by Rachel Webb (Portland State University), hosted on LibreTexts (stats.libretexts.org) and licensed under CC BY-SA 4.0. Changes were made. License: CC-BY-SA-4.0.