From the free course AP Statistics on Lykke
5.5 Least-Squares Regression
Key concepts: Least-squares criterion — the line minimizing the sum of squared residuals · The LSRL always passes through the point (x̄, ȳ) · Slope b = r · s_y / s_x, found with technology · Slope in context — predicted change in y per one-unit increase in x · y-intercept in context — predicted y at x = 0, sometimes not meaningful · Coefficient of determination r² — share of variation in y explained by x
The "best-fit" line in linear regression is not a subjective choice or a visual guess; it is the result of a precise mathematical optimization called the least-squares criterion.
The "best-fit" line in linear regression is not a subjective choice or a visual guess; it is the result of a precise mathematical optimization called the least-squares criterion. While many lines could potentially pass through a cloud of data points, the least-squares regression line (LSRL) is the unique line that minimizes the sum of the squared residuals ($\sum e^2$). By squaring the vertical distances between the observed data points and the predicted values, the model penalizes large deviations more heavily and ensures that positive and negative residuals do not simply cancel each other out.
The Least-Squares Criterion
To understand why we square the residuals, imagine a scatterplot where every point is connected to a candidate line by a vertical string. The length of that string is the residual ($y - \hat{y}$). If we simply minimized the sum of the residuals, any line passing through the "center" of the data would result in a sum of zero, because the positive and negative distances would offset. By squaring these lengths, we turn them into areas of physical squares. The LSRL is the specific line positioned such that the total area of all these squares is as small as possible.
The Regression Equation
The LSRL is expressed in the form $\hat{y} = a + bx$, where $\hat{y}$ (pronounced "y-hat") represents the predicted value of the response variable for a given value of the explanatory variable $x$.
- The $y$-intercept ($a$): This is the predicted value of $y$ when $x = 0$. In many contexts, such as predicting a house's price based on its square footage, the intercept may not have a meaningful physical interpretation (a house with 0 square feet is not a house), but it is mathematically necessary to anchor the line.
- The slope ($b$): This is the most critical component for interpretation. The slope describes the predicted change in the response variable for every one-unit increase in the explanatory variable.
Interpretation Template for Slope ($b$): "For every additional [unit] increase in [explanatory variable $x$], the model predicts an average [increase/decrease] of [$b$ units] in [response variable $y$]."
Calculating the LSRL from Summary Statistics
You do not always need the raw data to find the equation of the LSRL. If you know the mean and standard deviation of both variables, along with their correlation, you can calculate the slope and intercept directly using Skill 3.B:
- Calculate the slope ($b$): $b = r \left( \frac{s_y}{s_x} \right)$. This formula reveals that the slope is a product of the correlation ($r$) and the ratio of the variabilities ($s_y / s_x$). If the variables are scaled differently, the slope adjusts accordingly.
- Calculate the intercept ($a$): $a = \bar{y} - b\bar{x}$. This formula is derived from a fundamental property of the LSRL: the line always passes through the point of averages, $(\bar{x}, \bar{y})$.
Interpreting Computer Output
In professional practice and on the AP Exam, regression models are often generated by software (like Minitab or Desmos). Interpreting this output (Skill 4.D) requires identifying specific values within a "Coefficients" table.
| Predictor | Coef (Coefficient) | SE Coef | T | P |
|---|---|---|---|---|
| Constant | 12.50 ($a$) | 1.20 | 10.42 | 0.000 |
| Square Footage | 0.15 ($b$) | 0.02 | 7.50 | 0.000 |
In the table above, the "Constant" row provides the $y$-intercept ($a = 12.50$), and the row labeled with the explanatory variable name provides the slope ($b = 0.15$). The resulting equation would be $\widehat{\text{Price}} = 12.50 + 0.15(\text{SqFt})$.
Misconception Check: Slope vs. Correlation
A common error is treating the slope ($b$) and the correlation ($r$) as interchangeable. While they always share the same sign (positive or negative), they represent different concepts. Correlation measures the strength and direction of a linear relationship and is unitless. The slope measures the rate of change and is expressed in units of $y$ per unit of $x$. A very strong correlation ($r = 0.99$) can exist for a line with a very shallow slope ($b = 0.001$).
Contextual Example: Battery Life
Suppose a researcher studies the relationship between the age of a smartphone (in months, $x$) and its maximum battery capacity (in percentage, $y$). The resulting LSRL is $\hat{y} = 98 - 0.8x$.
- Intercept (98): The model predicts that a brand-new phone (0 months old) has a capacity of 98%.
- Slope (-0.8): For every 1-month increase in the age of the phone, the model predicts an average decrease of 0.8% in battery capacity.
Interpretation Check: Using the battery life model $\hat{y} = 98 - 0.8x$, what is the predicted battery capacity for a phone that is 10 months old? Does a slope of -0.8 imply that every phone loses exactly 0.8% capacity every month?
