Least-Squares Regression
Many lines can run through a scatterplot. Which one should you use? Learn how least squares chooses a line, use technology to find it, and explain what its coefficients and model fit mean in a real situation.
By the end of this lesson, you should be able to:
- Explain what the least-squares line minimizes and identify the mean point it passes through.
- Use technology to find the fitted equation and distinguish the intercept, slope and correlation.
- Interpret slope, intercept and the coefficient of determination in context.
Before you start: Review linear regression models and residuals. A residual is an actual response minus its prediction.
First time learning this? Follow the delivery data from scatterplot to fitted line, then read the output and interpretation examples.
Here to revise? Use the coefficient checklist, then attempt the practice before opening solutions.
The concept in 60 seconds
The least-squares regression line is the line that makes the sum of squared residuals as small as possible for the observed data. Its usual prediction form is:
The intercept gives the predicted response when . The slope tells you how much the predicted response changes for each additional unit of .
We square each vertical prediction error before adding. This prevents positive and negative residuals from canceling and gives larger misses more weight.
Best for a specific purpose: “Best” here means the smallest sum of squared residuals among straight lines. It does not guarantee that a line is an appropriate model or that every prediction is accurate.
Quick check: does the least-squares line have to pass through every point?
No. It balances the squared misses across the whole data set. When an intercept is included, it does pass through the mean point .
A real situation: choosing a delivery-time line
A delivery team records distance in kilometres and time in minutes for invented deliveries. These are the same teaching data used in Topics 5.3 and 5.4.
| Delivery ID | Distance (km) | Observed time (min) |
|---|---|---|
| A | ||
| B | ||
| C | ||
| D | ||
| E | ||
| F | ||
| G | ||
| H | ||
| I |
Technology gives the least-squares line:
The means are km and minutes. The line predicts minutes at the mean distance, so it passes through .
Circles are observed deliveries. The line predicts time from distance. The highlighted mean point lies on the fitted line, even though it need not be an observed delivery.
These data were constructed to make the arithmetic easy; their exceptionally close fit is not typical of all real delivery data. Use the observed distance range, , when judging whether a prediction or interpretation is supported.
Key ideas and notation
Response and prediction
is an observed response; is the response predicted at the same . The hat matters.
Intercept:
The predicted response at . Its units are the response units.
Slope:
The change in predicted response per unit increase in . Its units are response units per explanatory unit.
Residual:
The signed vertical difference . Least squares uses to compare lines.
Correlation:
A unitless measure of the direction and strength of linear association. It is not the slope.
Coefficient of determination:
The proportion of variation in the response explained by its linear relationship with the explanatory variable.
Watch the output convention: some calculators label slope and intercept in the form . Others use . Identify coefficients from the displayed equation rather than memorizing which letter is the slope.
What least squares minimizes
For each observation, calculate the residual, square it, then add all squared residuals. We call this total the sum of squared errors, or .
The index simply labels an observation, and is the number of observations. For the delivery line, the residuals in minutes are:
There are residuals of magnitude and one of , giving square minutes. The signed residuals add to , but the squared errors do not.
| Candidate equation | (min) | What changes? |
|---|---|---|
| Least-squares fit | ||
| Same slope, higher intercept | ||
| Steeper line through the same mean point |
The fitted line has the smallest squared-error total. The other candidates illustrate why changing either the height or slope can increase the total. Squared-error units are square minutes.
Checking these candidates illustrates the rule; technology has found the minimum over all straight lines with an intercept. The line also passes through , so passing through the mean point alone does not prove a line is the least-squares line.
Vertical, not perpendicular: errors are measured in the response direction at the same explanatory value. The criterion is not shortest slanted distances, total absolute residuals, or the sum of signed residuals.
With an intercept and nonconstant explanatory values, the fitted line passes through and its residuals sum to , apart from rounding. Swapping and changes the prediction task and generally produces a different line.
Interpret the slope and intercept
Slope: a change in predicted response
For , the slope is minutes per kilometre.
For each additional kilometre of delivery distance, the model predicts an increase of minutes in delivery time, on average.
This describes the change in the prediction. It does not mean every pair of deliveries differs by exactly that amount, or that distance is the only cause of travel time. Over an increase of km, the predicted change is minutes.
Intercept: the prediction at zero
The intercept is minutes: the model predicts a delivery time of minutes at a distance of km.
However, km is outside the observed range . The intercept helps position the fitted line, but the data do not support interpreting it as an established loading time or a reliable zero-distance delivery time.
Meaningfulness check: Is sensible in the situation? Is it within or reasonably near the observed range? Is the predicted response logically possible? Explain any limitation instead of inventing a story for the intercept.
What if the slope is negative?
Say the predicted response decreases. For a hypothetical battery model , where is hours of use and is charge percentage, an additional hour predicts a decrease of percentage points in charge. This is a change in percentage points, not a relative decrease of .
Understand the coefficient of determination
In simple least-squares regression with an intercept, is the square of the correlation. It describes the proportion of variation in observed responses, about their mean, explained by the fitted linear relationship.