Home / Learn / Science / Astronomy / Lesson 5.7
All lessons

Module 5: Doing real research · Lesson 5.7 · about 25 min

Fitting models and error bars

Every measurement needs an uncertainty. Least-squares fitting finds the model that misses the data least, chi-squared says whether the misses match the error bars, and uncertainties pass through formulas in predictable ways.

Key points, meanings and formulas on one page: choose "Save as PDF" in the print box.

Module 5 · about 25 minutes · read first: 5.1 Aperture photometry, 5.2 Time series and periodograms · maths: sums of squares. You’ll be able to fit a straight line by least squares, judge a fit with chi-squared, and carry uncertainties through a calculation.

Every measurement needs an uncertainty: least squares finds the model that misses the data least, chi-squared says whether the misses match the error bars, and uncertainties pass through formulas in predictable ways.

1. Why this matters

A result without an error bar isn’t a result. “The planet is 1.2 Earth radii” means little; “1.2 ± 0.1” tells you whether it could be rocky. Every number in a research paper comes with an uncertainty, and much of the argument in science is about whether those uncertainties are honest.

2. Least squares and chi-squared

You have measurements yi with uncertainties σi and a model f(x) with adjustable numbers (parameters). The least-squares fit picks the parameters that make the total squared miss, weighted by the error bars, as small as possible. That total is chi-squared (χ2).

Try it: fit by hand, then let the maths do it
χ² (sum of squared misses ÷ σ²)
reduced χ² (÷ 10 degrees of freedom)
best slope ± error

Twelve simulated measurements with true scatter of 1 unit around a hidden line. Reduced χ² near 1 means the line and the error bars agree; much bigger means a bad model or error bars that are too small; much smaller means the error bars were too big. The slope's error shrinks as 1/√(number of points).

Things to notice:

  • By hand you can get close; the best-fit button finds the exact minimum.
  • Shrink the claimed error bars and χ² shoots up even though the line hasn’t changed.

Fit a straight line and judge the fit:

Data. Five points, each with an error bar of ±0.2.
Fit. Least squares finds the slope and intercept that make the squared misses smallest.
Score the misses. χ² adds up (miss / error bar)² for every point. Here χ² = 3.4.
Judge it. With 5 points and 2 parameters, χ²/(5 − 2) = 1.1: the misses match the error bars. A value near 10 would mean a bad model or underestimated errors.
Report. Slope 2.03 ± 0.06: the best value with its uncertainty, never just a bare number.
Maths and principle

Chi-squared:

χ2=∑i=1N(yi−f(xi)σi)2

Reduced chi-squared: χν2=χ2/(N−k) for k fitted parameters. About 1 is good.

Straight-line fit y=mx+b (equal error bars σ):

m=∑(xi−x‾)(yi−y‾)∑(xi−x‾)2,b=y‾−mx‾,σm=σ∑(xi−x‾)2

Error propagation (independent errors):

  • sums and differences: σa±b=σa2+σb2
  • powers: if q=an, then σq/q=|n|σa/a
  • mean of N equal measurements: σx‾=σ/N

3. What it means physically

Squaring the misses treats overshooting and undershooting alike and punishes big misses most. Dividing by σ means a point you measured carefully counts more than a rough one. If your error bars are right and your model is right, each point should miss by about one error bar on average, so χ² comes out near the number of points: that is the whole idea behind “reduced χ² ≈ 1”.

χ² = Σ((y − f(x)) / σ)²
How far the model misses each point, measured in error bars.
χ²ν = χ² / (N − k)
Reduced chi-squared: about 1 means a good fit.
σm ≈ 1.086 σF / F
Error propagation: a flux uncertainty becomes a magnitude uncertainty.
Physical meaning
Error bars are the honest "give or take" of a measurement. A good model passes within about one error bar of two-thirds of the points; if it misses by much more, either the model is wrong or the error bars were too optimistic.

“A fit that passes through every point is the best fit.” With error bars, a perfect pass through every point usually means the model has too many free parameters (overfitting) or the errors are overestimated. Expect misses about the size of the error bars.

4. Worked example

A star’s radius comes from R∝L/T2. L is known to 10% and T to 2%. How well is R known?

σRR=(12×10%)2+(2×2%)2=52+42%=6.4%

The temperature error, though only 2%, matters almost as much as the luminosity error, because T enters squared.

5. Practice

More practice (answers below):

  1. A fit to 22 points with 2 parameters gives χ² = 21. Is it good?
  2. You measure a period ten times; the spread is 0.03 days. How well do you know the average?
  3. m1=12.30±0.02, m2=11.85±0.03. What is m1−m2 with its error?
Answers
  1. χν2=21/20=1.05: good.
  2. 0.03/10=0.009 days.
  3. 0.45±0.022+0.032=0.45±0.036.
  • Least squares minimises the sum of squared, error-weighted misses (χ²).
  • Reduced χ² ≈ 1 means the model and error bars agree.
  • Errors add in quadrature: σ = √(σ₁² + σ₂²) for independent errors.
  • Always report a result with its uncertainty.

Try it with real numbers: fit real data with the radial velocity, the transit fitter or the rotation curve; each reports its uncertainties.

New words: uncertainty, least squares, chi-squared, reduced chi-squared, degrees of freedom, error propagation.

Check yourself

1A fit has reduced χ² = 5. The most likely problem is:
2Averaging 100 measurements each with uncertainty 0.1 gives an average uncertain by about:
3If d = 1/p and p has a 5% uncertainty, d has about:

Sources

  • Bevington, P. R. and Robinson, D. K. (2003), Data Reduction and Error Analysis for the Physical Sciences (methods described)

Your ticks stay in this browser. Save them as a file on the course home.

Updated 2026-11-22. Numbers in the examples are made up to show the idea unless a source is given. Simulations run in your browser on made-up data; nothing you type is sent anywhere. Astronomy only: nothing here is astrology.