We assumed each data point is taking from a distribution with mean and variance
in which, the mean can be a function of X.
For example, we have a data , it has relation with an independent variable . We would like to know the relationship between and , so we fit a function .
After the fitting (least square method), we will have so residual for each of the data
This residual should be follow the distribution
The goodness of fit, is a measure, to see the distribution of the residual, agree with the experimental error of each point, i.e.
Thus, we would like to divide the residual with and define the chi-squared
we can see, the distribution of
and the sum of this distribution would be the chi-squared distribution. It has a mean of the degree of freedom . Note that the mean and the peak of the chi-squared distribution is not the same that the peak at .
In the case we don’t know the error, then, the sample variance of the residual is out best estimator of the true variance. The unbiased sample variance is
where is degree of freedom. In the cause of , the , because there is 1 degree o freedom used in x. And because the 1 with the b is fixed, it provides no degree of freedom.