In statistics, the number of degrees of freedom is the number of values in the final calculation of a statistic that are free to vary.[1]
Estimates of statistical parameters can be based upon different amounts of information or data. The number of independent pieces of information that go into the estimate of a parameter is called the degrees of freedom. In general, the degrees of freedom of an estimate of a parameter are equal to the number of independent scores that go into the estimate minus the number of parameters used as intermediate steps in the estimation of the parameter itself. For example, if the variance is to be estimated from a random sample of independent scores, then the degrees of freedom is equal to the number of independent scores (N) minus the number of parameters estimated as intermediate steps (one, namely, the sample mean) and is therefore equal to .[2]
Mathematically, degrees of freedom is the number of dimensions of the domain of a random vector, or essentially the number of "free" components (how many components need to be known before the vector is fully determined).
The term is most often used in the context of linear models (linear regression, analysis of variance), where certain random vectors are constrained to lie in linear subspaces, and the number of degrees of freedom is the dimension of the subspace. The degrees of freedom are also commonly associated with the squared lengths (or "sum of squares" of the coordinates) of such vectors, and the parameters of chi-squared and other distributions that arise in associated statistical testing problems.
While introductory textbooks may introduce degrees of freedom as distribution parameters or through hypothesis testing, it is the underlying geometry that defines degrees of freedom, and is critical to a proper understanding of the concept.
Although the basic concept of degrees of freedom was recognized as early as 1821 in the work of German astronomer and mathematician Carl Friedrich Gauss,[3] its modern definition and usage was first elaborated by English statistician William Sealy Gosset in his 1908 Biometrika article "The Probable Error of a Mean", published under the pen name "Student".[4] While Gosset did not actually use the term 'degrees of freedom', he explained the concept in the course of developing what became known as Student's t-distribution. The term itself was popularized by English statistician and biologist Ronald Fisher, beginning with his 1922 work on chi squares.[5]
In equations, the typical symbol for degrees of freedom is ν (lowercase Greek letter nu). In text and tables, the abbreviation "d.f." is commonly used. R. A. Fisher used n to symbolize degrees of freedom but modern usage typically reserves n for sample size.
Geometrically, the degrees of freedom can be interpreted as the dimension of certain vector subspaces. As a starting point, suppose that we have a sample of independent normally distributed observations,
X1,...,Xn.
This can be represented as an n-dimensional random vector:
\begin{pmatrix}X1\ \vdots\ Xn\end{pmatrix}.
Since this random vector can lie anywhere in n-dimensional space, it has n degrees of freedom.
Now, let
\barX
\begin{pmatrix}X1\ \vdots\ Xn\end{pmatrix} =\barX\begin{pmatrix}1\ \vdots\ 1\end{pmatrix} +\begin{pmatrix}X1-\bar{X}\ \vdots\ Xn-\bar{X}\end{pmatrix}.
The first vector on the right-hand side is constrained to be a multiple of the vector of 1's, and the only free quantity is
\barX
The second vector is constrained by the relation . The first n − 1 components of this vector can be anything. However, once you know the first n − 1 components, the constraint tells you the value of the nth component. Therefore, this vector has n − 1 degrees of freedom.
Mathematically, the first vector is the oblique projection of the data vector onto the subspace spanned by the vector of 1's. The 1 degree of freedom is the dimension of this subspace. The second residual vector is the least-squares projection onto the (n − 1)-dimensional orthogonal complement of this subspace, and has n − 1 degrees of freedom.
In statistical testing applications, often one is not directly interested in the component vectors, but rather in their squared lengths. In the example above, the residual sum-of-squares is
n | |
\sum | |
i=1 |
(Xi-\bar{X})2=\begin{Vmatrix}X1-\bar{X}\ \vdots\ Xn-\bar{X}\end{Vmatrix}2.
If the data points
Xi
\sigma2
\sigma2
Likewise, the one-sample t-test statistic,
\sqrt{n | |
(\bar{X}-\mu |
0)}{
n | |
\sqrt{\sum\limits | |
i=1 |
2 | |
(X | |
i-\bar{X}) |
/(n-1)}}
\mu0
When the results of structural equation models (SEM) are presented, they generally include one or more indices of overall model fit, the most common of which is a χ2 statistic. This forms the basis for other indices that are commonly reported. Although it is these other statistics that are most commonly interpreted, the degrees of freedom of the χ2 are essential to understanding model fit as well as the nature of the model itself.
Degrees of freedom in SEM are computed as a difference between the number of unique pieces of information that are used as input into the analysis, sometimes called knowns, and the number of parameters that are uniquely estimated, sometimes called unknowns. For example, in a one-factor confirmatory factor analysis with 4 items, there are 10 knowns (the six unique covariances among the four items and the four item variances) and 8 unknowns (4 factor loadings and 4 error variances) for 2 degrees of freedom. Degrees of freedom are important to the understanding of model fit if for no other reason than that, all else being equal, the fewer degrees of freedom, the better indices such as χ2 will be.
It has been shown that degrees of freedom can be used by readers of papers that contain SEMs to determine if the authors of those papers are in fact reporting the correct model fit statistics. In the organizational sciences, for example, nearly half of papers published in top journals report degrees of freedom that are inconsistent with the models described in those papers, leaving the reader to wonder which models were actually tested.[6]
A common way to think of degrees of freedom is as the number of independent pieces of information available to estimate another piece of information. More concretely, the number of degrees of freedom is the number of independent observations in a sample of data that are available to estimate a parameter of the population from which that sample is drawn. For example, if we have two observations, when calculating the mean we have two independent observations; however, when calculating the variance, we have only one independent observation, since the two observations are equally distant from the sample mean.
In fitting statistical models to data, the vectors of residuals are constrained to lie in a space of smaller dimension than the number of components in the vector. That smaller dimension is the number of degrees of freedom for error, also called residual degrees of freedom.
Perhaps the simplest example is this. Suppose
X1,...,Xn
\overline{X}n=
X1+ … +Xn | |
n |
Xi-\overline{X}n
An example which is only slightly less simple is that of least squares estimation of a and b in the model
Yi=a+bxi+eifori=1,...,n
\widehat{a}
\widehat{b}
\widehat{e}i=yi-(\widehat{a}+\widehat{b}xi)
are constrained to lie within the space defined by the two equations
\widehat{e}1+ … +\widehat{e}n=0,
x1\widehat{e}1+ … +xn\widehat{e}n=0.
One says that there are n − 2 degrees of freedom for error.
Notationally, the capital letter Y is used in specifying the model, while lower-case y in the definition of the residuals; that is because the former are hypothesized random variables and the latter are actual data.
We can generalise this to multiple regression involving p parameters and covariates (e.g. p − 1 predictors and one mean (=intercept in the regression)), in which case the cost in degrees of freedom of the fit is p, leaving n - p degrees of freedom for errors
The demonstration of the t and chi-squared distributions for one-sample problems above is the simplest example where degrees-of-freedom arise. However, similar geometry and vector decompositions underlie much of the theory of linear models, including linear regression and analysis of variance. An explicit example based on comparison of three means is presented here; the geometry of linear models is discussed in more complete detail by Christensen (2002).[7]
Suppose independent observations are made for three populations,
X1,\ldots,Xn
Y1,\ldots,Yn
Z1,\ldots,Zn
The observations can be decomposed as
\begin{align} Xi&=\bar{M}+(\bar{X}-\bar{M})+(Xi-\bar{X})\\ Yi&=\bar{M}+(\bar{Y}-\bar{M})+(Yi-\bar{Y})\\ Zi&=\bar{M}+(\bar{Z}-\bar{M})+(Zi-\bar{Z}) \end{align}
\bar{X},\bar{Y},\bar{Z}
\bar{M}=(\bar{X}+\bar{Y}+\bar{Z})/3
\begin{pmatrix}X1\ \vdots\ Xn\ Y1\ \vdots\ Yn\ Z1\ \vdots\ Zn\end{pmatrix} =\bar{M}\begin{pmatrix}1\ \vdots\ 1\ 1\ \vdots\ 1\ 1\ \vdots\ 1\end{pmatrix} +\begin{pmatrix}\bar{X}-\bar{M}\ \vdots\ \bar{X}-\bar{M}\\ \bar{Y}-\bar{M}\ \vdots\ \bar{Y}-\bar{M}\\ \bar{Z}-\bar{M}\ \vdots\ \bar{Z}-\bar{M}\end{pmatrix} +\begin{pmatrix}X1-\bar{X}\ \vdots\ Xn-\bar{X}\\ Y1-\bar{Y}\ \vdots\ Yn-\bar{Y}\\ Z1-\bar{Z}\ \vdots\ Zn-\bar{Z}\end{pmatrix}.
The observation vector, on the left-hand side, has 3n degrees of freedom. On the right-hand side, the first vector has one degree of freedom (or dimension) for the overall mean. The second vector depends on three random variables,
\bar{X}-\bar{M}
\bar{Y}-\bar{M}
\overline{Z}-\overline{M}
In statistical testing problems, one usually is not interested in the component vectors themselves, but rather in their squared lengths, or Sum of Squares. The degrees of freedom associated with a sum-of-squares is the degrees-of-freedom of the corresponding component vectors.
The three-population example above is an example of one-way Analysis of Variance. The model, or treatment, sum-of-squares is the squared length of the second vector,
SST=n(\bar{X}-\bar{M})2+n(\bar{Y}-\bar{M})2+n(\bar{Z}-\bar{M})2
SSE=
n | |
\sum | |
i=1 |
2 | |
(X | |
i-\bar{X}) |
+
n | |
\sum | |
i=1 |
2 | |
(Y | |
i-\bar{Y}) |
+
n | |
\sum | |
i=1 |
2 | |
(Z | |
i-\bar{Z}) |
Under the null hypothesis of no difference between population means (and assuming that standard ANOVA regularity assumptions are satisfied) the sums of squares have scaled chi-squared distributions, with the corresponding degrees of freedom. The F-test statistic is the ratio, after scaling by the degrees of freedom. If there is no difference between population means this ratio follows an F-distribution with 2 and 3n − 3 degrees of freedom.
In some complicated settings, such as unbalanced split-plot designs, the sums-of-squares no longer have scaled chi-squared distributions. Comparison of sum-of-squares with degrees-of-freedom is no longer meaningful, and software may report certain fractional 'degrees of freedom' in these cases. Such numbers have no genuine degrees-of-freedom interpretation, but are simply providing an approximate chi-squared distribution for the corresponding sum-of-squares. The details of such approximations are beyond the scope of this page.
Several commonly encountered statistical distributions (Student's t, chi-squared, F) have parameters that are commonly referred to as degrees of freedom. This terminology simply reflects that in many applications where these distributions occur, the parameter corresponds to the degrees of freedom of an underlying random vector, as in the preceding ANOVA example. Another simple example is: if
Xi;i=1,\ldots,n
(\mu,\sigma2)
| |||||||||
) |
2}{\sigma2}
\{Xi-\bar{X}\}
In the application of these distributions to linear models, the degrees of freedom parameters can take only integer values. The underlying families of distributions allow fractional values for the degrees-of-freedom parameters, which can arise in more sophisticated uses. One set of examples is problems where chi-squared approximations based on effective degrees of freedom are used. In other applications, such as modelling heavy-tailed data, a t or F-distribution may be used as an empirical model. In these cases, there is no particular degrees of freedom interpretation to the distribution parameters, even though the terminology may continue to be used.
Many non-standard regression methods, including regularized least squares (e.g., ridge regression), linear smoothers, smoothing splines, and semiparametric regression, are not based on ordinary least squares projections, but rather on regularized (generalized and/or penalized) least-squares, and so degrees of freedom defined in terms of dimensionality is generally not useful for these procedures. However, these procedures are still linear in the observations, and the fitted values of the regression can be expressed in the form
\hat{y}=Hy,
\hat{y}
For statistical inference, sums-of-squares can still be formed: the model sum-of-squares is
\|Hy\|2
\|y-Hy\|2
The effective degrees of freedom of the fit can be defined in various ways to implement goodness-of-fit tests, cross-validation, and other statistical inference procedures. Here one can distinguish between regression effective degrees of freedom and residual effective degrees of freedom.
For the regression effective degrees of freedom, appropriate definitions can include the trace of the hat matrix,[8] tr(H), the trace of the quadratic form of the hat matrix, tr(H'H), the form tr(2H – H H), or the Satterthwaite approximation, .[9] In the case of linear regression, the hat matrix H is X(X 'X)−1X ', and all these definitions reduce to the usual degrees of freedom. Notice that
\operatorname{tr}(H)=\sumihii=\sumi
\partial\hat{y | |
i}{\partial |
yi},
the regression (not residual) degrees of freedom in linear models are "the sum of the sensitivities of the fitted values with respect to the observed response values",[10] i.e. the sum of leverage scores.
One way to help to conceptualize this is to consider a simple smoothing matrix like a Gaussian blur, used to mitigate data noise. In contrast to a simple linear or polynomial fit, computing the effective degrees of freedom of the smoothing function is not straightforward. In these cases, it is important to estimate the Degrees of Freedom permitted by the
H
\chi2
There are corresponding definitions of residual effective degrees-of-freedom (redf), with H replaced by I − H. For example, if the goal is to estimate error variance, the redf would be defined as tr((I − H)'(I − H)), and the unbiased estimate is (with
\hat{r}=y-Hy
\hat\sigma2=
\|\hat{r | |
\| |
2}{\operatorname{tr}\left((I-H)'(I-H)\right)},
\hat\sigma2=
\|\hat{r | |
\| |
2}{n-\operatorname{tr}(2H-HH')}=
\|\hat{r | |
\| |
2}{n-2\operatorname{tr}(H)+\operatorname{tr}(HH')}
\hat\sigma2 ≈
\|\hat{r | |
\| |
2}{n-1.25\operatorname{tr}(H)+0.5}.
The last approximation above[12] reduces the computational cost from O(n2) to only O(n). In general the numerator would be the objective function being minimized; e.g., if the hat matrix includes an observation covariance matrix, Σ, then
\|\hat{r}\|2
\hat{r}'\Sigma-1\hat{r}
Note that unlike in the original case, non-integer degrees of freedom are allowed, though the value must usually still be constrained between 0 and n.[15]
Consider, as an example, the k-nearest neighbour smoother, which is the average of the k nearest measured values to the given point. Then, at each of the n measured points, the weight of the original value on the linear combination that makes up the predicted value is just 1/k. Thus, the trace of the hat matrix is n/k. Thus the smooth costs n/k effective degrees of freedom.
As another example, consider the existence of nearly duplicated observations. Naive application of classical formula, n − p, would lead to over-estimation of the residuals degree of freedom, as if each observation were independent. More realistically, though, the hat matrix