---
title: "Fitting a Model to Data: Least Squares, Chi-Square and Goodness of Fit"
description: "A fit chooses parameters that minimise a weighted sum of squared residuals, and the size of that sum says whether the model is believable at all. Without uncertainties on the points, neither the param"
canonical: https://lightmysky.com/learn/science/fitting-a-model-to-data-least-squares-chi-square-and-goodness-of-fit-mt_NN0WYlp0md
source: https://lightmysky.com/learn/science/fitting-a-model-to-data-least-squares-chi-square-and-goodness-of-fit-mt_NN0WYlp0md.md
retrieved: 2026-09-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# Fitting a Model to Data: Least Squares, Chi-Square and Goodness of Fit

A fit chooses parameters that minimise a weighted sum of squared residuals, and the size of that sum says whether the model is believable at all. Without uncertainties on the points, neither the parameters nor the verdict means anything.

Subject: Science · Area: Scientific Inquiry · Ages 22 to 23
Page: https://lightmysky.com/learn/science/fitting-a-model-to-data-least-squares-chi-square-and-goodness-of-fit-mt_NN0WYlp0md

## Ready when they can

- Fits a straight line by weighted least squares and reports parameter uncertainties
- Interprets a reduced chi-square value, including what too small a value suggests
- Reads structure in the residuals and says what it implies about the model

## Lesson: Fitting lines and judging the fit

A residual is the gap between one observed value and the value your model predicts there: y minus y-hat. The method of least squares chooses parameters that make the sum of the squared residuals as small as possible. Squaring makes misses above and below the line both count, and big misses count extra. Without uncertainties on the points, neither the fitted parameters nor any verdict on the model means anything.

**Example.** You measure one temperature three times and get 2.0, 3.0, and 4.0 degrees with equal uncertainties. Your model is just a constant, y equals a. The sum of squared residuals is smallest at a equals 3, the middle of the three readings. The residuals there are 1, negative 2, and 1, each with uncertainty 1, so the chi-square sum is 1 plus 4 plus 1, which is 6.

The chi-square statistic weights each point fairly: divide each residual by that point's uncertainty, square it, then add all the terms. That is why points measured more precisely pull the fit harder than sloppy points. A reduced chi-square near 1 means the typical miss is about one sigma, so the model fits about as well as the stated uncertainties say it should. A value far below 1 suggests the uncertainties were overestimated, or the model has so many parameters it merely follows the noise. And if the residuals show a visible pattern, like a U shape from a straight line fitted to curved data, the model is systematically wrong: a good fit leaves only random scatter.

**Tip.** Always plot the residuals before you believe a fit. Random scatter around zero means the model shape is plausible, while curves or drifts mean you need a different model. Report the parameter uncertainties alongside the parameters, since a value without its uncertainty cannot guide any decision.

**Recap.** Minimize the squared misses, weight by the uncertainties, and let chi-square plus the residual pattern judge the model.

## Practice

18 questions on this page, each with its working shown.

## Needs first

- [Dimensional Analysis, Scaling and the Order-of-Magnitude Estimate](https://lightmysky.com/learn/science/dimensional-analysis-scaling-and-the-order-of-magnitude-estimate-mt_jXnXRMKnC3)
- [Least-Squares Calibration and the Uncertainty of a Result Read From It](https://lightmysky.com/learn/science/least-squares-calibration-and-the-uncertainty-of-a-result-read-from-it-mt_L08U-Extq_)
- [Conditioning, Stability and Floating-Point Error](https://lightmysky.com/learn/mathematics/conditioning-stability-and-floating-point-error-mt_q8IoCElXIV)
- [Simple Linear Regression and Inference on the Slope](https://lightmysky.com/learn/mathematics/simple-linear-regression-and-inference-on-the-slope-mt_W2huNTKsMj)
- [Chi-Square Tests for Categorical Data](https://lightmysky.com/learn/mathematics/chi-square-tests-for-categorical-data-mt_yxc87pzaXX)

## Opens up

- [Systematic Error, Controls and the Design of a Measurement](https://lightmysky.com/learn/science/systematic-error-controls-and-the-design-of-a-measurement-mt_rGjB_JcsLJ)
