Fix bug in computing degrees of freedom.