Definitioncore
Deviance
Also called residual deviance, scaled deviance.
Twice the log-likelihood gap between the saturated model and a fitted model. It plays the part of the residual sum of squares for a generalized linear model.
The deviance of a fitted generalized linear model is twice the difference between the log-likelihood of the saturated model, which fits every observation exactly, and the log-likelihood of the fitted model, multiplied by the dispersion. For a normal model with the identity link it is the residual sum of squares. The scaled deviance is the same quantity divided by the dispersion. The residual deviance is the deviance of the fitted model, and the null deviance is the deviance of the model with only an intercept. The difference of the scaled deviances of two nested models fitted to the same data is the likelihood ratio statistic of the smaller model against the larger one. The deviance of one model alone is a test of fit only in special cases.
Definition
Let be independent, and let have a density or mass function from an exponential dispersion family,
with known prior weights , dispersion , mean and variance (see exponential family distribution). Write for the log-likelihood as a function of the vector of means. A model with coefficients (the coefficient vector is , and is its maximum likelihood estimate) gives the fitted means . The saturated model has one free mean per observation, so its fit is . The unit deviance is
where and are the natural parameters with means and . The scaled deviance and the deviance are
The deviance does not depend on . For the Poisson and binomial families , so . The unit deviances of the common families are as follows, with :
| family | ||
|---|---|---|
| normal | ||
| Poisson | ||
| binomial, a proportion of trials, | ||
| gamma | ||
| inverse Gaussian |
Facts.
- , with equality only at . More exactly, , twice the Kullback-Leibler divergence from the member with mean to the member with mean . Proof: , and the expectation of under is . So the scaled deviance is twice a sum of divergences, and the maximum likelihood fit minimizes it.
- For the normal family with the identity link, is the residual sum of squares and .
- A difference of deviances is a likelihood ratio statistic. Let be nested models with coefficients, fitted by maximum likelihood to the same data with the same . Then . Proof: in the saturated term is the same number and cancels. So under the conditions of Wilks' theorem, with fixed and , under tends in law to . In the normal case with known the law is exact.
- Unknown dispersion. With unknown, the usual test uses with or, less biased for small counts, the Pearson estimate with . In the normal case this is the regression F-test and has the exact law. In the other families the F law is an approximation.
- The deviance of one model is not in general . The saturated model has parameters, so the number of parameters grows with the data and Wilks' theorem does not apply to itself. is close to under small-dispersion limits with fixed: Poisson counts whose means are all large, or binomial counts with all and large.
- Binary data. For Bernoulli responses with the logit link, depends on the data only through . Proof: for , with , so . With , the score equations give . So , which is fixed once is fixed. It cannot measure how far is from .
- Deviance residuals. satisfy . Pierce and Schafer (1986) showed that they are closer to normal than the Pearson residuals , so they are the usual choice for residual plots.
Examples and non-examples
Eight counts. Take and the counts . The Poisson model with , fitted by iteratively reweighted least squares, gives and
The fitted counts sum to 39, the same as the observed counts: this is the score equation of the intercept under the canonical link. The unit deviances are , so the residual deviance is on degrees of freedom, and the Pearson statistic is . The null model has deviance on 7 degrees of freedom. The log-likelihoods are and , and
as Fact 3 says. On its p-value is , so the slope is needed. is small for 6 degrees of freedom, but the next example shows why that comparison is rough for counts this small.
The mean of a unit deviance for small counts. For one Poisson count with mean , the expectation of at the true mean is:
| 0.1 | 0.5 | 1 | 2 | 5 | 20 | |
|---|---|---|---|---|---|---|
| 0.474 | 1.007 | 1.147 | 1.139 | 1.047 | 1.009 |
The reference assumes a mean near 1 per observation. With many counts below 1 the deviance is too small on average, and with means between 1 and 5 it is too large by about 5 to 15%. Across 100 cells these errors add up to many units of the reference scale.
Non-example: deviance as a test of fit for binary data. Fit only an intercept to Bernoulli responses with successes. Then and . For this is , and for it is , whatever the order of the zeros and ones. So is about 1.39 or about 0.65 because of the success rate, not because of lack of fit. Fact 6 shows that the same holds for every logistic regression. Grouped binomial data with large , or a test that compares nested models, avoid the problem.
Non-example: deviances from different data. If one model drops the rows with a missing value of and the other keeps them, the saturated terms differ and is not a likelihood ratio statistic. Both models must be fitted to the same rows.
Non-example: deviances of models that are not nested. For a model with and another with , the difference of deviances is not under either model. Compare such models by an information criterion or by cross-validation.
Related definitions
- Null deviance. The deviance of the intercept-only model. is the fraction of deviance explained, the analogue of the coefficient of determination; for the eight counts it is .
- Akaike information criterion. For a fixed family and , , and the last term depends only on the data. So differences of AIC between models for the same data are differences of plus twice the differences of the numbers of parameters.
- Pearson statistic. is the second-order expansion of in around , since . In a contingency table it is the statistic of the chi-squared goodness-of-fit test, and is the likelihood ratio statistic .
- Quasi-deviance. The same integral with any variance function defines a deviance for quasi-likelihood models that have no full likelihood.
- Cross-entropy loss. For Bernoulli responses, is times the average cross-entropy loss of the fitted probabilities.
- Logistic regression. The usual software output reports the residual and null deviances. Fact 6 says how to read them.
References
- J. A. Nelder and R. W. M. Wedderburn, Generalized linear models, Journal of the Royal Statistical Society, Series A 135(3), 1972, pp. 370 to 384, The whole paper (the exponential family model with a link, the fit by iterative weighted least squares, and the deviance as the measure of goodness of fit that extends the residual sum of squares)
- Donald A. Pierce and Daniel W. Schafer, Residuals in generalized linear models, Journal of the American Statistical Association 81(396), 1986, pp. 977 to 986, The whole paper (deviance residuals and their near-normal distribution)
- P. McCullagh and J. A. Nelder, Generalized Linear Models, second edition, Chapman and Hall, 1989, Chapter 2 (the deviance and the generalized Pearson statistic as measures of discrepancy, and the unit deviances of the common families) and Chapter 4 (binary data, where the deviance does not measure fit)
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag 0H7XKM Edit this page History Report an error Markdown