Tutorials › Exam SRM - Statistics for Risk Modeling › Degrees of Freedom and Mean Squares in ANOVA

Exam SRM · Inference and ANOVA · Tutorial 74 of 926

Degrees of Freedom and Mean Squares in ANOVA

Calculate regression ANOVA degrees of freedom and mean squares, then use them to construct and interpret the overall F test.

Intermediate 9 min read

What You'll Learn

  • Calculate regression, residual, and total degrees of freedom for a model with an intercept
  • Compute regression and residual mean squares from their sums of squares
  • Explain why the overall F statistic uses the ratio of these mean squares
  • State the assumptions behind the exact F distribution under the null hypothesis
  • Recognize why a full-rank saturated model has no residual mean square or overall F test
  • Avoid common degrees-of-freedom errors involving the intercept or predictor count

Why Degrees of Freedom and Mean Squares Matter

A regression ANOVA table separates the observed variation into a part associated with the fitted regression and a residual part. Degrees of freedom record how many independent pieces of information contribute to each sum of squares. Dividing each sum of squares by its degrees of freedom gives a mean square, and the ratio of the regression and residual mean squares is the overall F statistic.

The predictor count and the intercept both matter. In particular, a model with \(p\) predictors estimates \(p+1\) coefficients when it includes an intercept. A full-rank design matrix alone is not enough to guarantee that the residual mean square exists: there must also be more observations than fitted coefficients.

Definition: Consider a linear regression with an intercept and \(p\) predictors, fitted to \(n\) observations. Let \(\widehat{y}_i\) be the fitted value for observation \(i\), and let \(e_i=y_i-\widehat{y}_i\) be its residual. Define the regression, residual, and total sums of squares by $$ SS_{\mathrm{Reg}}=\sum_{i=1}^n(\widehat{y}_i-\bar{y})^2,\qquad SS_{\mathrm{Res}}=\sum_{i=1}^n e_i^2,\qquad SS_{\mathrm{Tot}}=\sum_{i=1}^n(y_i-\bar{y})^2. $$ For a model with an intercept, \(SS_{\mathrm{Tot}}=SS_{\mathrm{Reg}}+SS_{\mathrm{Res}}\). The corresponding mean squares are each sum of squares divided by its degrees of freedom.

Model, Assumptions, and Degrees of Freedom

Write the model for observation \(i\) as

$$ Y_i=\beta_0+\beta_1x_{i1}+\cdots+\beta_px_{ip}+\varepsilon_i,\qquad i=1,\ldots,n. $$

For the usual exact overall F test, treat the predictor values as fixed and assume that the errors are independent and identically distributed as \(N(0,\sigma^2)\), with \(\sigma^2>0\). The design matrix, including its intercept column, must have full column rank. To define the residual mean square and the overall F statistic, also require \(n>p+1\). If this last condition fails, the formulas that divide by residual degrees of freedom do not apply.

With an intercept, the fitted model estimates \(p+1\) coefficients. The total sum of squares is centered at \(\bar{y}\), which uses one degree of freedom for the estimated overall mean. The ANOVA degrees of freedom are therefore:

$$ df_{\mathrm{Reg}}=p,\qquad df_{\mathrm{Res}}=n-p-1,\qquad df_{\mathrm{Tot}}=n-1. $$

The degrees of freedom add: \(p+(n-p-1)=n-1\). The residual degrees of freedom count what remains after estimating the intercept and all \(p\) slopes. When \(n=p+1\), that count is zero; when \(n<p+1\), a full-column-rank design with an intercept is impossible.

Key result: For a full-rank regression with an intercept and \(n>p+1\), the regression and residual mean squares are $$ MS_{\mathrm{Reg}}=\frac{SS_{\mathrm{Reg}}}{p},\qquad MS_{\mathrm{Res}}=\frac{SS_{\mathrm{Res}}}{n-p-1}. $$ The overall F statistic is \(F=MS_{\mathrm{Reg}}/MS_{\mathrm{Res}}\). Its exact null distribution requires the stated independent normal, constant-variance error assumptions.

Why the Mean-Square Ratio Gives an F Test

The overall test asks whether the predictors, considered jointly, contribute linear signal beyond an intercept-only model:

$$ H_0:\beta_1=\cdots=\beta_p=0 \qquad\text{versus}\qquad H_A:\text{at least one }\beta_j\ne 0. $$

Under the null hypothesis, both mean squares estimate the same error variance \(\sigma^2\). The residual mean square measures variation left after fitting the model. Under the null, the regression mean square also reflects only error variation, after accounting for its \(p\) degrees of freedom. If the fitted predictors explain substantial variation relative to the residual variation, the ratio is large.

1
Separate the fitted and residual parts.
With an intercept, the centered total variation decomposes into regression and residual sums of squares: \(SS_{\mathrm{Tot}}=SS_{\mathrm{Reg}}+SS_{\mathrm{Res}}\).
2
Count independent directions.
The regression component has \(p\) degrees of freedom, while the residual component has \(n-p-1\). Under the null, these components are orthogonal projections of the normal error vector.
3
Scale by degrees of freedom.
Under \(H_0\), \(SS_{\mathrm{Reg}}/\sigma^2\) and \(SS_{\mathrm{Res}}/\sigma^2\) have independent chi-square distributions with \(p\) and \(n-p-1\) degrees of freedom. Dividing each by its degrees of freedom gives two independent estimates of \(\sigma^2\).
4
Form the ratio.
The ratio of independent chi-square variables after division by their respective degrees of freedom has an F distribution. Thus, under \(H_0\), \(F=MS_{\mathrm{Reg}}/MS_{\mathrm{Res}}\sim F_{p,n-p-1}\).

The degree-of-freedom counts can also be seen from the projection ranks. The full fitted model has \(p+1\) independent coefficient directions; the intercept-only fit has one. The regression component therefore has rank \((p+1)-1=p\). The residual projection has rank \(n-(p+1)=n-p-1\), while centering the response leaves total rank \(n-1\). This argument explains both the counts and why zero residual degrees of freedom make a residual variance estimate unavailable.

Worked Calculations

Worked Example: Overall Test with One Predictor

A hypothetical insurer models a monthly claim-handling measure using one predictor and an intercept. There are \(n=10\) observations, and the fitted regression output gives \(SS_{\mathrm{Reg}}=32\) and \(SS_{\mathrm{Res}}=56\). Find all three degrees of freedom, both mean squares, and the overall F statistic. Assume the full-rank design and the normal, independent, constant-variance error model.

Method. Here \(p=1\). First calculate the degrees of freedom:

Regression: \(df_{\mathrm{Reg}}=p=1\). Residual: \(df_{\mathrm{Res}}=n-p-1=10-1-1=8\). Total: \(df_{\mathrm{Tot}}=n-1=9\). The check \(1+8=9\) confirms the degrees of freedom add correctly. Also, \(10>1+1\), so the residual degrees of freedom are positive.

Calculate the mean squares:

\(MS_{\mathrm{Reg}}=32/1=32\). \(MS_{\mathrm{Res}}=56/8=7\).

The overall statistic is \(F=32/7=4.5714\) to four decimal places. Under the joint null that the sole slope is zero, its reference distribution is \(F_{1,8}\). The test compares this observed value with the appropriate upper-tail reference distribution or critical value at the chosen significance level.

Check. The total sum of squares is \(32+56=88\), and the degrees of freedom satisfy \(1+8=9\). A common mistake avoided here is using the total degrees of freedom as the denominator for the residual mean square; the correct divisor is the residual degrees of freedom, 8.

Worked Example: Three Predictors and the Intercept Count

A hypothetical pricing analysis uses \(n=15\) observations and three predictors, along with an intercept. The regression and residual sums of squares are \(SS_{\mathrm{Reg}}=72\) and \(SS_{\mathrm{Res}}=88\). Calculate the ANOVA degrees of freedom, mean squares, and overall F statistic.

Method. Set \(p=3\). There are four estimated coefficients because the intercept is included. Therefore, \(df_{\mathrm{Reg}}=3\), \(df_{\mathrm{Res}}=15-3-1=11\), and \(df_{\mathrm{Tot}}=15-1=14\). The check is \(3+11=14\), and the positive residual degrees of freedom confirm that the mean square is defined.

Now divide each sum of squares by its corresponding degrees of freedom:

\(MS_{\mathrm{Reg}}=72/3=24\). \(MS_{\mathrm{Res}}=88/11=8\).

Thus \(F=24/8=3\). Under the joint null that all three slopes are zero, the reference distribution is \(F_{3,11}\). This is one joint test of the three slope coefficients, not three separate tests.

Common mistake and correction. Omitting the intercept from the parameter count gives the wrong residual degrees of freedom, \(15-3=12\). That incorrect divisor produces \(88/12=7.3333\) for the residual mean square and a wrong F ratio of \(24/7.3333\approx3.2727\). The intercept must be counted, so the correct residual degrees of freedom are 11, the correct residual mean square is 8, and the correct F statistic is 3.

Check. The sums of squares add to \(72+88=160\), so the total sum of squares is 160, and \(3+11=14\) for the degrees of freedom.

Worked Example: A Full-Rank Model with No Residual Degrees of Freedom

A study fits a regression with an intercept and \(p=5\) predictors to \(n=6\) observations. The design matrix has full column rank, and the fitted values reproduce all six observed responses, so \(SS_{\mathrm{Res}}=0\) and \(SS_{\mathrm{Reg}}=34\). Determine the degrees of freedom and whether the usual overall F statistic can be calculated.

Method. The fitted model has \(p+1=6\) coefficient directions. The degrees of freedom are \(df_{\mathrm{Reg}}=5\), \(df_{\mathrm{Res}}=6-5-1=0\), and \(df_{\mathrm{Tot}}=6-1=5\). The degree-of-freedom check is \(5+0=5\).

Although the design matrix has full column rank, \(n=p+1\), so the model is saturated: it can fit all six responses exactly. The residual mean square would require \(SS_{\mathrm{Res}}/df_{\mathrm{Res}}=0/0\), which is undefined. Consequently, the usual overall F statistic is also undefined. The regression mean square alone is \(34/5=6.8\), but it cannot be divided by a residual mean square to form the F test.

Check. The sums of squares add to \(34+0=34\), consistent with the stated total variation. Full column rank permits coefficient estimation here; it does not create residual degrees of freedom. The overall F test requires the additional condition \(n>p+1\).

Common Traps and Interpretation

The overall F statistic is a ratio of mean squares, not a ratio of raw sums of squares. Dividing by degrees of freedom matters because the regression and residual components generally have different numbers of degrees of freedom. The test is also a joint test: a large statistic provides evidence against the hypothesis that all slopes are zero, but it does not by itself identify which slope is responsible.

  • Forgetting the intercept: In a model with \(p\) predictors and an intercept, there are \(p+1\) fitted coefficients. The residual degrees of freedom are \(n-p-1\), not \(n-p\).
  • Using the wrong divisor: Divide \(SS_{\mathrm{Reg}}\) by \(p\), and divide \(SS_{\mathrm{Res}}\) by \(n-p-1\). Do not divide both sums by \(n-1\).
  • Assuming full rank is sufficient: A full-rank saturated model can have zero residual degrees of freedom. The standard residual mean square and overall F statistic require \(n>p+1\).
  • Applying the exact F reference distribution without its assumptions: The standard finite-sample result relies on independent normal errors with constant variance. Without those conditions, the ratio need not have the stated exact F distribution.
  • Confusing a large ratio with a standalone conclusion: A test decision also depends on the selected significance level and the relevant \(F_{p,n-p-1}\) reference distribution.
Key takeaway: For an intercept model with \(p\) predictors, the ANOVA degrees of freedom are \(p\), \(n-p-1\), and \(n-1\). Divide each regression or residual sum of squares by its own degrees of freedom before forming the overall F ratio, and verify \(n>p+1\) before using that ratio.

Check Your Understanding

For each problem, calculate the requested quantities using an intercept model. Assume the stated sums of squares come from the fitted regression.

  1. A simple regression has \(n=9\), \(SS_{\mathrm{Reg}}=18\), and \(SS_{\mathrm{Res}}=48\). Find the three degrees of freedom, both mean squares, and the overall F statistic. (Answer: regression, residual, and total df \(=1,7,8\); \(MS_{\mathrm{Reg}}=18\), \(MS_{\mathrm{Res}}=48/7\approx6.8571\), \(F=2.6250\).)
  2. A model has \(n=14\), \(p=2\), \(SS_{\mathrm{Reg}}=30\), and \(SS_{\mathrm{Res}}=66\). Find the degrees of freedom and the overall F statistic. (Answer: df \(=2,11,13\); \(MS_{\mathrm{Reg}}=15\), \(MS_{\mathrm{Res}}=6\), \(F=2.5\).)
  3. A four-predictor model uses \(n=20\) observations, with \(SS_{\mathrm{Reg}}=100\) and \(SS_{\mathrm{Res}}=75\). Find all three degrees of freedom, both mean squares, and the null reference distribution. (Answer: df \(=4,15,19\); \(MS_{\mathrm{Reg}}=25\), \(MS_{\mathrm{Res}}=5\), \(F=5\), with null reference distribution \(F_{4,15}\).)
  4. A full-rank model includes an intercept and seven predictors fitted to eight observations. State the residual degrees of freedom and whether the usual overall F statistic is defined. (Answer: residual df \(=8-7-1=0\); the usual residual mean square and overall F statistic are undefined.)
  5. An intercept model has four predictors and residual degrees of freedom 9. Its sums of squares are \(SS_{\mathrm{Reg}}=36\) and \(SS_{\mathrm{Res}}=45\). Recover \(n\), the other two degrees of freedom, the mean squares, and the F statistic. (Answer: \(n=9+4+1=14\); regression df \(=4\), total df \(=13\); \(MS_{\mathrm{Reg}}=9\), \(MS_{\mathrm{Res}}=5\), \(F=1.8\).)
Clinical Biostats