logo

Degrees of Freedom: Meaning, Formulas and Examples

Four-bead counting sculpture with one bead constrained, representing a statistical constraint.
16

Degrees of freedom describe how many independent pieces of information remain available for a statistical calculation after its constraints or estimated parameters are taken into account. The correct count depends on the calculation. It is not always the sample size minus one.

For an ordinary sample variance, estimating one mean leaves n − 1 degrees of freedom. For a full-rank linear regression with p fitted coefficients, including the intercept, residual degrees of freedom are n − p. Other tests use different counts or approximations.

What Do Degrees of Freedom Mean?

Think about what can still vary once a condition has been fixed. Four numbers constrained to add to 20 do not have four freely selectable values. Once three are chosen, the last must make the sum equal 20.

That intuition helps explain why estimated parameters matter. When you measure deviations around a sample's own estimated mean, those deviations must sum to zero. They therefore cannot vary independently in every direction.

The degrees of freedom describe the information left for a particular purpose, such as estimating residual variation. They do not mean that observations have literally been deleted from the dataset.

The same sample can have several relevant degrees of freedom. A regression output may show one count for the fitted model and another for its residuals. An ANOVA table separates variation into components, each with its own count.

Why Sample Variance Uses n − 1

Take four hypothetical forecast errors, measured in percentage points:

2, 4, 6, 8.

Their mean is 5. Subtracting that mean produces deviations of −3, −1, 1, 3. They sum to zero because the mean was calculated from these same observations.

Their squared deviations sum to 9 + 1 + 1 + 9 = 20. The usual sample variance is:

s² = sum of squared deviations / (n − 1) = 20/3 ≈ 6.6667.

Its units are squared percentage points. The sample standard deviation is the square root of that quantity, approximately 2.5820 percentage points.

Quantity Value
Observations 4
Estimated means 1
Degrees of freedom 3
Squared sum 20

The three degrees of freedom reflect the zero-sum constraint on the deviations. Dividing by four instead gives 5, a different variance calculation. It is not the usual unbiased estimator of population variance from a random independent sample when the population mean is unknown.

If those four values are the entire population you want to describe, a population-style divisor of four answers a different question. State which question you are answering rather than treating one denominator as correct for every use.

Four deviations minus three, minus one, plus one and plus three sum to zero, leaving 3 degrees of freedom.
Hypothetical deviations around an estimated mean: −3, −1, 1, and 3 percentage points sum to zero. Four deviations with one zero-sum constraint leave three degrees of freedom for the usual sample variance.

Degrees of Freedom in a T-Test

In a one-sample t-test, the estimated sample standard deviation uses n − 1 degrees of freedom. A paired test applies the same reasoning to the differences within the pairs.

For eight pairs, there are eight differences. The paired t-test therefore uses 7 degrees of freedom, rather than treating the 16 original measurements as independent observations.

NIST's t-test reference sets out the formulas and reference distributions for these cases. The degrees of freedom help determine the critical value used to judge the observed statistic.

Do not choose a count because it gives a more favorable p value. The data structure and test determine the count. If the observations are dependent in a way the test does not accommodate, changing the denominator by hand will not fix the underlying analysis.

Our null hypothesis guide explains how that reference calculation fits into a clearly stated test.

Independent Samples and Fractional Degrees of Freedom

For a pooled two-sample t-test with an equal-variance assumption, the familiar count is n₁ + n₂ − 2. One mean is estimated in each independent group.

Welch's test does not pool the two variances in the same way. Its reference degrees of freedom use an approximation and can be fractional. For positive sample variances, define a = s₁²/n₁ and b = s₂²/n₂. Then:

df ≈ (a + b)² / [a²/(n₁ − 1) + b²/(n₂ − 1)].

A fractional value is not a fractional number of observations. It is a feature of the reference approximation. NIST discusses the related Welch–Satterthwaite treatment of degrees of freedom in uncertainty calculations.

If a software package returns a noninteger count, check which method it used. Replacing the result with n₁ + n₂ − 2 silently substitutes a different assumption.

Residual Degrees of Freedom in Regression

For an ordinary least-squares model with n observations and a full-rank design matrix containing p fitted coefficients, residual degrees of freedom equal n − p.

Include the intercept in p. Suppose a hypothetical model uses 12 observations, two predictors, and an intercept. It fits three coefficients, leaving 12 − 3 = 9 residual degrees of freedom.

The U.S. Energy Information Administration's regression methods handbook gives this denominator for residual mean squared error under the stated model assumptions.

The number of named columns is not always the number of independently estimated coefficients. Perfectly redundant predictors make the design matrix rank deficient. The general count uses the rank actually estimated, and regularized models can require other definitions of effective complexity.

For this reason, adding observations does not automatically repair an overcomplicated or poorly specified model. Inspect the design, dependence, and estimation method as well as the reported count. The linear regression guide provides the broader modeling context.

ANOVA Has More Than One Count

Consider a one-way ANOVA with 12 independent observations across three nonempty groups. Under the usual model, the degrees of freedom divide as follows:

Component Degrees of freedom
Between groups 2
Within groups 9
Total 11

The between-group count is k − 1, where k is the number of groups. The within-group count is n − k. The total is n − 1. Here, 2 + 9 = 11.

These counts belong to the corresponding sums of squares. Dividing each sum by its own degrees of freedom produces a mean square. The ordinary F statistic compares the between-group and within-group mean squares.

That framework is discussed in the site's ANOVA guide. Do not transfer these counts unchanged to repeated-measures designs or other models with a different dependence structure.

Redundant Predictors Do Not Add Independent Information

Return to the 12-observation regression. If the second predictor is exactly twice the first, it does not add a new independent direction to the design matrix. With an intercept and one nonconstant predictor, the matrix has rank two, leaving 12 − 2 = 10 residual degrees of freedom under that rank calculation.

Software may omit a redundant column or report a warning. Inspect that output rather than counting every column name as a separately estimated coefficient.

Group indicators provide another example. An intercept plus an indicator for every one of three mutually exclusive, exhaustive groups is redundant: the indicators already sum to the intercept column. A valid parameterization can instead use an intercept and two group indicators. The fitted information, rather than the number of labels in the spreadsheet, determines the count.

What Degrees of Freedom Cannot Tell You

A count does not certify that a sample is representative or that a model is useful. Twelve selected observations can still omit the periods when a strategy failed. A regression with positive residual degrees of freedom can still fit noise.

Likewise, a larger count does not by itself establish independence. Repeated rows about the same event, overlapping returns, or common shocks can contain less independent information than their spreadsheet dimensions suggest.

Use degrees of freedom as part of a transparent calculation. Report the sample size, fitted parameters, method, and assumptions so a reader can understand where the count came from.

Frequently Asked Questions

Are Degrees of Freedom Always n Minus One?

No. That count applies to specific calculations, including the usual sample variance and one-sample t-test. Regression, independent-sample tests, ANOVA, and other methods use counts appropriate to their own fitted parameters and constraints.

Do Degrees of Freedom Have to Be Whole Numbers?

Not always. Exact counts of independent directions are integers, but approximations such as Welch's test can use fractional reference degrees of freedom. Identify the method before interpreting the reported value.

What If Residual Degrees of Freedom Are Zero?

The usual residual variance estimate cannot divide by zero. A model that uses all available degrees of freedom may interpolate the observations without providing the ordinary estimate of residual uncertainty. More data, fewer parameters, or a different justified method may be needed.

Author
Dale Hanson
Dale HansonCommunity Manager. X @InHansonWeTrust
Categories