Chapter 7 of 11 · 13 min read
Least squares fitting
The formulas for a best-fit line and its uncertainties, weighted fits, lines through the origin, and what r and χ² tell you.
The ordinary least squares line
For points , the line that minimises has
Equivalently, and , which is less prone to rounding errors.
To get uncertainties, first estimate the scatter about the line, using because two parameters were fitted:
Weighted fits
If each has its own uncertainty , use weights and replace , , and so on:
These errors come from the error bars, not from the scatter, so they are only honest if the error bars are.
A line through the origin
When theory says (Hubble's law, , ), fit only the slope:
This is exactly how the 2023 solution gets mas from eight epochs.
Judging the fit
- Correlation coefficient : close to means a tight linear relation. It does not tell you the line is the right model: a gentle curve can have .
- Residuals : plot them against . Random scatter is good; a systematic arch means curvature you have not modelled.
- Chi-square : for a good model and honest errors, . Much larger means the errors are underestimated or the model is wrong; much smaller means the errors are overestimated.
Doing it with a calculator
Most scientific calculators have a linear regression ("LR", "STAT", "A+BX") mode that gives , and directly. They usually do not give errors, but they do give the sums , , , , from which you get and the formulas above. Practise this before the exam on the 2018 IRX–β data. You should recover in about five minutes.
Write the fitted equation on the graph, and draw the line on it as well. Several schemes give a separate mark for "best-fit equation noted on the same page".
Key formulas
- Slope and intercept
- Their uncertainties
- Weighted line through the origin
- Goodness of fit
Common mistakes
- Using N instead of N − 2 in the scatter about a fitted line.
- Taking r ≈ 1 as proof that the relation is linear.
- Fitting with an intercept when the physics requires the line to pass through the origin, or the reverse.
- Fitting all points including ones the method says must be excluded (2023: a straight line through all eight epochs absorbs the deflection).
Practise this chapter
Past IOAA problems that use these skills.
- 2016 D1 | Timing a binary millisecond pulsarOlympiad
- 2017 D1 | Calibrating the distance ladder to the LMCAdvanced
- 2017 D2 | Dark matter in a low surface brightness galaxyOlympiad
- 2018 D1 | Dust and young stars: the IRX–β relationAdvanced
- 2023 DA1 | Distance to the LMC from eclipsing binariesAdvanced
- 2023 DA2 | Weighing an isolated black hole with astrometric microlensingOlympiad
Saved in this browser only.
