Least-Squares Regression
Finding the one line that fits a scatter of points best — and reading what its slope and intercept actually mean.
Which straight line is the best one?
Plot two related measurements against each other and you usually get a cloud of dots that almost follows a straight line, but never exactly. So which straight line is the best one to draw through it? There are infinitely many lines to choose from, so we first need a rule that turns the vague word best into something we can actually compute.
For any candidate line and any point, there is a residual: the vertical gap between the point and the line, \(e_i = y_i - \hat y_i\). Points above the line have a positive residual, points below have a negative one. The least-squares rule says: square every residual, add them all up, and pick the line that makes that total as small as possible.
Why square? Squaring makes every miss positive, so the gaps above and below cannot cancel out, and it punishes big misses far more than small ones — so the winning line refuses to stray far from any point.
The slope and intercept have simple formulas
You do not have to test infinitely many lines by hand — calculus pins down the exact answer, and it depends only on things you already know: the correlation \(r\), the two standard deviations \(s_x\) and \(s_y\), and the two means \(\bar x\) and \(\bar y\).
The slope is just the correlation rescaled from standard-deviation units back into the real units of the data. The intercept is then fixed by forcing the line to pass through the point of averages \((\bar x, \bar y)\) — the least-squares line always goes through that balance point.
Reading the slope, the intercept, and a prediction
Once you have \(\hat y = b_0 + b_1 x\), the two numbers tell the story:
- The slope \(b_1\) is a rate: for each one-unit increase in \(x\), the predicted \(y\) changes by \(b_1\) units. A slope of 14 means the line predicts 14 more units of \(y\) for every extra unit of \(x\).
- The intercept \(b_0\) is the predicted \(y\) when \(x = 0\). It carries a real-world meaning only when \(x = 0\) actually sits inside the range of your data; otherwise it is just where the line happens to cross the vertical axis.
To predict, drop an \(x\) into the equation and read off \(\hat y\). That is the whole job of a regression line: a rule that turns an \(x\) into a best-guess \(y\).
- Stay in range. A line fit on \(x\) values from 10 to 30 says nothing trustworthy about \(x = 100\). Predicting far outside the data is extrapolation, and it can be badly wrong.
- A line is not a cause. A tight fit shows that \(x\) and \(y\) move together; it does not show that changing \(x\) makes \(y\) change. Correlation is not causation.
- Straight lines only. Least squares fits the best straight line even when the true pattern is curved, so always look at the scatter, not just the numbers.
- Slope: \(b_1 = r\,\dfrac{s_y}{s_x} = 0.9 \times \dfrac{80}{5} = 0.9 \times 16 = 14.4\).
- Intercept: \(b_0 = \bar y - b_1\,\bar x = 300 - 14.4 \times 20 = 300 - 288 = 12\).
- So the line is \(\hat y = 12 + 14.4\,x\). Reading the slope: each extra 100 sq ft is associated with about 14.4 thousand dollars more predicted price.
- A 2500-square-foot home means \(x = 25\): \(\hat y = 12 + 14.4 \times 25 = 12 + 360 = 372\).
Check your understanding
- The least-squares regression line yhat = b0 + b1x is the single line that minimizes the sum of the squared residuals.
- Slope: b1 = r·sy/sx, the correlation rescaled into the data's real units. Intercept: b0 = ybar − b1·xbar, which forces the line through the point of averages (xbar, ybar).
- The slope is a rate: predicted y changes by b1 for each one-unit change in x.
- The intercept is the predicted y at x = 0 — meaningful only when x = 0 lies within the data's range.
- Predict by plugging an x into the equation, but avoid extrapolating far beyond the data, and remember a fitted line shows association, not causation.