Search code examples
pythonstatisticsscipydata-fitting

Chi square value from scipy.stats has degree of freedom = 0 as default. What does this mean?


Hi I have data sets (maxwellian and gaussian) that I make a histogram plot with. I fit the data using scipy.stats.chisquare but it has by default, degrees of freedom as 0. If I understand correctly, it is not possible right?enter image description here


Solution

  • To directly answer your question, you are correct - Degrees of freedom being 0 is invalid/useless. scipy.stats.chisquare parameter isn't degrees of freedom but an adjustment to degrees of freedom. Degrees of freedom defaults to k - 1 when ddof = 0. k can be directly determined from the data you pass to the chisquare function.

    From the Scipy chiqsuare documentation

    ddof : int, optional “Delta degrees of freedom”: adjustment to the degrees of freedom for the p-value. The p-value is computed using a chi-squared distribution with k - 1 - ddof degrees of freedom, where k is the number of observed frequencies. The default value of ddof is 0.

    ddof is the delta not the absolute value for degrees of freedom. So degrees of freedom is k - 1 and ddof is an adjustment subtracted from k - 1. So when ddof = 0, degrees of freedom = k - 1 - 0 or k - 1 . When ddof = 1, degrees of freedom = k - 1 - 1 or k - 2 . k is the number of observed frequencies and the chisquare function can determine that from the data you pass