Tutorials › Exam PA - Predictive Analytics › Residual Deviance and Degrees of Freedom

Exam PA · Model Comparison, Offsets, and Weights · Tutorial 368 of 966

Residual Deviance and Degrees of Freedom

Interpret residual deviance and residual degrees of freedom in context, including their assumptions, calculations, and limits as evidence of model fit.

Advanced 12 min read

What You'll Learn

  • Define residual deviance relative to the saturated model.
  • Calculate deviance for Poisson and grouped-binomial examples.
  • Determine residual degrees of freedom using the rank of the model matrix.
  • Interpret deviance in relation to degrees of freedom without treating a ratio as a universal rule.
  • Recognize why in-sample fit summaries do not establish predictive quality.

What Residual Deviance Summarizes

A fitted generalized linear model (GLM) gives a compact description of how the response changes with its predictors. Residual deviance summarizes one aspect of that description: how much less closely the fitted model matches the observed responses than a saturated model does. Residual degrees of freedom describe how many independent pieces of information remain after estimating the model parameters. Both are useful summaries, but neither by itself establishes that a model is appropriate or predicts well for new cases.

Definition: The residual deviance is twice the difference between the maximized log-likelihood of a saturated model and the maximized log-likelihood of the fitted model, using the same response data and likelihood convention: $$ D_{\mathrm{res}}=2\{\ell_{\mathrm{sat}}-\ell_{\mathrm{fit}}\}. $$ A saturated model fits each independent response unit as closely as the model family permits. Smaller residual deviance means the fitted model is closer to that saturated fit on the observed data; it does not, on its own, mean the model predicts well.

The precise numerical deviance depends on the response distribution and on how the observations are represented. For example, a binomial response can be stored as individual zeros and ones or as success and failure counts for groups. The grouped representation compares each group’s observed success count with its fitted expected count. The model and the form of the data must therefore be clear before interpreting a deviance value.

Residual Degrees of Freedom

For a GLM fitted to \(m\) independent response units with a fixed design matrix \(X\), the usual residual degrees of freedom are

$$ \operatorname{df}_{\mathrm{res}}=m-\operatorname{rank}(X). $$

Here, \(\operatorname{rank}(X)\) is the number of linearly independent columns in the model matrix, including the intercept column if the model has an intercept. It is not necessarily the number of columns originally specified: redundant columns do not add estimable parameters. The count \(m\) is the number of independent response units represented in the likelihood. For grouped-binomial data, it is ordinarily the number of groups, not the total number of trials across the groups.

An offset is a known component of the linear predictor, not an estimated coefficient, so it does not increase the model-matrix rank. Other features of a data analysis, such as estimated dispersion parameters or non-independent responses, can affect how degrees of freedom and fit summaries should be interpreted. The simple formula above applies to the usual fixed-design GLM setting with independent response units.

Worked Example: An Intercept-Only Poisson Model

A hypothetical maintenance team records the number of equipment alerts on four comparable shifts: \(0,1,2,3\). Fit an intercept-only Poisson GLM, then find its residual deviance and residual degrees of freedom. Use natural logarithms, and round the deviance to four decimal places.

Method and fitted mean. Under an intercept-only Poisson model, each shift has the same fitted mean. The maximum-likelihood estimate is the sample mean: $$ \hat{\mu}=\frac{0+1+2+3}{4}=\frac{6}{4}=1.5. $$ The model estimates one coefficient, the intercept. The model matrix has rank 1, so the residual degrees of freedom are \(4-1=3\).

Deviance calculation. For a Poisson observation \(y\) with fitted mean \(\hat{\mu}\), its contribution is \(2\{y\log(y/\hat{\mu})-(y-\hat{\mu})\}\), with the \(y\log(y/\hat{\mu})\) term defined as zero when \(y=0\). The four contributions are:

For \(y=0\), the contribution is \(2(1.5)=3.000000\).

For \(y=1\), it is \(2\{\log(1/1.5)+0.5\}=2\{ -0.4054651+0.5\}=0.1890698\).

For \(y=2\), it is \(2\{2\log(2/1.5)-0.5\}=2\{2(0.2876821)-0.5\}=0.1507283\).

For \(y=3\), it is \(2\{3\log(3/1.5)-1.5\}=2\{3(0.6931472)-1.5\}=1.1588831\).

Adding the contributions gives \(3.0000000+0.1890698+0.1507283+1.1588831=4.4986812\), so the residual deviance is 4.4987 to four decimal places. The result is consistent with the definition: all contributions are nonnegative, and each would be zero if the fitted mean equalled that observation.

Common mistake avoided. The observed total is 6, but the fitted value for each shift is 1.5; using 6 as the fitted mean would confuse the total count with the mean count per response unit.

Why the Deviance Formula Works

The likelihood-ratio form of deviance follows directly from comparing the two fitted likelihoods. The saturated model has at least as much flexibility as the fitted model, so its maximized log-likelihood cannot be smaller. The likelihood ratio in favor of the saturated model is \(\exp(\ell_{\mathrm{sat}}-\ell_{\mathrm{fit}})\). Taking twice its natural logarithm gives the deviance:

1
Fit both models to the same response data.
The fitted model uses the specified predictors and link; the saturated model fits each response unit as closely as the family allows.
2
Compare their maximized log-likelihoods.
Because the saturated model is at least as flexible, \(\ell_{\mathrm{sat}}\geq\ell_{\mathrm{fit}}\), subject to the same likelihood convention.
3
Express the comparison as a likelihood ratio.
The ratio is \(\exp(\ell_{\mathrm{sat}}-\ell_{\mathrm{fit}})\); twice its log is \(2\{\ell_{\mathrm{sat}}-\ell_{\mathrm{fit}}\}\), the residual deviance.

For independent Poisson observations \(y_j\) with fitted means \(\hat{\mu}_j\), the saturated model sets its mean for unit \(j\) to \(y_j\). Subtracting the fitted log-likelihood from the saturated log-likelihood cancels terms that are common to both models and gives

$$ D_{\mathrm{res}}=2\sum_{j=1}^{m}\left\{y_j\log\left(\frac{y_j}{\hat{\mu}_j}\right)-(y_j-\hat{\mu}_j)\right\}, $$

where a term \(y_j\log(y_j/\hat{\mu}_j)\) is taken to be zero when \(y_j=0\). This formula assumes the ordinary Poisson likelihood with a positive fitted mean for each unit. It is not a generic formula to apply unchanged to every response family.

For grouped-binomial observations with \(y_j\) successes from \(n_j\) trials and fitted probability \(\hat{p}_j\), the corresponding deviance is

$$ D_{\mathrm{res}}=2\sum_{j=1}^{m}\left\{ y_j\log\left(\frac{y_j}{n_j\hat{p}_j}\right) +(n_j-y_j)\log\left(\frac{n_j-y_j}{n_j(1-\hat{p}_j)}\right) \right\}, $$

with a zero-count logarithmic term defined as zero. This expression assumes binomial sampling within each group and fitted probabilities strictly between zero and one; boundary cases require the corresponding likelihood limits. The saturated model has a separate fitted probability for each group.

Worked Example: Grouped-Binomial Deviance and Degrees of Freedom

A hypothetical study records successes in three groups, each with 10 trials: \(2,5,8\) successes. Fit an intercept-only binomial GLM. Find the common fitted probability, residual degrees of freedom, and residual deviance. Round the deviance to four decimal places.

Method and fitted probability. The total number of successes is \(2+5+8=15\), and the total number of trials is \(30\). Therefore the intercept-only maximum-likelihood estimate is \(\hat{p}=15/30=0.5\). There are three independent grouped responses and one estimated intercept, so \(\operatorname{df}_{\mathrm{res}}=3-1=2\).

Deviance calculation. Each group has fitted success and failure counts of \(10(0.5)=5\). The middle group has five successes and five failures, matching these fitted counts, so its contribution is zero. The first group contributes $$ 2\left\{2\log(2/5)+8\log(8/5)\right\} =2\left\{2(-0.9162907)+8(0.4700036)\right\} \approx 3.8549. $$

The third group contributes the same amount, with the roles of successes and failures reversed. Thus \(D_{\mathrm{res}}\approx 3.8548951+0+3.8548951=7.7097903\), or 7.7098 to four decimal places. This is a check on the calculation: the first and third groups are symmetric around the fitted probability of 0.5 and must have equal contributions.

Common mistake avoided. There are 30 Bernoulli trials, but the data supplied to this grouped model consist of three independent group-level binomial responses. The residual degrees of freedom are therefore based on three groups, not 30 trials.

Interpreting Deviance Relative to Degrees of Freedom

Under suitable regularity conditions, residual deviance can be approximately compared with a chi-squared distribution having the residual degrees of freedom. This is a large-sample approximation, most useful when the response model is correctly specified, observations are independent, the fitted model is regular and identifiable, and the expected counts are not too sparse. It is not an exact rule for every GLM or data layout. For example, with individual binary outcomes, a saturated model can fit each zero or one exactly, while the usual chi-squared approximation may be poor.

The ratio \(D_{\mathrm{res}}/\operatorname{df}_{\mathrm{res}}\) is sometimes inspected as a rough diagnostic in settings where the approximation is reasonable. A ratio near one is not proof that all modeling assumptions hold; a ratio far from one is a reason to investigate the data and model, not a universal pass-or-fail threshold. In particular, the usual interpretation needs care when dispersion is not fixed at one or the observations are dependent.

Worked Example: A Gaussian GLM and the Meaning of Its Deviance

A hypothetical analyst models four observed repair durations, in hours, with an intercept-only Gaussian GLM: \(2,4,4,6\). Find the fitted mean, residual deviance, residual degrees of freedom, and deviance-to-degrees-of-freedom ratio. Round the ratio to four decimal places.

Method and fitted mean. For the intercept-only Gaussian model, the fitted mean is the sample mean: $$ \hat{\mu}=\frac{2+4+4+6}{4}=4. $$ The fitted values are therefore \(4,4,4,4\). The residual degrees of freedom are \(4-1=3\).

For the ordinary Gaussian GLM, residual deviance is the residual sum of squares. The residuals are \(2-4=-2\), \(4-4=0\), \(4-4=0\), and \(6-4=2\). Squaring and summing gives \(4+0+0+4=8\), so \(D_{\mathrm{res}}=8\). The ratio is \(8/3=2.6667\) to four decimal places.

Interpretation. This calculation identifies the model’s residual deviance and degrees of freedom; it does not make \(2.6667\) a universal verdict on the fit. For a Gaussian model, the scale is estimated from residual variation, so the ratio should not be interpreted as if every family had a known unit dispersion. The example also shows why the response family matters when using deviance summaries.

Common mistake avoided. Dividing deviance by degrees of freedom does not turn the result into a family-independent measure of predictive accuracy. Here it is simply \(8/3\), and its interpretation depends on the Gaussian model and its scale.

What These Summaries Cannot Tell You

Residual deviance and residual degrees of freedom describe the fitted model’s relationship to the observed data. They do not show whether its predictions will remain accurate on new observations, whether the chosen predictors capture the relevant structure, or whether the model is useful for the decision at hand. A saturated model has zero residual deviance by construction, yet its flexibility can make it a poor guide to future cases. Conversely, a model with a nonzero residual deviance can still be useful if it captures the patterns that matter for its intended use.

The numerical summaries also depend on representation and assumptions. For grouped-binomial data, changing the grouping can change the saturated comparison and the degrees of freedom. Sparse counts can weaken a chi-squared approximation. Overdispersion or dependence can make a standard reference interpretation unreliable. A model should therefore be assessed in context, alongside diagnostics and evidence relevant to its intended purpose; residual deviance is one piece of that assessment, not a complete evaluation.

Key takeaway: Residual deviance measures the fitted model’s likelihood gap from a saturated model; residual degrees of freedom count response units minus the rank of the estimated model. Both summarize in-sample fit, and neither alone demonstrates good predictive performance.

Check Your Understanding

For each problem, identify the relevant response units and model parameters before interpreting the requested summaries.

  1. A Poisson intercept-only model is fitted to counts \(1,1,2,4\). Find the fitted mean, residual degrees of freedom, and residual deviance to four decimal places. (Answer: fitted mean \(=2\); residual degrees of freedom \(=3\); residual deviance \(=2.7726\).)
  2. An intercept-only grouped-binomial model has two groups, each with eight trials, and success counts \(4\) and \(8\). Find the fitted probability, residual degrees of freedom, and residual deviance to four decimal places. (Answer: fitted probability \(=12/16=0.75\); residual degrees of freedom \(=1\); residual deviance \(=6.9044\).)
  3. An intercept-only Gaussian GLM is fitted to observations \(1,3,4\). Find the fitted mean, residual deviance, and residual degrees of freedom. (Answer: fitted mean \(=8/3\); residual deviance \(=14/3\); residual degrees of freedom \(=2\).)
  4. A grouped-binomial model has 12 independent groups and a model matrix of rank 4. Each group contains 25 trials. Find the residual degrees of freedom, and explain which count determines it. (Answer: \(12-4=8\); use the 12 grouped responses, not the total of 300 trials.)
  5. A Poisson GLM has residual deviance 18.2 on 20 residual degrees of freedom. Calculate the ratio and state one conclusion that is justified and one that is not. (Answer: \(18.2/20=0.91\); the ratio is a descriptive in-sample summary, but it alone does not establish that the model predicts well or that all assumptions hold.)
Clinical Biostats