Statistics & Probability · Grades 10, 11
The Least-Squares Regression Line
Quick answer
The least-squares regression line is the line through a scatter plot that makes the sum of the squared residuals as small as possible. Its slope is b = Σ(x − x̄)(y − ȳ)/Σ(x − x̄)², equivalently r·s_y/s_x, and it always passes through the point of means (x̄, ȳ). The slope is the predicted change in y for each unit of x. R², the square of the correlation, is the fraction of the variation in y the line explains. Predictions are trustworthy only inside the range of the data.
What you'll learn
- Compute the slope and intercept of the least-squares line
- Explain what 'least squares' minimizes
- Interpret the slope, the intercept and R² in context
- Recognize the danger of extrapolation
The line that misses least
Five students record hours studied, , and test score, :
| (hours) | |||||
|---|---|---|---|---|---|
| (score) |
Many lines pass near these points. A residual measures how far a line misses one point, vertically: . The least-squares regression line is the one line that makes the sum of the squared residuals as small as possible.
Its slope and intercept have formulas:
For the data, and . The deviations of are and of are . So and . The slope is and the intercept is :
- ŷ = 50 + 6x
Why squares, and why the line passes through the means
Squaring makes every residual count as positive, so misses above and below cannot cancel. It also punishes large misses more than small ones, so the line will not ignore a point to fit the others perfectly.
Minimizing a sum of squares is a calculus problem with two unknowns, and . Setting the partial derivative with respect to to zero gives : the residuals of the best line add to zero, which rearranges to . So the line always passes through . Here the residuals are , which do add to . Setting the other derivative to zero gives the formula for .
Slope from the correlation
The slope can also be written with summary statistics:
For the data, , and , so . In words: a change of one standard deviation in predicts a change of standard deviations in .
How good is the fit?
, the square of the correlation, is the fraction of the variation in that the line explains. The total variation is . What the line leaves unexplained is the sum of squared residuals, . So
About of the variation in scores is explained by hours studied.
Worked examples
Common mistakes
Practice problems
-
Find the least-squares line for and .
Answer
Full solution
, . The products of deviations add to , and , so and .
-
Find the least-squares line for and .
Answer
Full solution
, . The products of deviations add to , and , so and .
-
Given , and , find the slope.
Answer
Full solution
.
-
A line has slope and passes through the point of means . Find its intercept.
Answer
Full solution
.
-
Find the residuals for the line and the five students’ data, and check that they add to zero.
Answer
; sum
Full solution
Predictions are . Subtracting from gives the residuals.
-
A regression of house price on size has . What is if the relationship is positive, and what does mean?
Answer
; size explains of the variation in price.
Full solution
, positive because larger houses cost more. The other of the variation comes from other factors.
-
The line predicts a score of for hours. Why should this prediction not be trusted?
Answer
It is an extrapolation far outside the data, and it gives an impossible score.
Full solution
The data cover to hours. Scores must level off at the maximum, so the straight-line pattern cannot continue to hours.
-
A student finds the line for predicting hours from score by flipping to . Why is this wrong?
Answer
Predicting from minimizes horizontal misses, a different line; its slope is , not .
Full solution
. The two lines agree only when the points lie exactly on a line, .
Frequently asked questions
What is the least-squares regression line?
The line that minimizes the sum of the squared residuals, the vertical distances from the data points to the line. It is written ŷ = a + bx.
What is the formula for the slope?
b = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)², which equals r · s_y / s_x, where r is the correlation and s_x and s_y are the standard deviations.
How do you find the intercept?
The line passes through the point of means, so a = ȳ − b·x̄.
What does R² mean?
The fraction of the variation in y that the line explains. An R² of 0.97 means 97 percent of the variation in y is accounted for by its linear relationship with x.
Why is extrapolation risky?
The line describes the data's pattern only over the range of x that was observed. Outside that range the relationship may bend, level off or break down.
Standards alignment
This lesson covers the following Common Core State Standards for Mathematics.
- CCSS.MATH.CONTENT.HSS.ID.B.6Interpreting Categorical and Quantitative DataRepresent data on two quantitative variables on a scatter plot, and describe how the variables are related.
- CCSS.MATH.CONTENT.HSS.ID.B.6aInterpreting Categorical and Quantitative DataFit a function to the data; use functions fitted to data to solve problems in the context of the data.
- CCSS.MATH.CONTENT.HSS.ID.C.7Interpreting Categorical and Quantitative DataInterpret the slope (rate of change) and the intercept (constant term) of a linear model in the context of the data.
- CCSS.MATH.CONTENT.HSS.ID.C.8Interpreting Categorical and Quantitative DataCompute (using technology) and interpret the correlation coefficient of a linear fit.