# Correct number of degrees of freedom for reduced chi square of linear regression?

I have a set of $N$ x,y points for which I perform a simple linear regression of the form $y=a x+b$.

I need to calculate the reduced chi square ($\chi^2_{\nu}$) to asses the goodness of fit of this regression. According to Wikipedia, the number of degrees of freedom is:

The degree of freedom, $\nu =n-m$, equals the number of observations $n$ minus the number of fitted parameters $m$.

Given that I have 2 fitted parameters, $a$ and $b$, I'd have

$\nu = N - 2$

But I've seen in a blog post with Python code to obtain the reduced chi square, that $\nu$ is calculated as:

$\nu=N-2-1$

The number of points I'm fitting is rather small ($N<10$), so an extra $-1$ will affect the value of my $\chi^2_{\nu}$ quite a bit.

Which is the correct formula for obtaining the degrees of freedom and why?

• This statistic is based on values of variances of the residuals. Where did you get those values from? If you estimated them from the same data, you need to account for that in your calculation of the degrees of freedom.
– whuber
May 4 '17 at 17:09
• The residuals are obtained as $(observation - predictions)$, where $predictions = a * observations+b$. Is this what you meant @whuber? May 4 '17 at 17:25
• That's what I meant by residual, to be sure: but the point is that the reduced chi-square statistic divides those squared residuals by variances. How do you find those variances? It matters.
– whuber
May 4 '17 at 19:12
• Is the x-variable observed with error? (e.g. if you imagine being able to wind back and do it again with things otherwise the same, would the x-values be the same? Or would you have observed the values somewhat differently if you could have had a do-over) May 5 '17 at 6:11
• @whuber there is definitely a variance being used, I'm tracking down how it is obtained (I'm dealing with some really old and cryptic legacy code, sorry) Glen: I guess if I started the observation process from zero the x values would probably change a little bit (is this not true for all observation processes?) May 5 '17 at 12:12

$v=n-m$ is correct. Explaining Degrees of Freedom is a complicated and I doubt that I understand it well enough to explain. Here is an article that is very useful: http://courses.ncssm.edu/math/Stat_Inst/PDFS/DFWalker.pdf