Goodness of Fit and Degrees of Freedom
~8 min read · Tier toggle changes depth (T1 plain · T2 standard · T3 rigour)
You should be comfortable with the definition of the chi-squared distribution and its mean, as established in the previous lecture. Familiarity with the concept of minimizing a function to find best-fit parameters is also assumed.
Why this matters
Goodness of fit provides the statistical criterion for deciding whether a model is consistent with experimental data.
In experimental physics, we rarely measure a single value; we collect a set of data points and compare them to a theoretical curve. The central question is not just "how close are the points to the line?" but "is the deviation consistent with random noise?" This lecture establishes the formal link between the number of data points, the number of adjustable parameters, and the expected value of the chi-squared statistic. This link allows us to quantify the "quality" of a fit and, crucially, to calculate the correct degrees of freedom for subsequent hypothesis testing.
The Intuition of Degrees of Freedom
Imagine you have a set of data points and you want to draw a straight line through them. If you have only two points, there is exactly one straight line that passes through both of them perfectly. The "error" between the data and the model is zero. However, this does not mean the model is "good" in a statistical sense; it simply means you have used up all your freedom to adjust the line. You have no "leftover" freedom to check if the line is consistent with the noise.
Now imagine you have ten points. You can still adjust the slope and the intercept (two parameters) to minimize the distance between the line and the points. However, because you have many more points than parameters, the line cannot pass through every single point. The deviations that remain are the "residuals." These residuals represent the information that was not used to define the line. Statistically, each parameter you fit "consumes" one degree of freedom. If you have \( N \) data points and fit \( M \) parameters, you are left with \( N - M \) independent pieces of information that can be used to assess the fit. This number, \( \nu = N - M \), is the degrees of freedom. It is the effective number of independent errors that remain after the model has been tuned to the data.
The Chi-Squared Statistic in Fitting
When we fit a model \( f(x; \theta) \) to data \( y_i \) with known uncertainties \( \sigma_i \), we define the chi-squared statistic as:
Our goal is to find the parameters \( \theta \) that minimize this quantity. Let \( \chi^2_{\min} \) be the minimum value achieved. If the model is correct and the errors are Gaussian, the minimized statistic is not just a single number; it follows a specific probability distribution. According to the derivation cited in D-124, for a linear model with independent Gaussian errors, the distribution of \( \chi^2_{\min} \) is the chi-squared distribution with \( \nu = N - M \) degrees of freedom.
This result is profound because it tells us that the "best" fit is not expected to have \( \chi^2 = 0 \). Instead, the expected value of the minimized statistic is equal to the degrees of freedom:
If you find a fit where \( \chi^2_{\min} \) is significantly smaller than \( N - M \), it suggests that the errors have been overestimated or that the model has enough freedom to follow the noise. If \( \chi^2_{\min} \) is significantly larger, the model is likely incorrect or the errors are underestimated.
The Reduced Chi-Squared
To make the goodness-of-fit test independent of the size of the dataset, we define the reduced chi-squared, often denoted as \( \chi^2_\nu \) or \( \bar{\chi}^2 \):
By dividing by the degrees of freedom, we normalize the statistic. For a good fit, the expected value of this reduced statistic is exactly one:
This provides a simple rule of thumb. If \( \chi^2_\nu \approx 1 \), the fit is consistent with the data within the expected statistical fluctuations. If \( \chi^2_\nu \gg 1 \), the model is poor. If \( \chi^2_\nu \ll 1 \), the errors may be overestimated. This normalization is crucial because it allows us to compare the quality of fits from experiments with vastly different numbers of data points. For example, 100 points with two fitted parameters and \( \chi^2_{\min} = 95 \) give \( \chi^2_\nu \approx 0.97 \), and 10 points with one parameter and \( \chi^2_{\min} = 9 \) give \( \chi^2_\nu = 1.0 \): both are consistent. The larger data set tests the model more sharply, because the spread of \( \chi^2_\nu \) about 1 is \( \sqrt{2/\nu} \).
Connection to the Chi-Squared Distribution
The result that \( \chi^2_{\min} \) follows a chi-squared distribution with \( N - M \) degrees of freedom relies on the properties of the chi-squared distribution itself, derived in D-123. Recall that if \( Z_1, \dots, Z_k \) are independent standard normal variables, then \( Q = \sum_{i=1}^k Z_i^2 \) follows a chi-squared distribution with \( k \) degrees of freedom, with mean \( E[Q] = k \) and variance \( \text{Var}(Q) = 2k \).
In the context of fitting, the residuals \( r_i = y_i - f(x_i; \hat{\theta}) \) are not independent in the same way as the raw errors because they are constrained by the fitting conditions (the derivatives of \( \chi^2 \) with respect to the parameters are zero at the minimum). These constraints reduce the effective number of independent variables from \( N \) to \( N - M \). Therefore, the sum of the squared standardized residuals behaves like a sum of \( N - M \) independent squared standard normal variables. This is why the degrees of freedom are \( N - M \) rather than \( N \). The variance of the minimized chi-squared statistic is therefore \( 2(N - M) \), which is essential for calculating the probability of obtaining a fit as good or worse than the observed one.
The derivations
Goodness of Fit and Degrees of Freedom
For N data points with independent Gaussian errors, fitted to a model with M adjustable parameters by minimising χ², the minimised statistic obeys E[χ²min] = N − M and, for a linear model, is distributed as χ² with ν = N − M degrees of freedom. Each fitted parameter therefore removes exactly one degree of freedom, and the reduced statistic χ²ν = χ²min / (N − M) has expectation one, which is the working goodness-of-fit test.
The Chi-Squared Distribution
Let Z1, …, Zk be independent standard-normal variables, Zi ~ N(0, 1), and define Q = Σi=1k Zi2. Then Q follows the chi-squared distribution with k degrees of freedom, with probability density fQ(x) = xk/2 − 1 e−x/2 ⁄ [2k/2 Γ(k/2)] for x > 0, mean E[Q] = k, and variance Var(Q) = 2k.
A common misconception is that a "perfect" fit with \( \chi^2_{\min} = 0 \) is the ideal outcome. In fact, with \( N > M \) and genuine random errors, \( \chi^2_{\min} \) should be close to \( N - M \). A value near zero usually means the uncertainties \( \sigma_i \) were greatly overestimated, the residuals are not independent (for example, smoothed or averaged data), or the model has so many parameters that it follows the noise. Always check that \( \chi^2_\nu \) is close to 1, not 0. C
Worked example
Problem. A student measures the period of a pendulum 20 times. They fit the data to a model with 2 adjustable parameters (length and gravitational acceleration). The minimized chi-squared value is \( \chi^2_{\min} = 18.5 \). Calculate the reduced chi-squared and determine if the fit is consistent with the data.
- Identify the number of data points \( N = 20 \) and the number of parameters \( M = 2 \).
- Calculate the degrees of freedom: \( \nu = N - M = 20 - 2 = 18 \).
- Calculate the reduced chi-squared: \( \chi^2_\nu = \frac{18.5}{18} \).
- Compare \( \chi^2_\nu \) to the expected value of 1.
Units check. The chi-squared statistic is dimensionless, as it is a sum of squared ratios of quantities with the same units. The reduced chi-squared is also dimensionless. The value 1.03 is very close to the expected value of 1, indicating that the fit is statistically consistent with the data. The deviations are within the range expected from random Gaussian noise.
Three quick tests
- If you have 50 data points and fit a model with 5 parameters, what is the expected value of \( \chi^2_{\min} \)?
Answer
45. The expected value is \( N - M = 50 - 5 = 45 \). - Why is the degrees of freedom \( N - M \) and not \( N \)?
Answer
Because fitting \( M \) parameters imposes \( M \) constraints on the residuals, reducing the number of independent pieces of information by \( M \). - If \( \chi^2_\nu = 5.0 \), what does this suggest about the fit?
Answer
The fit is poor. The deviations are much larger than expected from the stated uncertainties, suggesting either the model is incorrect or the errors are underestimated.
Problem set for PU-106 →
Each derivation in this unit ends with five graded problems with full solutions.
Lecture notes drafted with a local model and checked line by line by the editor; every number in the worked example was recomputed.
Derivations cited: D-124 · D-123 · Threads: chance