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:


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?

  • $\begingroup$ 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. $\endgroup$ – whuber May 4 '17 at 17:09
  • $\begingroup$ The residuals are obtained as $(observation - predictions)$, where $predictions = a * observations+b$. Is this what you meant @whuber? $\endgroup$ – Gabriel May 4 '17 at 17:25
  • 1
    $\begingroup$ 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. $\endgroup$ – whuber May 4 '17 at 19:12
  • 1
    $\begingroup$ 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) $\endgroup$ – Glen_b May 5 '17 at 6:11
  • $\begingroup$ @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?) $\endgroup$ – Gabriel 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

Edit See Glen_b's comment below.

| cite | improve this answer | |
  • 1
    $\begingroup$ It's only correct under some particular sets of circumstances. Since the situation that pertains hasn't been sufficiently explained, the assertion that any particular thing is correct may be a little bold. $\endgroup$ – Glen_b May 5 '17 at 6:08
  • $\begingroup$ @Glen_b, good call. I read too much into the question. $\endgroup$ – c4sadler May 5 '17 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.