The number of degrees of freedom is the number of values in the final calculation of a statistic that are free to vary.
A simple example is shown in calculating the mean of a sample. Supposeis a sample from a population.
Theare estimates of the residualswhereis the true mean of the population.
The sum of the residuals (unlike the sum of the errors) is necessarily 0. If we know the values of anyof the residuals, we can find the last residual, so that even though there are n residuals, onlyof these are free to vary. For this reason we say that the residuals of a sample of size n hasdegrees of freedom.
For the same reason, the sample standard deviationincludes an expression n-1 in the denominator.
We can write
is the sum of the squares of the residuals and the residuals only have n-1 degrees of freedom, so that