Quant Memo
Core

Degrees of Freedom

A plain-English take on degrees of freedom, the count of values in a calculation that are still free to vary after you have spent some of them estimating other quantities, why the sample variance divides by n minus 1, and how the same bookkeeping shows up in t-tests and regression.

Degrees of freedom sounds abstract, but it's really a headcount: of all the numbers going into a calculation, how many are still free to be anything once you've used the data to pin down other quantities? Every quantity you estimate from the sample "uses up" one of those free slots. That single idea explains the mysterious "minus one" in the variance formula and the "minus kk" all over regression.

The cleanest picture: imagine five numbers whose average is required to equal some fixed value xˉ\bar x. You can pick the first four to be whatever you like, but the moment those four are set, the fifth is forced, it has to be exactly the value that makes the average come out right. So five numbers with a pinned average carry only four free choices. In symbols, degrees of freedom =n1= n - 1: you started with nn values and spent one on fixing the mean.

mean pinned at x̄ free free free free fixed df = n − 1 = 4
Five values constrained to a fixed average. The first four can be anything (green), so the fifth is completely determined (clay). One constraint costs one degree of freedom, leaving $n-1 = 4$.

Worked example: why variance divides by n − 1

Take three numbers: 2,4,92, 4, 9. Their mean is xˉ=5\bar x = 5. The deviations from the mean are 3, 1, +4-3,\ -1,\ +4, and notice they must sum to zero (that's what "mean" guarantees). So if I tell you the first two deviations, 3-3 and 1-1, the third is forced to be +4+4. Only two of the three deviations are free: n1=2n - 1 = 2 degrees of freedom.

Now the payoff. The sum of squared deviations is (3)2+(1)2+(4)2=9+1+16=26(-3)^2 + (-1)^2 + (4)^2 = 9 + 1 + 16 = 26. How should we turn that into a variance?

divide by n=3: 2638.67vs.divide by n1=2: 262=13.\text{divide by } n = 3 : \ \frac{26}{3} \approx 8.67 \qquad\text{vs.}\qquad \text{divide by } n-1 = 2 : \ \frac{26}{2} = 13 .

Dividing by nn systematically underestimates the true variance, because the deviations are measured from the sample mean, which is itself tuned to sit as close to the data as possible, making the squared gaps a touch too small. Dividing by the degrees of freedom n1n-1 (Bessel's correction) exactly cancels that shrinkage and gives an unbiased estimate. The correction is largest for tiny samples and fades as nn grows. See Bias, Variance, and the Quality of Estimators.

For a sample, divide the summed squared deviations by n1n-1, not nn. Dividing by nn biases variance, and therefore volatility, downward, and the distortion is worst exactly when the sample is small.

The same rule everywhere

The recipe generalizes: degrees of freedom = number of data points − number of parameters you estimated from them. Each estimated parameter is one constraint, one used-up slot.

The one rule to carry: df = data points − parameters estimated from the data. Every quantity you estimate spends one slot, which is why the sample variance uses n1n-1 and a kk-predictor regression leaves nk1n-k-1.

CalculationValues (nn)Parameters estimatedDegrees of freedom
Sample variancenn1 (the mean)n1n - 1
Two-sample tt-testn1+n2n_1 + n_22 (two means)n1+n22n_1 + n_2 - 2
Simple regressionnn2 (slope, intercept)n2n - 2
Regression with kk predictorsnnk+1k + 1nk1n - k - 1
Chi-square, r×cr \times c tablercr\,crow & column totals(r1)(c1)(r-1)(c-1)

In a regression (see Ordinary Least Squares (OLS)), fitting an intercept plus kk slopes burns k+1k+1 slots, leaving nk1n - k - 1 degrees of freedom for the residuals. That leftover count is what goes into standard errors, tt-statistics, and the FF-test, which is why cramming in predictors until you're nearly out of degrees of freedom makes every test unreliable.

Common pitfalls

  • Dividing variance by nn. For a sample (not the whole population), use n1n-1. With small samples the difference is real: dividing by nn biases the variance, and hence the volatility, downward.
  • Spending all your degrees of freedom. Fit a model with kk predictors and only slightly more than kk observations and you have almost no residual degrees of freedom left, the fit hugs the noise and looks great in-sample while predicting nothing out of sample. This is one face of Overfitting.
  • Grabbing the wrong df. Different tests have different formulas (a paired tt-test uses n1n-1, a two-sample uses n1+n22n_1 + n_2 - 2, a chi-square uses (r1)(c1)(r-1)(c-1)). Guessing changes your critical value and your conclusion. See Hypothesis Testing.
  • Forgetting df fattens the tails. The tt-distribution's degrees of freedom control how heavy its tails are, few degrees of freedom means fatter tails and wider honest intervals. Treating a small-sample tt as a normal understates your uncertainty.

The one-line takeaway: degrees of freedom count the numbers that are still free to move after your estimates have tied the rest down, and honoring that count is what keeps variances unbiased and tests trustworthy.

Related concepts

Practice in interviews

Further reading

  • Wasserman, All of Statistics (Ch. 7)
  • Wooldridge, Introductory Econometrics (Appendix C)
ShareTwitterLinkedIn