Mostly Harmless StatisticsXYZ Homework Edition

⇩ Download ▾

12.4 Simple Linear Regression

A linear regression is a straight line that describes how the values of a response variable yy change as the predictor variable xx changes. The equation of a line, relating xx to yy 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 b0b_{0} represent the sample yy-intercept (the value of yy when x=0x = 0), b1b_{1} the sample slope (rise over run), and y^\hat{y} the predicted value of yy for a specific value of xx. The equation is written as y^=b0+b1x\hat{y} = b_{0} + b_{1}x.

Some textbooks and the TI calculators use the letter aa to represent the yy-intercept and bb to represent the slope, and the equation is written as y^=a+bx\hat{y} = a + bx. These letters are just symbols representing the placeholders for the numeric values for the yy-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.

Scatterplot titled Figure 12-9: A scatterplot of five points at (2.4, 7.5), (5.2, 7.2), (6.2, 9.5), (10, 8.7), and (12, 11.4), rising overall from lower left to upper right with the middle points scattered above and below the trend.
Figure 12-9: A scatterplot.

Figure 12-10 shows the least-squares regression line of yy on xx, 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 titled Figure 12-11: Scatterplot with Least-Squares Regression Line showing five points at (2.4, 7.5), (5.1, 7.2), (6.1, 9.5), (10, 8.7), and (12, 11.4) with the dashed least-squares line y = 0.354x + 6.341 drawn through them; three points lie above the line and two below, and only the points and the line are drawn.
Figure 12-11: Scatterplot with least-squares regression line and squared residuals.

To find the slope and yy-intercept for the equation of the least-squares regression line y^=b0+b1x\hat{y} = b_{0} + b_{1} x we use the following formulas: slope =b1=SSxySSxx= b_{1} = \frac{SS_{xy}}{SS_{xx}}, yy-intercept: b0=y¯b1x¯b_{0} = \bar{y} - b_{1} \bar{x}.

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 yy-intercept: b0=y¯b1x¯b_{0} = \bar{y} - b_{1} \bar{x}, where x¯\bar{x} = the sample mean of the xx’s and y¯\bar{y} = the sample mean of the yy’s.

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

Note: we would only want to use the regression equation for prediction if we reject H0H_{0} and find that there is a significant correlation between xx and yy. 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, https://mostlyharmlessstat.wixsite.com/webpage), © Rachel Webb, licensed under CC BY-SA 4.0. Changes were made. License: CC-BY-SA-4.0.

These eBooks are a prerelease and are not yet certified conformant with WCAG 2.1 AA or ADA Title II. Every page is built against an automated accessibility gate, and the published editions will meet ADA Title II requirements when they release in late September 2026. If something is unusable, please tell us.