Degrees of freedom count the values in a statistical test’s final calculation that remain free to vary after constraints are applied. In a chi-square test, they help determine the p-value and statistical significance. section 12.5.1
For a chi-square goodness-of-fit calculation organized by rows and categories, derive degrees of freedom from the row and category counts. With 9 leading-digit rows and 2 categories, the result is (9 − 1)(2 − 1) = 8. section 12.5.1
Leading digits in world population counts
A chi-square statistic of 7.1925 with 8 degrees of freedom produces a p-value of about 0.516 using scipy.stats.chisquare(). Because the p-value exceeds 5%, the data do not provide grounds to reject conformity with the expected distribution. section 12.5.1


