Resources For Teachers For Tutors For Students & Parents AI New Books Pricing
Year 12 Maths - General (Unit 3 & Unit 4) Investigating and modelling linear associations

The least squares line

20 practice questions 0 video lessons Theory + worked examples

Learn to fit the least squares line in Year 12 VCE General Mathematics. When a scatterplot shows a linear trend, such as the air getting colder as you climb Mt Buller, one straight line \(y = a + bx\) can sum it up. The least squares line is the fairest choice, because it keeps the squared vertical gaps between the points and the line as small as possible.

You will find the intercept \(a\) and slope \(b\) two ways: with the regression mode of your calculator, and from summary statistics using \(b = r\,s_y/s_x\) and \(a = \bar{y} - b\bar{x}\). You will write the line in context, check it passes through the point of means, and then move on to interpreting what the slope and intercept tell you.

Create a free accountTrack your progress and save your work as you go.
Create free account

Theory

The least squares line \(y = a + bx\) is the straight line that best fits a scatterplot of numerical data. This Year 12 General Mathematics guide for students in Victoria shows what the line minimises, how to find its intercept \(a\) and slope \(b\) with technology or from summary statistics, and how to use the point of means as a check.

A residual is the vertical gap between a data point and a fitted line: the actual value of \(y\) minus the value the line predicts. The least squares line is the one straight line that makes the sum of the squared residuals as small as possible. Squaring stops the positive and negative gaps from cancelling, so every point counts.

The line is written \(y = a + bx\), where \(a\) is the intercept and \(b\) is the slope. The explanatory variable goes on the horizontal axis as \(x\) and the response variable on the vertical axis as \(y\), so in context the line reads \(\text{response} = a + b \times \text{explanatory}\). Swapping the variables gives a different line.

You can find the line in two ways: enter the data pairs into the two-variable statistics (linear regression) mode of a CAS or scientific calculator, or calculate it from summary statistics: the correlation coefficient \(r\), the means \(\bar{x}\) and \(\bar{y}\), and the standard deviations \(s_x\) and \(s_y\).

Key idea. The least squares line \(y = a + bx\) has the smallest possible total of squared residuals. Its slope is \(b = r\dfrac{s_y}{s_x}\), its intercept is \(a = \bar{y} - b\bar{x}\), and it always passes through the point of means \((\bar{x}, \bar{y})\).
The least squares line makes the squared residuals as small as possibleSix points with the least squares line y = 1 + 2x. Dashed vertical segments join each point to the line and shaded squares show each squared residual. x y 1 2 3 4 5 6 4 8 12 16
Each dashed segment is a residual, and each shaded square is that residual squared. The least squares line \(y = 1 + 2x\) makes the total area of the squares as small as possible.
The least squares line passes through the point of meansFive points with the least squares line y = 17.5 - 1.25x, which passes through the point of means (6, 10), marked with a gold ring. x y 2 4 6 8 10 5 10 15 20 point of means (6, 10)
The least squares line \(y = 17.5 - 1.25x\) passes through the point of means \((\bar{x}, \bar{y}) = (6, 10)\). A negative slope means \(y\) falls as \(x\) rises.

The least squares line, with intercept \(a\) and slope \(b\):

\[y = a + bx\]
y=a+bx

From summary statistics, find the slope first and then the intercept:

\[b = r\,\dfrac{s_y}{s_x}\]
b=r⁢sysx
\[a = \bar{y} - b\bar{x}\]
a=y¯-bx¯

What the calculator does with the raw data (the same slope, written with sums of deviations):

\[b = \dfrac{S_{xy}}{S_{xx}}, \quad S_{xx} = \sum (x - \bar{x})^2, \quad S_{xy} = \sum (x - \bar{x})(y - \bar{y})\]
b=SxySxx
Sign check. \(s_x\) and \(s_y\) are always positive, so the slope \(b\) always has the same sign as \(r\). Rearranging \(a = \bar{y} - b\bar{x}\) gives \(\bar{y} = a + b\bar{x}\): the point of means is always on the line.

Finding the least squares line

  1. Choose \(x\) and \(y\). The explanatory variable (the one used to predict) is \(x\); the response variable (the one being predicted) is \(y\).
  2. From raw data, use technology. Enter the pairs in the calculator's two-variable statistics (linear regression) mode and read off \(a\) and \(b\). Check which letter your calculator uses for the slope: it is the number multiplying \(x\).
  3. From summary statistics, use the formulas. Calculate \(b = r\,s_y/s_x\) first, then \(a = \bar{y} - b\bar{x}\) using the unrounded \(b\).
  4. Write the line in context. State \(y = a + bx\) with the variable names, for example \(\text{price} = 32.3 - 1.8 \times \text{age}\), rounding \(a\) and \(b\) only at the end.
Example 1 — From summary statistics
For a sample of Latrobe Valley households, the number of people in the household, \(x\), and the weekly grocery bill, \(y\) (dollars), have \(\bar{x} = 3\), \(s_x = 1.2\), \(\bar{y} = 210\), \(s_y = 45\) and \(r = 0.8\). Find the least squares line.
Solution

Find the slope from \(r\) and the standard deviations, then the intercept from the means.

\(b\)\(=\)\(r \times \dfrac{s_y}{s_x}\)
\(b\)\(=\)\(0.8 \times \dfrac{45}{1.2}\)
\(b\)\(=\)\(0.8 \times 37.5\)
\(b\)\(=\)\(30\)
\(a\)\(=\)\(\bar{y} - b\bar{x}\)
\(a\)\(=\)\(210 - 30 \times 3\)
\(a\)\(=\)\(210 - 90\)
\(a\)\(=\)\(120\)
grocery bill=120+30×people

The least squares line is \(\text{grocery bill} = 120 + 30 \times \text{people}\), with the bill in dollars.

Example 2 — Using technology
A St Kilda kiosk recorded the hours of sunshine and the number of ice creams sold on five days. Use technology to find the least squares line.
Hours of sunshine, \(x\)246810
Ice creams sold, \(y\)3041496268
Solution

Sunshine explains the sales, so sunshine is \(x\). The regression mode calculates these values:

\(S_{xx}\)\(=\)\(40\)
\(S_{xy}\)\(=\)\(194\)
\(b\)\(=\)\(\dfrac{S_{xy}}{S_{xx}}\)
\(b\)\(=\)\(\dfrac{194}{40}\)
\(b\)\(=\)\(4.85\)
\(\bar{x}\)\(=\)\(6\)
\(\bar{y}\)\(=\)\(50\)
\(a\)\(=\)\(\bar{y} - b\bar{x}\)
\(a\)\(=\)\(50 - 4.85 \times 6\)
\(a\)\(=\)\(50 - 29.1\)
\(a\)\(=\)\(20.9\)
ice creams=20.9+4.85×sunshine
Example 2 scatterplotIce creams sold against hours of sunshine, with the least squares line y = 20.9 + 4.85x. hours ice creams 2 4 6 8 10 20 40 60 80

The least squares line is \(\text{ice creams} = 20.9 + 4.85 \times \text{sunshine}\).

Example 3 — A negative slope, rounded
A hiker recorded the altitude and the air temperature at six points on a walk up Mt Buller one morning. Find the least squares line, with \(a\) and \(b\) correct to \(2\) decimal places.
Altitude, \(x\) (hundreds of m)468101214
Temperature, \(y\) (°C)15.212.910.18.45.33.6
Solution

Enter altitude as \(x\) and temperature as \(y\). Keep the unrounded slope when finding \(a\):

\(S_{xx}\)\(=\)\(70\)
\(S_{xy}\)\(=\)\(-82.5\)
\(b\)\(=\)\(\dfrac{S_{xy}}{S_{xx}}\)
\(b\)\(=\)\(\dfrac{-82.5}{70}\)
\(b\)\(\approx\)\(-1.178571\)
\(\bar{x}\)\(=\)\(9\)
\(\bar{y}\)\(=\)\(9.25\)
\(a\)\(=\)\(\bar{y} - b\bar{x}\)
\(a\)\(\approx\)\(9.25 - (-1.178571)(9)\)
\(a\)\(\approx\)\(9.25 + 10.6071\)
\(a\)\(\approx\)\(19.86\)
temperature=19.86-1.18×altitude
Example 3 scatterplotTemperature against altitude, with the least squares line y = 19.86 - 1.18x. altitude temperature 4 8 12 5 10 15 20

The least squares line is \(\text{temperature} = 19.86 - 1.18 \times \text{altitude}\). The slope is negative, matching the falling pattern of the points (and the negative \(r\)).

Example 4 — Working backwards
For members of a Ballarat cycling club, the least squares line relating weekly training distance, \(x\) (km), to average speed, \(y\) (km/h), is \(y = 24.5 + 0.05x\). The training distances have \(\bar{x} = 120\) and \(s_x = 32\), and the speeds have \(s_y = 2\). Find \(\bar{y}\) and the correlation coefficient \(r\).
Solution

The point of means lies on the line, so substitute \(\bar{x}\). Then rearrange \(b = r\,s_y/s_x\) to make \(r\) the subject.

\(\bar{y}\)\(=\)\(a + b\bar{x}\)
\(\bar{y}\)\(=\)\(24.5 + 0.05 \times 120\)
\(\bar{y}\)\(=\)\(24.5 + 6\)
\(\bar{y}\)\(=\)\(30.5\)
\(r\)\(=\)\(\dfrac{b \times s_x}{s_y}\)
\(r\)\(=\)\(\dfrac{0.05 \times 32}{2}\)
\(r\)\(=\)\(\dfrac{1.6}{2}\)
\(r\)\(=\)\(0.8\)
r=0.8

The mean speed is \(30.5\) km/h and \(r = 0.8\), a strong positive association.

Common pitfalls

Watch the calculator's letters. Some calculators show the line as \(y = ax + b\) and others as \(y = a + bx\). Match each value to its role: the number multiplying \(x\) is the slope \(b\), and the constant is the intercept \(a\).
Put the explanatory variable on \(x\). The line that predicts \(y\) from \(x\) is not the line that predicts \(x\) from \(y\), and it must not be rearranged to predict the explanatory variable. Decide which variable explains the other before you enter the data.
Use the unrounded slope for \(a\). Rounding \(b\) first and then calculating \(a = \bar{y} - b\bar{x}\) can change the second decimal place of \(a\). Round both values only at the end.

Frequently asked questions

What is the least squares line?

It is the straight line through a scatterplot that makes the sum of the squared residuals (the squared vertical gaps between the points and the line) as small as possible. It is written y = a + bx, with intercept a and slope b.

How do you find the least squares line on a calculator?

Use the two-variable statistics or linear regression mode. Enter the explanatory values as x and the response values as y, then read off the intercept and the slope. The slope is the number multiplying x, whatever letter your calculator gives it.

How do you find a and b from r and the standard deviations?

Use b = r times s_y divided by s_x for the slope. Then use a = y-bar minus b times x-bar for the intercept, keeping the unrounded slope. Finally write the line as y = a + bx.

Does the least squares line always pass through the point of means?

Yes. Because a = y-bar minus b times x-bar, substituting x = x-bar into y = a + bx gives y = y-bar, so the point (x-bar, y-bar) is always on the line.

Why are the residuals squared?

Residuals above the line are positive and those below are negative, so their plain total is always zero for this line. Squaring makes every gap count, and the line with the smallest total of squares is the least squares line.

Does it matter which variable is x?

Yes. The explanatory variable must be x and the response variable must be y. Swapping them gives a different least squares line, because the method only makes the vertical gaps small.