Space-weather services warn satellite operators a day or two before a coronal mass ejection reaches Earth, and some of their simplest forecasts rest on straight lines fitted to past storms, like the line through the ten clouds of Section D1. Those points scatter widely, and two people drawing the best line by eye would not draw quite the same one. The method of least squares gives a single line that anyone can reproduce with a table of sums and a calculator, and it gives the uncertainties of the slope and intercept from the scatter of the points. In this section we see what the method does, set out its working so that it can be done by hand in the exam, and use it to forecast the arrival of two more storms.
D6.1The line that fits best
Before you readMake a guess first
The method of least squares chooses, from all possible straight lines, the one that makes a certain quantity as small as possible. Which quantity?
It makes the sum of the squares of the distances as small as possible, which is where its name comes from. A plain sum would let points above the line cancel points below it.
For a trial line , each point lies a distance above or below it, its from Section D3. The method of least squares chooses the line that makes the sum of the squared residuals, , as small as possible. Squaring makes every residual count whether the point is above or below the line, and it makes a point twice as far away count four times as much, so the line cannot ignore a point that lies far from it. The method measures residuals up and down only, so it treats the values of as exact and puts all the uncertainty into . The quantity with the larger uncertainty therefore belongs on the vertical axis.
Figure D.6Squares on the residualsinteractive
Trial line
Sum of the squared residuals
The figure shows the average accelerations of the ten coronal mass ejections of Section D1 against their starting speeds , in units of km/s. The sliders set the slope and intercept of a trial line, drawn heavy. Each point's residual is the thin vertical stroke between the point and the line, and the square drawn on it has an area proportional to the residual squared, so the total grey area stands for the sum that least squares makes as small as possible. The table gives that sum and compares it with the least it can be. The words below set and , whose sum is only 1.01 times the least.
ResultThe least-squares line(D.6)
the slope and intercept of the line
the means of the values of and of
a sum over all the points
The line passes through the centre of the points C, at , like every line of Section D3.
Show the derivation
The sum is smallest where its derivatives with respect to and to are both zero. The derivative with respect to is , which is zero when . Putting this value of into the sum gives , whose derivative with respect to is . This is zero when , which gives .
D6.2Working it out by hand
Before you readMake a guess first
Five points have , and one of them has . How much does that point change the slope of the least-squares line?
It does not change the slope at all, because its is zero and so it adds nothing to or . The points far from the centre steer the slope most.
In the exam the working earns the marks, so we set it out as a table with one row for each point and columns for , , , , and . The sums of the last two columns are and . The means should carry one more figure than the data, because the differences are small differences between larger numbers.
Example D.12The Tully–Fisher relation by least squares
The faster a spiral galaxy rotates, the brighter it is. In IOAA 2021 the five galaxies of the table, with maximum rotation speeds and absolute magnitudes in the infrared, were to be fitted with by least squares, taking as . Find and .
(km/s)
(mag)
79.4
−16.8
100.1
−19.2
158.5
−21.3
251.2
−21.4
316.2
−24.0
Solution
To three places the logarithms are 1.900, 2.000, 2.200, 2.400 and 2.500, so , and .
1.900
−16.8
−0.300
3.74
0.0900
−1.122
2.000
−19.2
−0.200
1.34
0.0400
−0.268
2.200
−21.3
0.000
−0.76
0.0000
0.000
2.400
−21.4
0.200
−0.86
0.0400
−0.172
2.500
−24.0
0.300
−3.46
0.0900
−1.038
The sums are and , so
AnswerThe relation is . With the logarithms kept to four places, as a calculator keeps them, the intercept comes out as 1.47, the value of the official solution. The difference is far smaller than the uncertainty of the intercept, which we find below.
A calculator with a statistics mode, such as the Casio fx-82CW handed out at IOAA 2026, fits the same line from a list of values of and , and it calls the intercept and the slope . It is a quick check on the table, but the table and the sums are the working that a marker looks for.
D6.3The uncertainties of the slope and intercept
Before you readMake a guess first
Ten points scatter about a line. If the same scatter were spread over twice as wide a range of , how would the uncertainty of the slope change?
It would halve. Over a wider range the same scatter tilts the line by a smaller angle, which is why a good graph spreads the points out.
The scatter of the points about the line tells us how uncertain the line is. The typical size of a residual is estimated by , where dividing by instead of allows for the two constants that the line has already taken from the same points, just as a standard deviation divides by , as Section D7 explains. The slope is more certain when the points spread over a wide range of , which is what measures. The intercept is the value of the line at , and it is less certain the farther the data lie from .
ResultUncertainties of a least-squares line(D.7)
the uncertainties of the slope and of the intercept
the residuals of the points from the least-squares line
the number of points
These hold when the points scatter at random by about the same amount, and with only a few points they are rough. When the data come with error bars, the steepest and shallowest lines of Section D3 are the other accepted way, and an answer should say which one it used.
For the five galaxies the residuals from the line are 0.74, −0.66, −0.76, 1.14 and −0.46 magnitudes, and their squares add up to . The sum of the squared logarithms is , so , and
With the rule of Section D3 for rounding, the relation is . The intercept looks hopelessly uncertain, because it is the magnitude of a galaxy rotating at 1 km/s, far outside the data. At the centre of the points the line is known to about 0.45 magnitudes, which is divided by .
Calculators also give the correlation coefficient, where . It lies between and , and it is close to one of them when the points lie close to a straight line. For the five galaxies . A value near does not show that a straight line is the right model, though. The periods of Jupiter's moons against the sizes of their orbits, the curve of Figure D.4, give .
D6.4Lines through the origin
Before you readMake a guess first
A model says that exactly, with no intercept. Should the fitted line be made to pass through the origin?
It should, when the physics says that is zero when is zero, as in Hubble's law. When a model allows an intercept, forcing the line through the origin pulls the slope away from its true value.
When the model has no intercept, least squares gives , and its uncertainty is , with because the line now takes only one constant from the data. A line through the origin is right for Hubble's law, where a galaxy at zero distance has no velocity of recession. It is wrong whenever the model has an offset, such as an unknown zero point of a magnitude scale.
*D6.5Weighted least squaresOptional extension
When the points have different uncertainties , the precise ones should count for more. Each point is given a weight , and every sum of the method becomes a weighted sum. The centre of the points is then and , with and . The slope is still and the line still passes through the centre, while the uncertainties now come from the error bars themselves, as and .
Common errorsSection D6
When the quantity on the horizontal axis is the more uncertain one, least squares gives a slope that is too shallow. The more uncertain quantity belongs on the vertical axis.
The column of is spoilt when is rounded too early, because its values are small differences between larger numbers. The means need one more figure than the data.
The uncertainties of the slope and intercept come out too small when is divided by instead of , by a noticeable amount when there are only a few points.
The intercept is the value of the line at , which may lie far outside the data, where even a well-determined line is very uncertain. A value read from the line near the centre of the points is much more certain.
A correlation coefficient close to does not show that a straight line is the right model, because points on a smooth curve can give .
ExercisesSection D66 questions
D6.1
For a set of points , , and . What is the intercept of the least-squares line?
The slope is , and the intercept is .
D6.2
A least-squares line through six points has and . How uncertain is its slope?
By (D.7), .
D6.3
A model says with no intercept. For the data and . What is the slope of the least-squares line through the origin?
The slope is .
D6.4
For a set of points , and . What is the correlation coefficient?
The correlation coefficient is .
D6.5
Why does the estimate of the scatter about a least-squares line divide by ?
The answer is (b). The line is chosen to make the residuals as small as possible, so they understate the true scatter, and dividing by makes up for the two constants fitted. With only two points the residuals would be zero whatever the scatter.
D6.6
A fit gives an intercept of , but at the centre of the points the line is known to within 0.45. What is the main reason?
The answer is (a). A small uncertainty in the slope moves the line by a large amount far from the centre of the points, and the intercept may be very far from it.
Olympiad problemsPast IOAA problems, restated1 problem
2025Forecasting the arrival of solar storms28 points
Adapted from IOAA 2025 (Mumbai), data-analysis problem 2, parts 1 and 2. We have restated it in our own words and kept the original data. The solution was last checked on 20 October 2026.
The table gives, for ten coronal mass ejections, the speed at which each left the surface of the Sun, its speed on reaching Earth and the time it took to arrive. Take the distance from the surface of the Sun to Earth as 214 solar radii, with a solar radius of km, and treat the space in between as empty.
Cloud
(km/s)
(km/s)
(h)
CME-A
804
470
74.5
CME-B
247
360
127.5
CME-C
523
396
103.5
CME-D
830
415
71.0
CME-E
665
400
104.5
CME-F
347
350
101.5
CME-G
446
375
99.5
CME-H
155
360
97.0
CME-I
1016
515
67.0
CME-J
683
410
54.0
(a) Find the average acceleration of each cloud in m s⁻². This was worth 3 marks. (b) A model says that , with km/s. Find and and their uncertainties from a suitable graph. This was worth 15 marks. (c) Tabulate the model's acceleration for each cloud, and find the root-mean-square deviation . This was worth 4 marks. (d) Two more clouds, CME-1 and CME-2, leave the Sun at 1044 km/s and 273 km/s. Taking each one's acceleration from the model as constant, predict how long each takes to reach Earth. This was worth 4 marks. (e) They actually arrived after 46.0 h and 74.5 h. The model counts as valid for a cloud if its prediction is within 20% of the observed time. Say whether it is valid for each. This was worth 2 marks.
A cloud with constant acceleration that starts at speed reaches a distance with a speed given by , and it takes the time .
The accelerations are those found in Section D1, from with the speeds in m/s and the time in seconds: −1.25, 0.246, −0.341, −1.62, −0.704, 0.008, −0.198, 0.587, −2.08 and −1.40 m s⁻².
With and , a table as in Example D.12 gives , m s⁻², and m s⁻². So m s⁻² and m s⁻².
The squared residuals add up to (m s⁻²)², so by (D.7) m s⁻² and m s⁻².
The model gives −1.40, 0.336, −0.524, −1.48, −0.966, 0.024, −0.284, 0.622, −2.06 and −1.02 m s⁻² for the ten clouds. The root-mean-square deviation, which the problem defines with 10 in the denominator, is m s⁻².
For CME-1 the model gives m s⁻². The distance is km km, so the cloud arrives at km/s, after h.
For CME-2 the model gives m s⁻², an arrival speed of 388 km/s and h.
The prediction for CME-1 is 4.8% longer than the observed 46.0 h, and the prediction for CME-2 is 68% longer than the observed 74.5 h.
AnswerThe model is m s⁻², with a root-mean-square deviation of 0.176 m s⁻². It predicts 48.2 h for CME-1, within 20% of the observed time, so it is valid there, and 125 h for CME-2, far outside 20%, so it is not valid there. The official solution, with a line drawn by hand, finds and m s⁻², within our uncertainties, and the same deviation and conclusions. Its uncertainties come from steepest and shallowest lines judged by eye, which are narrower than the scatter of the points suggests.
Contents
Sections finished, Chapter D
0 of 8
Exercises right
None attempted yet
To redo
Nothing yet
Progress is saved in this browser on this device. Back it upClear every tick and answer?