Tutorials › Exam SRM - Statistics for Risk Modeling › Reading Deviance Degrees of Freedom

Exam SRM · Deviance and GLM Diagnostics · Tutorial 359 of 926

Reading Deviance Degrees of Freedom

Calculate residual degrees of freedom for GLMs by counting independent fitted parameters, and understand what that count does—and does not—say about residual deviance.

Advanced 10 min read

What You'll Learn

  • Calculate residual degrees of freedom from the number of response observations and the fitted model’s rank.
  • Count intercepts, factor contrasts, quantitative slopes, and interaction parameters.
  • Recognize why an offset is not an estimated regression coefficient.
  • Distinguish grouped-binomial response rows from the total number of trials.
  • Interpret residual deviance relative to its degrees of freedom without treating the ratio as a definitive test.
  • Identify how redundant or aliased model terms affect the parameter count.

Why Deviance Degrees of Freedom Matter

Residual deviance is interpreted relative to the degrees of freedom left after fitting a model. A deviance value by itself does not tell the whole story: the same value can represent a different degree of lack of fit when the model has a different number of fitted parameters. Correctly reading the reported degrees of freedom therefore starts with a careful count of the response observations and the independent parameters estimated by the model.

This tutorial focuses on that count and its interpretation for generalized linear models (GLMs). The principle is aligned with the SOA Exam SRM (Statistics for Risk Modeling) syllabus. It applies to standard GLM mean models, including Poisson, binomial, and Gamma models, while the conditions for treating deviance as approximately chi-square still need attention.

Definition: For a standard GLM fitted to \(n\) response observations, the residual degrees of freedom are ordinarily \(n-p\), where \(p\) is the rank of the fitted mean-model design matrix. Equivalently, \(p\) is the number of independently estimable regression coefficients, including the intercept when present. A coefficient that is redundant or not separately estimable does not increase \(p\).

What Counts as an Observation and a Parameter?

Here, \(n\) counts the response rows used to fit the model. Each row contributes one response observation to the fitted model. For individual binary data, a row commonly represents one Bernoulli outcome. For grouped binomial data, a row can represent a group with a number of successes out of a number of trials; the row is one response observation for this degrees-of-freedom calculation, even though it summarizes many trials.

The parameter count \(p\) is not simply the number of variable names in the model formula. It is the number of independent coefficients the fitted mean structure estimates. For example, a factor with \(K\) levels generally requires \(K-1\) coefficients when an intercept is included and one level is the reference. A quantitative predictor generally contributes one slope. Interactions contribute coefficients for the additional independent combinations represented by the interaction.

An offset is different from a coefficient: it is a known quantity included in the linear predictor with its coefficient fixed at one. It does not add an estimated regression parameter. Conversely, an intercept is estimated unless the model is explicitly specified without one, so it ordinarily counts toward \(p\).

Model componentUsual contribution to \(p\)Counting note
Intercept1Count it when the model estimates an intercept.
Quantitative predictor1 per estimated slopeA nonlinear basis expansion may require more than one coefficient.
Factor with \(K\) levels\(K-1\) with an interceptReference-level coding represents the factor using independent contrasts.
InteractionNumber of independent interaction coefficientsCount the terms actually estimable, not merely the number of labels in the formula.
Known offset0Its coefficient is fixed rather than estimated.

This table gives common counts, not a substitute for checking the fitted model. If columns of the design matrix are linearly dependent—for example, because a factor level is absent or a predictor is an exact combination of other predictors—the rank can be smaller than the nominal number of listed coefficients. Use the rank, or the number of coefficients actually estimated, rather than counting redundant columns twice.

Why the Formula Is \(n-p\)

A saturated model can assign a separate fitted mean to each of the \(n\) response observations. Its mean structure therefore has \(n\) independent dimensions in the usual setting. The fitted model restricts those means to a structure controlled by \(p\) independent coefficients. The number of dimensions left over after fitting is the difference between those dimensions.

$$ \text{Residual degrees of freedom} = \text{dimensions in the saturated mean model} - \text{dimensions in the fitted mean model} = n-p. $$

This dimension count explains why adding an independently estimable coefficient reduces residual degrees of freedom by one: the fitted model uses one more dimension to describe the responses. If a proposed term is redundant and adds no independent dimension, it does not reduce the residual degrees of freedom. This is a count of model dimensions, not a statement that each remaining degree of freedom corresponds to a particular observation or to a particular residual.

1
Identify the response rows.
Count the observations actually used in the fit. For grouped binomial data, count groups or rows, not the total number of trials.
2
Count independent fitted coefficients.
Include an estimated intercept, slopes, factor contrasts, and estimable interaction coefficients. Account for redundant terms by using the fitted model’s rank.
3
Subtract and interpret.
Calculate \(n-p\). A residual deviance may be compared with a chi-square reference distribution with these degrees of freedom when the usual large-sample approximation is appropriate.

That last condition matters. A chi-square reference for residual deviance is an approximation, not an automatic consequence of calculating \(n-p\). It is most defensible when the model is appropriate and the data provide enough information for the asymptotic approximation; sparse data or very small expected counts can make it unreliable. The residual degrees of freedom can still be reported and counted, but they do not by themselves certify a valid goodness-of-fit assessment.

Worked Parameter Counts

Worked Example: A Poisson Model With a Known Exposure Offset

A hypothetical insurer models claim counts for 48 independent policy segments using a Poisson GLM. The linear predictor contains an intercept, three quantitative predictors, a two-level territory indicator, and the logarithm of known exposure as an offset. The fitted residual deviance is 55.9. Find the residual degrees of freedom and describe the basic deviance comparison.

Method. Count the response rows and the independently estimated coefficients. The 48 policy-segment counts are 48 response observations, so \(n=48\).

The intercept contributes 1 coefficient. The three quantitative predictors contribute 3 slopes. A two-level indicator contributes 1 coefficient relative to its reference level. Thus

$$ p=1+3+1=5. $$

The exposure offset is known and has a fixed coefficient of one, so it contributes 0 estimated coefficients. Therefore,

$$ \text{Residual degrees of freedom}=48-5=43. $$

The residual deviance is 55.9 on 43 degrees of freedom. As a simple descriptive comparison, its ratio to the degrees of freedom is

$$ \frac{55.9}{43}=1.3. $$

The arithmetic checks because \(43(1.3)=55.9\). The ratio is a compact summary, not a substitute for assessing whether the chi-square approximation is suitable or for comparing the deviance with the appropriate reference distribution. Common mistake avoided: counting the known exposure offset as an additional coefficient would incorrectly give \(p=6\) and 42 residual degrees of freedom.

Worked Example: Grouped Binomial Rows Versus Trials

A hypothetical study records 24 groups of applicants. Each group has a number of approvals out of its own number of applications, and the group sizes sum to 960 applications. A binomial GLM includes an intercept, a three-level occupation factor, and two quantitative predictors. Find the residual degrees of freedom. Then find the degrees of freedom if an interaction between occupation and the first quantitative predictor is added, with all its coefficients estimable.

Original model. The 24 grouped responses give \(n=24\). The intercept contributes 1 coefficient, the three-level factor contributes \(3-1=2\) contrasts, and the two quantitative predictors contribute 2 slopes:

$$ p=1+2+2=5,\qquad 24-5=19. $$

The original model has 19 residual degrees of freedom. The total of 960 applications does not replace the 24 response rows in this calculation.

Model with the interaction. Interacting a three-level factor with one quantitative predictor adds \(3-1=2\) independent interaction coefficients, one for each nonreference occupation contrast. The new count is

$$ p_{\text{expanded}}=5+2=7,\qquad 24-7=17. $$

The expanded model has 17 residual degrees of freedom, two fewer than the original model because it adds two independently estimable coefficients. Common mistake avoided: using \(960-5\) would treat each individual application as a separate response row, although the fitted data consist of 24 grouped binomial responses.

Worked Example: Counting a Factor and Its Interaction

A hypothetical pricing analysis uses 40 response rows. The original model has an intercept, a three-level product factor, and one quantitative predictor. An expanded model adds an interaction between the factor and the predictor, and the interaction contributes two independent coefficients. Find the residual degrees of freedom for both models. The expanded model has residual deviance 35.6.

Original model. The intercept contributes 1 coefficient. The three-level factor contributes \(3-1=2\) contrasts. The quantitative predictor contributes 1 slope. Thus

$$ p_{\text{original}}=1+2+1=4, \qquad \text{df}_{\text{original}}=40-4=36. $$

Expanded model. The stated interaction contributes two independent coefficients, so the expanded parameter count is

$$ p_{\text{expanded}}=4+2=6, \qquad \text{df}_{\text{expanded}}=40-6=34. $$

The expanded residual deviance is therefore 35.6 on 34 residual degrees of freedom. Its deviance-to-degrees-of-freedom ratio is \(35.6/34\approx1.047\), or 1.05 to two decimal places. The key count is 4 coefficients in the original model, not 5: the three-level factor contributes two coefficients, not three. Common mistake avoided: counting all three factor levels as separate coefficients in addition to the intercept double-counts one degree of freedom in the factor coding.

Interpreting the Degrees of Freedom Carefully

When residual deviance is assessed against a chi-square reference, its reference degrees of freedom are the residual degrees of freedom for the fitted model. A larger fitted model usually has fewer residual degrees of freedom because it estimates more coefficients. This does not mean that its residual deviance must be smaller by a predictable amount, nor does a particular deviance-to-degrees-of-freedom ratio alone establish that the model fits adequately.

Parameter counting also depends on the data structure. For grouped binomial responses, the number of trials affects the likelihood and the information in the data, but it is not the number of response rows for the conventional residual degrees-of-freedom count. For Poisson models with exposure offsets, exposure values affect the mean structure through the offset, but the offset does not add an estimated coefficient. For factors and interactions, count independent contrasts and estimable terms rather than the raw number of category labels.

A related distinction is between regression coefficients and a dispersion parameter. The standard residual degrees-of-freedom convention for a GLM is based on the rank of its mean-model design matrix. A separately estimated dispersion parameter is not ordinarily included as one more regression coefficient in \(p\). The model family and the method used to assess fit still matter: a computed \(n-p\) does not on its own establish that a chi-square reference is appropriate.

Common Counting Traps

  • Counting factor levels instead of contrasts. With an intercept, a factor with \(K\) observed levels ordinarily contributes \(K-1\) coefficients, not \(K\).
  • Counting an offset as a fitted coefficient. A known offset enters with a fixed coefficient, so it contributes nothing to \(p\).
  • Using the total number of grouped trials as \(n\). For grouped binomial data, use the number of grouped response rows in the conventional residual degrees-of-freedom calculation.
  • Counting every formula term even if it is aliased. The relevant quantity is the design matrix rank, not the nominal count of columns before dependencies are accounted for.
  • Treating the chi-square comparison as automatic. The degrees-of-freedom formula is a dimension count; reliability of the deviance approximation depends on the model and data conditions.
Key takeaway: For a standard GLM, calculate residual degrees of freedom as the number of response rows minus the rank of the fitted mean-model design matrix. Count only independently estimated coefficients, and keep the degrees-of-freedom calculation separate from the question of whether a chi-square goodness-of-fit approximation is reliable.

Check Your Understanding

For each problem, count response rows first, then count independent fitted coefficients. Assume the specified terms are estimable unless the problem says otherwise.

  1. A Poisson model has 64 response rows, an intercept, and four quantitative predictors. What are its residual degrees of freedom? (Answer: 59)
  2. A grouped-binomial model has 15 response rows containing a total of 3,000 trials. It has an intercept, a three-level factor, and one quantitative predictor. Find the residual degrees of freedom. (Answer: 11)
  3. A model has 32 response rows, an intercept, two quantitative predictors, and a five-level factor. It also includes an interaction between that factor and one quantitative predictor. All interaction coefficients are estimable. Find the residual degrees of freedom. (Answer: 21)
  4. A model has 50 response rows and a design matrix with 8 listed columns, but one column is an exact linear combination of the others, leaving rank 7. Find the residual degrees of freedom. (Answer: 43)
  5. A Poisson model has 25 response rows, an intercept, two quantitative predictors, and a known exposure offset. Find its residual degrees of freedom, and state the result of incorrectly counting the offset as a coefficient. (Answer: 22 correctly; 21 if the offset is incorrectly counted)
Clinical Biostats