Skip to main content

Least-squares regression and prediction (QCE General Mathematics Unit 3)

Syllabus dot point

“Fit a least-squares line y = mx + c to bivariate numerical data using technology and using m = r(s_y / s_x) and c = y-bar - m x-bar, interpret the slope and y-intercept in context, distinguish between interpolation and extrapolation, use the line to make predictions, and recognise and explain the potential dangers of extrapolation”

15 min read

Quick answer

The least-squares line y=mx+cy = mx + c minimises the sum of the squared residuals. Find it with the calculator's regression mode, or from m=rsysxm = r\frac{s_y}{s_x} and c=yˉ−mxˉc = \bar{y} - m\bar{x}; it passes through (xˉ,yˉ)(\bar{x}, \bar{y}). The slope is the predicted change in yy for each one-unit increase in xx; the intercept is the predicted yy at x=0x = 0 and is often meaningless. Predictions inside the data range (interpolation) are generally reliable; predictions outside it (extrapolation) can be badly wrong and must always be flagged.

Jump to a section
  1. What this dot point is asking
  2. The answer
  3. Exam-style questions
  4. Practice questions

What this dot point is asking

Once a scatterplot shows a linear association between two numerical variables, you model it with a straight line and use the line to predict. The QCAA General Mathematics 2025 syllabus (Unit 3, Topic 2, Bivariate data analysis 2, "Fitting a linear model to numerical data") asks you to

  • fit a least-squares line y=mx+cy = mx + c using technology (your calculator's statistics mode),
  • understand and use m=rsysxm = r\dfrac{s_y}{s_x} and c=yˉ−mxˉc = \bar{y} - m\bar{x} to find the line from summary statistics,
  • interpret the slope and yy-intercept in context,
  • distinguish between interpolation and extrapolation,
  • use the line to make predictions, and
  • recognise and explain the dangers of extrapolation.

Residual plots, the other part of this sub-topic, have their own page, and so does association and causation. In the external assessment you have a scientific calculator, which can run a linear regression from raw data in its statistics mode.

The answer

Explanatory and response variables

The explanatory variable (xx, horizontal axis) is the one you think explains or predicts the other; the response variable (yy, vertical axis) is the one being predicted. Hours of training explains run time, temperature explains ice-cream sales, age explains height. Getting this the right way round matters: regressing yy on xx gives a different line from regressing xx on yy.

The least-squares line

For any line drawn through a scatterplot, each point has a residual: the vertical distance from the point to the line, y−y^y - \hat{y} (observed minus predicted). The least-squares line is the one line that makes the sum of the squared residuals as small as possible. In QCAA notation it is written

y=mx+c,y = mx + c,

where mm is the slope (gradient) and cc is the yy-intercept. Always write it with the variable names in context, for example time=−0.655×hours+32.69\text{time} = -0.655 \times \text{hours} + 32.69.

Using the calculator

Put the calculator into its statistics (two-variable or linear regression) mode, enter the xx values in one column and the matching yy values in the other, and read off the regression coefficients. Two cautions:

  • Many scientific calculators write the line as y=a+bxy = a + bx or y=A+Bxy = A + Bx, so the letter called aa or AA is the intercept and bb or BB is the slope. Check which is which before you copy them into y=mx+cy = mx + c.
  • The same screen gives rr. Write it down: you need it to judge how good the model is.

Round the coefficients sensibly (usually to 3 or 4 significant figures) and keep more precision in any follow-up calculation.

From summary statistics

When you are given the means, standard deviations and rr instead of the raw data, use

m=rsysx,c=yˉ−mxˉ,m = r\frac{s_y}{s_x}, \qquad c = \bar{y} - m\bar{x},

where rr is the correlation coefficient, sxs_x and sys_y are the (sample) standard deviations of the xx and yy values, and xˉ\bar{x} and yˉ\bar{y} are the means. Three facts follow from these formulas:

  • The slope has the same sign as rr (standard deviations are positive).
  • The line always passes through the mean point (xˉ,yˉ)(\bar{x}, \bar{y}), because rearranging c=yˉ−mxˉc = \bar{y} - m\bar{x} gives yˉ=mxˉ+c\bar{y} = m\bar{x} + c.
  • A weaker correlation gives a flatter line for the same spreads: the slope is "shrunk" by the factor rr.

Interpreting the slope and intercept

Use a template and put the context in:

  • Slope. "For each increase of 1 [unit of xx] in [xx variable], the [yy variable] is predicted to increase (or decrease) by [∣m∣|m| units of yy]."
  • yy-intercept. "When [xx variable] is 0, the predicted [yy variable] is [cc units]." Then judge it: if x=0x = 0 is far outside the data or is impossible in context, say the intercept has no practical meaning.

Words like "predicted", "on average" or "is associated with" matter: the line describes a trend, not a law, and it does not prove that xx causes yy.

Making predictions

Substitute the xx value into the equation. For the run-time model y=−0.655x+32.69y = -0.655x + 32.69, 7 hours of training gives y=−0.655×7+32.69≈28.1y = -0.655 \times 7 + 32.69 \approx 28.1 minutes.

Interpolation and extrapolation

  • Interpolation is predicting for an xx value within the range of the data. It is generally reliable, especially when the association is strong.
  • Extrapolation is predicting for an xx value outside the range of the data. It assumes the linear pattern continues where there is no data to support it.

Least-squares line with interpolation and extrapolation regionsScatterplot of hours of training per week, from 2 to 11, against time for a 5 km run in minutes, from about 25.8 to 31.8. The points fall from left to right. The least-squares line y equals minus 0.655 x plus 32.69 is drawn solid between x equals 2 and x equals 11, the interpolation region, and dashed outside it, the extrapolation regions.0258112426283032hours of training per week5 km time (min)interpolation: 2 to 11 hoursy = -0.655x + 32.69extrapolationSolid: inside the data range. Dashed: outside it, where the model is untested.

The dangers of extrapolation

Extrapolation can go badly wrong because:

  • The pattern may change. Relationships that look linear over a small range often curve, level off or reverse outside it. Training improves run times, but not without limit.
  • The prediction can be impossible. The run-time line predicts a 5 km time of about 3.2 minutes at 45 hours of training a week, and a negative time beyond about 50 hours.
  • Conditions change over time. Forecasting a future year from past trends (time-series extrapolation) assumes nothing about the situation changes.

Extrapolating a little beyond the data (for example one year ahead in a steady trend) is common and can be reasonable, but you must always label it as extrapolation and say it is less reliable.

How reliable is a prediction?

A prediction is more trustworthy when

  1. it is an interpolation,
  2. the association is strong (rr close to ±1\pm 1, so R2R^2 is close to 1: a high proportion of the variation in yy is explained by xx),
  3. the residual plot shows no pattern, so a straight line is an appropriate model, and
  4. the data set is reasonably large and contains no influential outliers.

Coding time

When xx is a year, code it as "years since" a starting year (for example x=1x = 1 for 2019). Using 2019 directly gives a huge negative intercept that is hard to interpret and easy to mis-key. State your coding in words; the marker needs it to follow your intercept and your forecast.

Key fact

Least-squares line: y=mx+cy = mx + c, from the calculator's regression mode or from m=rsysxm = r\dfrac{s_y}{s_x} and c=yˉ−mxˉc = \bar{y} - m\bar{x}. It passes through (xˉ,yˉ)(\bar{x}, \bar{y}) and its slope has the sign of rr. Slope: predicted change in yy per one-unit increase in xx. Intercept: predicted yy at x=0x = 0 (often meaningless). Interpolation (inside the data range) is generally reliable; extrapolation (outside it) is not.

Worked examples: fitting, interpreting and predicting

1. Fitting a line with the calculator

Hours of training per week, xx: 2, 3, 5, 6, 8, 9, 11. Time for a 5 km run, yy (min): 31.8, 30.2, 30.0, 28.1, 27.9, 26.2, 25.8. Find the least-squares line and rr.

Variables
Training explains run time, so xx = hours of training, yy = time (min).
Calculator
Linear regression gives intercept 32.68832.688, slope −0.65495-0.65495, r=−0.9671r = -0.9671.
Answer
time=−0.655×hours+32.69\text{time} = -0.655 \times \text{hours} + 32.69, with r≈−0.967r \approx -0.967: a strong, negative, linear association.

Marker's note: the calculator may show a=32.688a = 32.688 and b=−0.65495b = -0.65495. Here aa is the intercept, not the slope.

2. The same line from summary statistics

For the training data, xˉ=6.2857\bar{x} = 6.2857, sx=3.2514s_x = 3.2514, yˉ=28.5714\bar{y} = 28.5714, sy=2.2021s_y = 2.2021 and r=−0.96705r = -0.96705. Verify the equation using the syllabus formulas.

Slope
m=rsysx=−0.96705×2.20213.2514≈−0.655m = r\frac{s_y}{s_x} = -0.96705 \times \frac{2.2021}{3.2514} \approx -0.655.
Intercept
c=yˉ−mxˉ=28.5714−(−0.65496)(6.2857)≈32.69c = \bar{y} - m\bar{x} = 28.5714 - (-0.65496)(6.2857) \approx 32.69.
Answer
y=−0.655x+32.69y = -0.655x + 32.69, the same line as Example 1.

Marker's note: use the unrounded slope when you calculate cc. With m=−0.66m = -0.66 you would get c=32.72c = 32.72.

3. Interpreting the slope and intercept

Interpret the slope and yy-intercept of time=−0.655×hours+32.69\text{time} = -0.655 \times \text{hours} + 32.69.

Slope. For each extra hour of training per week, the predicted 5 km time decreases by about 0.655 minutes (about 39 seconds).

Intercept. A runner who does no training is predicted to take about 32.7 minutes. Zero hours is just outside the data (2 to 11 hours), so this is a small extrapolation; it is plausible, but it is not supported directly by the data.

4. Interpolation and extrapolation

Use the model to predict the run time for 7 hours and for 20 hours of training a week, and comment on each.

7 hours. y=−0.655×7+32.69≈28.1y = -0.655 \times 7 + 32.69 \approx 28.1 min. Interpolation (7 lies within 2 to 11), and r≈−0.967r \approx -0.967 is strong, so this is reliable.

20 hours. y=−0.655×20+32.69≈19.6y = -0.655 \times 20 + 32.69 \approx 19.6 min. Extrapolation (20 is well above 11). The improvement from training is unlikely to keep going at the same rate, so this prediction is unreliable.

5. Coding the year

Museum visitors (thousands) from 2019 to 2024: 12.4, 13.1, 14.3, 14.8, 16.0, 16.5. Forecast the visitors in 2026.

Code
x=1x = 1 for 2019, so 2024 is x=6x = 6 and 2026 is x=8x = 8.
Fit
y=0.849x+11.55y = 0.849x + 11.55, r≈0.994r \approx 0.994.
Forecast
y=0.849×8+11.55≈18.3y = 0.849 \times 8 + 11.55 \approx 18.3, about 18 300 visitors.
Comment
The trend is very strong, but 2026 is two years beyond the data, so this is extrapolation and should be treated as an estimate.

6. When the intercept is meaningless

A pool's weekly visitors, VV, are modelled by V=42T−520V = 42T - 520 for maximum temperatures TT from 18 °C to 34 °C. Interpret the intercept and predict for T=10T = 10.

Intercept. At 0 °C the model predicts −520-520 visitors: impossible, and 0 °C is far outside the data, so the intercept has no practical meaning. It simply fixes the height of the line.

Prediction. V=42×10−520=−100V = 42 \times 10 - 520 = -100: impossible again. Extrapolating below 18 °C breaks the model.

Common traps
Swapping the calculator's aa and bb
On many calculators aa is the intercept and bb the slope. Check against the scatterplot: a falling pattern must have a negative slope.
Interpreting without context
"The slope is −0.655-0.655" earns little. Say what increases, by how much, and in what units.
Treating the intercept as always meaningful
If x=0x = 0 is outside the data or impossible, say so.
Not labelling extrapolation
Every prediction outside the data range must be called extrapolation, with a comment on reliability.
Rounding mm before finding cc
Use the full value of mm in c=yˉ−mxˉc = \bar{y} - m\bar{x}.
Using the wrong variable as xx
The explanatory variable goes on the horizontal axis and into the calculator's xx column.
Claiming causation
A strong line shows association, not that xx causes yy.
Exam technique

For a regression question: (1) name the explanatory and response variables; (2) write the equation with variable names, coefficients to about 3 or 4 significant figures; (3) substitute and show the working for each prediction; (4) label each prediction interpolation or extrapolation and comment on reliability using rr (or R2R^2), the residual plot and the data range. For a "justify" or "evaluate" question, finish with a clear conclusion sentence.

Note

If you plot points that roughly follow a straight line, the least-squares line is the "best" straight line through them: it is as close as possible to all the points at once. You can then use it to guess values you did not measure. Guessing in between the points you have (interpolation) usually works well. Guessing far beyond them (extrapolation) is risky, because the pattern might change, like assuming a child who grew 6 cm a year will be 3 metres tall by age 40.

Exam-style questions

Questions in the style of QCAA exam questions on this dot point, each with a worked answer. They are written by ExamExplained unless tagged "Past paper"; the year shows the paper a question is modelled on.

Practice3 marks
The table shows the number of sales for a small business in their first six months of trading. Time in months, t: 1, 2, 3, 4, 5, 6. Number of sales, n: 86, 180, 160, 226, 240, 335. a) Use your calculator to determine the equation of the least-squares line. [1 mark] b) Use the equation from part a) to predict the number of sales in the 21st month. [2 marks]
Show worked answer →

a) Fit the line (1 mark). Enter tt as the explanatory variable and nn as the response variable in the calculator's two-variable statistics (linear regression) mode: n=42.6t+55.4n = 42.6t + 55.4.

b) Predict (2 marks). Substitute t=21t = 21 (1 mark): n=42.6×21+55.4=894.6+55.4=950n = 42.6 \times 21 + 55.4 = 894.6 + 55.4 = 950. The model predicts about 950 sales in the 21st month (1 mark).

This is extrapolation far beyond months 1 to 6, so the prediction is unreliable: a new business's early growth rarely continues in a straight line for almost two years.

Practice4 marks
The table shows the profit made each year (in thousands of dollars) by a small business. Year: 2015, 2016, 2017, 2018, 2019, 2020. Profit ($'000s): 42.1, 36.9, 48.4, 52.3, 56.1, 59.8. a) Use a mathematical model to determine the equation of the least-squares line to fit this data. [2 marks] b) Use the least-squares line to forecast the profit in 2021, to the nearest hundred dollars. [2 marks]
Show worked answer →

a) Fit the line (2 marks). Define the variables (1 mark): let xx be the number of years since 2014 (so 2015 is x=1x = 1) and yy the annual profit in $'000s. Linear regression gives y=4.286x+34.267y = 4.286x + 34.267 (1 mark).

b) Forecast (2 marks). For 2021, x=7x = 7 (1 mark): y=4.286×7+34.267≈64.269y = 4.286 \times 7 + 34.267 \approx 64.269. The forecast profit is about $64 300 (1 mark).

The marks reward defining xx clearly (the choice of starting year fixes the intercept) and converting the $'000s answer back into dollars at the required rounding.

Practice4 marks
The least-squares line has been provided for a scatterplot showing the association between an employee's years of experience, n, and their hourly pay, p. a) Given that the least-squares line passes directly through the points (2, 20) and (7, 40), determine its equation. [2 marks] b) Use the equation from part a) to predict the hourly pay of an employee with 15 years experience. [2 marks]
Show worked answer →

a) Equation (2 marks). Slope (1 mark): m=40−207−2=4m = \frac{40 - 20}{7 - 2} = 4. Through (2,20)(2, 20): 20=4×2+c20 = 4 \times 2 + c, so c=12c = 12 and p=4n+12p = 4n + 12 (1 mark).

b) Predict (2 marks). p=4×15+12=72p = 4 \times 15 + 12 = 72 (1 mark). An employee with 15 years of experience is predicted to earn about $72 per hour (1 mark).

If 15 years is beyond the plotted range this is extrapolation, so flag the prediction as less reliable. The slope means pay rises by about $4 per hour for each extra year of experience.

Original4 marks
For a group of Year 12 students, the weekly hours of part-time work, xx, and the exam score (%), yy, have xˉ=9.5\bar{x} = 9.5, sx=4.8s_x = 4.8, yˉ=71.2\bar{y} = 71.2, sy=11.5s_y = 11.5 and r=−0.62r = -0.62. (a) Use m=rsysxm = r\frac{s_y}{s_x} and c=yˉ−mxˉc = \bar{y} - m\bar{x} to determine the equation of the least-squares line. (b) Interpret the slope in context. (c) Predict the score of a student who works 12 hours a week.
Show worked answer →

(a) m=−0.62×11.54.8≈−1.485m = -0.62 \times \frac{11.5}{4.8} \approx -1.485. (1 mark) c=71.2−(−1.4854)(9.5)≈85.31c = 71.2 - (-1.4854)(9.5) \approx 85.31. (1 mark) So y=−1.485x+85.31y = -1.485x + 85.31.

(b) For each extra hour of part-time work per week, the predicted exam score falls by about 1.5 percentage points. (1 mark)

(c) y=−1.485×12+85.31≈67.49y = -1.485 \times 12 + 85.31 \approx 67.49, a predicted score of about 67%. (1 mark)

Keep full precision for mm when finding cc; rounding mm to −1.5-1.5 first gives c=85.45c = 85.45. The association is only moderate (r=−0.62r = -0.62), so predictions are rough.

Original5 marks
Arm span, aa (cm), and height, hh (cm), were measured for eight people. Arm span: 152, 158, 163, 167, 171, 176, 181, 188. Height: 155, 160, 162, 170, 169, 178, 180, 186. (a) Use your calculator to determine the least-squares line and rr. (b) Predict the height of a person with an arm span of 165 cm, and comment on the reliability. (c) A basketballer has an arm span of 210 cm. Explain why the model's prediction for them should be treated with caution.
Show worked answer →

(a) Arm span is the explanatory variable. h=0.886a+19.88h = 0.886a + 19.88, r≈0.987r \approx 0.987. (2 marks)

(b) h=0.886×165+19.88≈166.1h = 0.886 \times 165 + 19.88 \approx 166.1, so about 166 cm. (1 mark) This is interpolation (165 lies within 152 to 188) and the association is very strong (r≈0.987r \approx 0.987, R2≈0.974R^2 \approx 0.974), so the prediction is reliable. (1 mark)

(c) 210 cm is well outside the data range (152 to 188 cm), so the prediction (about 206 cm) is extrapolation. There is no evidence the linear pattern continues for very tall people, and only eight people were measured. (1 mark)

Original4 marks
A council models the number of weekly visitors to a pool, VV, against the maximum daily temperature, TT (°C), for temperatures from 18 °C to 34 °C: V=42T−520V = 42T - 520. (a) Interpret the slope. (b) Interpret the yy-intercept and explain whether it is meaningful. (c) Predict the visitors at 26 °C and at 10 °C, and comment on each.
Show worked answer →

(a) For each 1 °C increase in maximum temperature, the model predicts 42 more weekly visitors. (1 mark)

(b) At 0 °C the model predicts −520-520 visitors. This is impossible and 0 °C is far outside the data (18 to 34 °C), so the intercept has no practical meaning. (1 mark)

(c) T=26T = 26: V=42×26−520=572V = 42 \times 26 - 520 = 572 visitors, an interpolation, so reasonably reliable. (1 mark) T=10T = 10: V=42×10−520=−100V = 42 \times 10 - 520 = -100, which is impossible; it is an extrapolation and shows the danger of using the line outside the data range. (1 mark)

Practice questions

Original practice questions graded from foundation to exam level, each with a full worked solution. Try them before revealing the solution.

foundation2 marks
For the line y=2.4x+15y = 2.4x + 15, where xx is the number of hours a shop is open on a day and yy is its daily sales in $'00s, interpret the slope and the yy-intercept.
Show worked solution →

Slope: each extra hour of opening is associated with a predicted increase of 2.4 hundred dollars ($240) in daily sales. (1 mark)

Intercept: at 0 hours of opening, predicted sales are $1500. This is not meaningful, since a closed shop makes no sales, and 0 hours is almost certainly outside the data. (1 mark)

foundation2 marks
xˉ=20\bar{x} = 20, sx=4s_x = 4, yˉ=50\bar{y} = 50, sy=6s_y = 6 and r=0.8r = 0.8. Find the equation of the least-squares line.
Show worked solution →

m=0.8×64=1.2m = 0.8 \times \frac{6}{4} = 1.2. (1 mark)

c=50−1.2×20=26c = 50 - 1.2 \times 20 = 26, so y=1.2x+26y = 1.2x + 26. (1 mark)

foundation2 marks
A least-squares line was fitted to data with xx from 5 to 40. Classify each prediction as interpolation or extrapolation: (a) x=12x = 12 (b) x=55x = 55 (c) x=38x = 38 (d) x=0x = 0.
Show worked solution →

(a) interpolation, (b) extrapolation, (c) interpolation, (d) extrapolation. (2 marks, lose 1 for each error)

core3 marks
Hours of training per week, xx: 2, 3, 5, 6, 8, 9, 11. Time for a 5 km run, yy (min): 31.8, 30.2, 30.0, 28.1, 27.9, 26.2, 25.8. (a) Find the least-squares line. (b) Predict the time for 7 hours of training.
Show worked solution →

(a) From the calculator's linear regression: y=−0.655x+32.69y = -0.655x + 32.69 (2 marks; r≈−0.967r \approx -0.967.)

(b) y=−0.655×7+32.69≈28.1y = -0.655 \times 7 + 32.69 \approx 28.1 minutes. (1 mark) This is interpolation.

core3 marks
The least-squares line for a data set passes through (xˉ,yˉ)=(12,40)(\bar{x}, \bar{y}) = (12, 40) and has slope −2.5-2.5. (a) Find its equation. (b) If sx=3s_x = 3 and sy=9s_y = 9, find rr.
Show worked solution →

(a) c=40−(−2.5)(12)=70c = 40 - (-2.5)(12) = 70, so y=−2.5x+70y = -2.5x + 70. (1 mark)

(b) m=rsysxm = r\frac{s_y}{s_x} gives −2.5=r×93=3r-2.5 = r \times \frac{9}{3} = 3r, so r=−2.53≈−0.833r = -\frac{2.5}{3} \approx -0.833. (2 marks)

exam3 marks
Annual visitors (thousands) to a museum from 2019 to 2024 were 12.4, 13.1, 14.3, 14.8, 16.0, 16.5. Using x=1x = 1 for 2019, (a) find the least-squares line, (b) forecast the visitors in 2026, and (c) give one reason the forecast may be unreliable.
Show worked solution →

(a) y=0.849x+11.55y = 0.849x + 11.55 (r≈0.994r \approx 0.994). (1 mark)

(b) 2026 is x=8x = 8: y=0.849×8+11.55≈18.34y = 0.849 \times 8 + 11.55 \approx 18.34, about 18 300 visitors. (1 mark)

(c) It is extrapolation beyond 2024, and the trend may not continue (a new exhibition, a closure or a change in tourism could change it). (1 mark)

exam3 marks
A student says: "The line y=−0.655x+32.69y = -0.655x + 32.69 predicts that with 45 hours of training a week I could run 5 km in about 3.2 minutes, so more training always makes me faster." Evaluate this claim.
Show worked solution →

The calculation is right: −0.655×45+32.69≈3.2-0.655 \times 45 + 32.69 \approx 3.2. (1 mark)

But the data only covered 2 to 11 hours, so 45 hours is extreme extrapolation. A 3-minute 5 km is physically impossible, which shows the linear pattern cannot continue: improvements level off and too much training can cause injury. (1 mark)

Conclusion: the claim is not supported. The model is only useful for predictions within (or very close to) 2 to 11 hours a week. (1 mark)

Practise this

Sources & how we know this

ExamExplained