Understanding the degrees of freedom calculator — concept and principle
This calculator gives the degrees of freedom (df) for common statistical tests: one-sample and paired t-tests, two-sample t-tests with equal or unequal variances (Welch), chi-square goodness of fit and independence, one-way ANOVA and linear regression. The df decide which t, χ² or F distribution gives the p-value.
How it is calculated
- One-sample or paired t-test: n − 1.
- Two-sample t-test, equal variances: n₁ + n₂ − 2.
- Welch t-test: df = (s₁²/n₁ + s₂²/n₂)² ÷ [(s₁²/n₁)²/(n₁ − 1) + (s₂²/n₂)²/(n₂ − 1)].
- Chi-square goodness of fit: k − 1; test of independence: (r − 1)(c − 1).
- One-way ANOVA: k − 1 between groups and N − k within groups.
- Regression with p predictors and an intercept: n − p − 1 for the residuals.
The principle
Every statistic estimated from the data uses up some of its freedom. With n values and a known mean, only n − 1 values can be chosen freely; the last is fixed. Fewer degrees of freedom mean more uncertainty in estimates such as the standard deviation, so test distributions get heavier tails. Welch's formula blends the two samples' information according to how much each contributes to the standard error, which is why it usually gives a fractional df between the smaller sample's n − 1 and n₁ + n₂ − 2.
Worked example
Default inputs: Welch t-test, n₁ = 12, n₂ = 15, s₁ = 4.2, s₂ = 6.8.
- s₁²/n₁ = 17.64 ÷ 12 = 1.47; s₂²/n₂ = 46.24 ÷ 15 = 3.0827.
- Numerator = (1.47 + 3.0827)² = 4.5527² = 20.727.
- Denominator = 1.47² ÷ 11 + 3.0827² ÷ 14 = 0.19645 + 0.67878 = 0.87523.
- df = 20.727 ÷ 0.87523 = 23.6818, using inputs n₁, n₂, s₁, s₂.
- Rounded down (conservative) = 23; the equal-variance df would be 12 + 15 − 2 = 25.
| Sample size n (n₁; total N for ANOVA) | Degrees of freedom |
|---|---|
| 3 | 4.4712 |
| 6 | 15.0665 |
| 9 | 21.9405 |
| 12 | 23.6818 |
| 15 | 23.3246 |
| 18 | 22.448 |
| 24 | 20.7538 |
How to read the result
Software uses the fractional Welch df directly; printed tables need it rounded down, which gives a slightly larger critical value and a more cautious test. Here the Welch df is lower than 25 because the second group is more variable, so its uncertainty dominates. Larger df bring t and χ²-based tests closer to their large-sample forms.
Common mistakes
- Using n instead of n − 1 for a one-sample t-test.
- Counting cells instead of (r − 1)(c − 1) in a contingency table.
- Using n₁ + n₂ − 2 when the variances are clearly unequal.
- Forgetting to subtract the intercept in regression.
Frequently asked questions
Why is it n − 1 and not n?
One degree of freedom is used up by estimating the mean from the same data.
Why is Welch's df not a whole number?
It is an approximation that weights each sample's variance; software accepts fractional df.
What are the df for a 3 × 4 chi-square table?
(3 − 1)(4 − 1) = 6.
Sources: NIST/SEMATECH e-Handbook of Statistical Methods, §1.3.5.3 Two-Sample t-Test for Equal Means