Linear Regression
Revise Linear Regression for Further Mathematics — revision notes and instant AI marking. Free to start.
Linear Regression
Summary — What This Chapter Covers
- Least squares regression finds the line
y = a + bxthat minimises the total squared distance between the line and every data point. - Sxx, Sxy, Syy are three "helper sums" you calculate first — everything else (the gradient, the intercept, how good the fit is) is built from them.
- Interpolation vs extrapolation — predicting inside your data range is safe; predicting outside it is a guess dressed up as maths.
- Coded data lets you work with small, friendly numbers instead of huge ones, then convert your answer back using substitution.
- Residuals are the leftover gaps between what actually happened and what your line predicted — plotting them tells you if a straight line was ever the right shape to use.
- RSS (Residual Sum of Squares) turns "how good is my fit" into a single number — smaller is better.
1. Least Squares Linear Regression
Imagine you've got a scatter of points on a graph — say, temperature against reaction time. You could draw a line through them freehand, but everyone would draw it slightly differently. Least squares regression removes the guesswork: it's the one specific line that makes the total "error" between the line and the real points as small as mathematically possible.
Here's the trick to understanding *why* it's called "least squares": for every point, there's a vertical gap between where the point actually is and where the line says it should be. That gap is called a residual. Some residuals are positive (point is above the line), some are negative (point is below). If you just added them up, positives and negatives would cancel out and hide how good or bad the fit really is. So instead, you square every residual first (which also makes them all positive) and add those up. The regression line is the one specific line that makes this sum — the sum of squared residuals — as small as it can possibly be. That's the whole idea behind the name "least squares."
y is the dependent variable (the thing being predicted), x is the independent variable (the thing you already know), b is the gradient of the line, and a is the y-intercept.Sxy = Σxy − (Σx)(Σy)/n
Syy = Σy² − (Σy)²/n
b first (it only needs the helper sums), then use it to find a. Note that ȳ = Σy/n and x̄ = Σx/n are just the means of the data — and a neat fact worth remembering: the regression line always passes through the point (x̄, ȳ), the "centre of mass" of your data. That's exactly why the formula for a works — you're finding the intercept that forces the line through that centre point.Worked Example
A researcher records temperature (x, °C) against the time taken for a reaction to finish (y, seconds):
| Temp (°C) | 22.0 | 23.0 | 24.0 | 25.0 | 26.0 | 27.0 | 28.0 | 29.0 |
|---|---|---|---|---|---|---|---|---|
| Time (s) | 43.2 | 41.6 | 39.9 | 38.1 | 36.5 | 33.6 | 31.7 | 30.1 |
Given: n = 8, Σx = 204, Σx² = 5244, Σy = 294.7, Σy² = 11012.53, Σxy = 7434.
Sxx = 5244 − 204²/8 = 42
Sxy = 7434 − (204 × 294.7)/8 = −80.85
b = −80.85 / 42 = −1.925
x̄ = 204/8 = 25.5, ȳ = 294.7/8 = 36.8375
a = 36.8375 − (−1.925 × 25.5) = 85.925
So the regression line is: y = 85.9 − 1.93x (3 s.f.)
b came out negative here. That's completely fine — it just means as x increases, y decreases (hotter temperature → faster/shorter reaction time). Don't panic and assume you've made an error just because the gradient isn't positive. Always sanity-check the sign against what the context suggests.
Using Sxx = 42 and Sxy = −80.85 from above, if instead Σy = 320 and n = 8, what would ȳ be, and how would that change the value of a (keeping b = −1.925 and x̄ = 25.5)?
Interpreting a and b in Context
This is the part students lose easy marks on — examiners always ask you to explain what a and b mean in real-world terms, not just state the numbers.
- a (the intercept) is the predicted value of y when x = 0. In context: "When the temperature is 0°C, the predicted time for the reaction to complete is 85.9 seconds."
- b (the gradient) is how much y changes for every 1-unit increase in x. In context: "For every 1°C increase in temperature, the time taken for the reaction decreases by 1.93 seconds."
2. Interpolation & Extrapolation
Once you have your regression equation, you can plug in an x-value to predict y. But whether you should trust that prediction depends entirely on where that x-value sits relative to your original data.
- Interpolation — predicting a y-value for an x that falls within the range of x-values you actually collected. This is reliable, because your line was built from evidence covering that exact region.
- Extrapolation — predicting for an x outside that range. This is unreliable, because you have no evidence the same straight-line relationship still holds out there. The pattern could curve, level off, or reverse entirely beyond your data.
Worked Example (continued)
Using y = 85.9 − 1.93x, with the original data spanning x = 22.0 to 29.0:
At x = 30.0 (outside range → extrapolation): y = 85.9 − 1.93(30) = 28s. Unreliable — 30°C is beyond the highest recorded temperature (29°C), so we're assuming the relationship keeps behaving the same way, which we can't confirm.
A data set of x-values ranges from 10 to 50. Using a regression equation, would predicting y at x = 45 be interpolation or extrapolation? What about x = 55? Explain your reasoning for both.
3. Coded Data
Sometimes the real data involves huge or awkward numbers (think: national income in the billions, or measurements in nanometres). To make the arithmetic manageable, the question will "code" the data using a substitution formula — you work entirely in the coded world, then translate your final answer back using algebra.
Worked Example
Data is coded using x = 3 − s and y = −16t. The regression line for y on x is found to be y = 3x + 8.
Part (i): Find t when s = 216.
Substitute into the regression line: y = 3(−216) + 8 = −640.
Now use the coding formula for y to isolate t: −640 = −16t ⟹ t = 40.
Part (ii): Find the regression line of t on s directly.
−16t = 3(3 − s) + 8
−16t = 9 − 3s + 8 = 17 − 3s
t = (−17 + 3s) / 16 = 1.125s − 6.375 ... wait, watch the signs carefully here — this is exactly the step where students lose marks by mis-distributing negatives. Divide every term by −16 individually and double check the sign of each.
Data is coded using u = x − 100 and v = y/10. The regression line of v on u is v = 2u + 5. Find the regression line of y on x.
4. Residuals
A residual measures exactly how wrong the regression line was for one specific point. It's the difference between what actually happened (the observed y-value) and what the line predicted (the fitted y-value).
Residuals are useful for more than just checking arithmetic — they let you test whether a straight line was even the right shape of model to use in the first place. Plot each residual against its x-value (or fitted value):
- Random scatter around zero, no pattern → the linear model is suitable. This tells you the leftover "error" isn't systematic — it's just noise.
- A clear pattern (like a curve, or residuals that grow/shrink in a trend) → the linear model is not suitable. A pattern in the residuals means there's structure in the data that a straight line failed to capture — often it means the true relationship is curved.
A regression line gives y = 12 + 4x. For the data point (5, 34), calculate the residual. What does the sign of your answer tell you about where the point lies relative to the line?
5. Residual Sum of Squares (RSS)
Looking at individual residuals or a scatter plot is useful for spotting patterns, but sometimes you need a single number that summarises "how good is this fit overall" — especially when comparing two different data sets or two different models. That number is RSS.
Worked Example (continued)
Using the reaction-time data: Sxy = −80.85, Sxx = 42, and Syy = 11012.53 − 294.7²/8 = 156.51875.
A second data set has RSS = 0.43. Since 0.43 < 0.8825, the second data set is more suitable for a linear model — its smaller RSS shows the data points sit closer to their regression line, meaning less unexplained "leftover" variation.
For a data set, Sxx = 60, Sxy = 45, and Syy = 40. Calculate the RSS.
What to Memorise
Sxx = Σx² − (Σx)²/n | Sxy = Σxy − ΣxΣy/n | Syy = Σy² − (Σy)²/n. Given in the formula booklet — know how to use them, not recite them from memory.
y = a + bx, where b = Sxy/Sxx and a = ȳ − bx̄. Always find b first.
Interpolation = inside the data range = reliable. Extrapolation = outside the range = unreliable.
Substitute the coding formulas directly into the regression equation, then rearrange carefully.
residual = yi − (a + bxi). All residuals in a data set sum to exactly 0.
RSS = Syy − (Sxy)²/Sxx. Smaller RSS always means a better-fitting linear model.
Concepts Checklist
Exam Tips — Common Mistakes & Mark-Scheme Traps
a before b. You can't — the formula for a needs b already calculated. Always find Sxx and Sxy → b → x̄ and ȳ → a, in that exact order.
- 2. Interpolation & Extrapolation
- Exam Tips — Common Mistakes & Mark-Scheme Traps
Read the full Linear Regression notes free
That's the preview — create a free account to read the rest, plus flashcards and practice questions with instant AI marking. No credit card.
Unlock the full notes free →