Deviance goodness-of-fit test Created 2026-10-06 Updated 2026-10-14
For a suitably regular generalized linear model, a residual deviance can be compared approximately with a chi-squared distribution on degrees of freedom to assess fit relative to the saturated model. Sparse or very small expected cell counts can invalidate this reference distribution. A large p-value means no detected lack of fit, not proof of correctness; dependence, wrong mean structure or overdispersion still require diagnostics.
A logistic-normal count model takes and , where is a stationary unit-variance autoregressive process of order one with coefficient and the independent have normal distribution with variance . The marginal latent variance is , and its off-diagonal covariance is . Random success probabilities produce overdispersion relative to the binomial distribution.
Negative binomial distribution Created 2026-09-24 Updated 2026-10-14
The negative binomial distribution counts failures before a target number of successes in successive independent Bernoulli trials with constant success probability . In this stopping model, is a positive integer and . On the failures-before-the-th-success convention, the random variable takes values ; for , its probability mass function is
The binomial coefficient counts possible arrangements before the final success, as explained by the negative binomial stopping argument. At , every trial succeeds: with probability one, so its expected value and variance are both zero. This handles the endpoint without needing to interpret . At , the target is never reached and there is no proper finite waiting-count law.
For a worked example, toss a fair coin until the second head, calling heads and tails . Thus and . Exactly two failures means that the second success is on trial four. The complete stopped sequences are , and ; each has probability , giving . The first three masses are
Both and are modes, each with mass : there is no unique mode here. Later masses decrease, since for .
Figure 1.
Exactly two failures before the second success: three stopped sequences, each of probability 1/16
. Details.
The expected value and variance of the failures count are
If instead counts all trials, including the successes, then and
For the fair-coin example, , , and . Shifting the count changes its expected value but preserves its variance. When , has the failures-count geometric distribution, while has the all-trials geometric distribution. The two conventions and the moments are treated in Kyle Siegrist, The Negative Binomial Distribution, Random Services.
Figure 2.
Negative binomial failure counts for success probability 1/2 and targets of one, two and five successes
. Details.
The negative binomial distribution is useful when a procedure runs until it collects a target number of successes: for example, obtaining usable samples from independent attempts with a stable acceptance probability. A binomial distribution instead counts successes in a fixed number of trials. The attractive connection is that these two experimental questions can be answered from the same trial sequence, using the negative binomial stopping argument. For the failures count and , the positive mean satisfies , so the law allows overdispersion relative to a Poisson distribution. At , both quantities vanish and the inequality is not strict. The separate Poisson-gamma mixture explains another way this count law arises; its noninteger shape parameters do not represent a literal target number of successes.
Use for the expected accident count, not for the accident rate. With a design row consisting of an intercept, seven non-reference site indicators and the after-treatment indicator,
Here is a known generalized linear model offset, with coefficient fixed at one. Differentiating the Poisson regression log-likelihood gives the score function equations
These nine equations estimate the intercept, seven site contrasts and one treatment contrast, with the stated reference-level constraints.
The Fisher information is , where . A Fisher scoring update adds to the current coefficient vector. In iteratively reweighted least squares, the working response is ; regress on the design with weights . Thus the reported four iterations solve the likelihood equations while accounting for unequal exposure periods.
The common adjusted rate ratio is obtained by exponentiating the after coefficient:
This estimates a lower accident rate after the intervention, conditional on the additive site model. The standard error gives normal Wald statistic , two-sided , and an approximate confidence interval for the rate ratio
The label t value is again a normal-reference Wald ratio under fixed Poisson dispersion, rather than an exact Student statistic.
The intercept gives the before rate at reference site one: accidents per year. The seven site coefficients are log baseline-rate ratios relative to that site. In site order two through eight, their exponentials are about . The third site has the largest estimated rate and a nominal Wald ratio about against the reference. These are adjusted baseline comparisons, not differences in absolute accident counts. The overall unadjusted before/after rate ratio is , and it differs from because site risks and their relative exposure weights differ.
An independent way to solve the fit is the profile likelihood for a common Poisson rate ratio with unequal exposures. Put and . For fixed , the site score gives . The remaining equation is
Its positive root reproduces the reported treatment estimate. Comparing the same site model with to the fitted model gives a deviance improvement about on one degree of freedom, with nominal likelihood-ratio .
There are count observations and fitted mean parameters, leaving residual degrees of freedom. The null deviance on degrees of freedom is for the intercept-only rate model, still including the exposure offset. The residual Poisson deviance is on degrees of freedom. A chi-squared comparison gives approximately , suggesting potential lack of fit of a single common treatment ratio; the extreme deviance residuals near and also deserve inspection. Several after-cell expected counts are below one or near two, so this absolute-fit calibration is only approximate. Site-specific treatment effects, overdispersion or temporal dependence are possible explanations to investigate, with a parametric bootstrap available to calibrate the sparse-count fit statistic. A before/after association alone does not isolate a causal effect from secular changes or regression to the mean at selected sites.
Here the negative binomial distribution has mean parameter and size parameter . Its support in the original PDF is all nonnegative integers; a finite endpoint appearing in the TeX aid would be incorrect. The probability generating function, obtained from the generalized binomial series, is
Differentiating at one gives and . Since the variance is , this proves
The extra positive term explains its overdispersion relative to a Poisson distribution.
For one observation, write the log-likelihood as
The mean score function and its cross derivative are
Taking expectations gives . In addition,
For reference, with the digamma function, the size score function is
Its variance is finite and positive for finite positive . Thus negative binomial mean-size parameter orthogonality makes the expected Fisher information matrix diagonal. For an independent identically distributed sample and a regular identifiable interior true parameter, asymptotic normality of a maximum likelihood estimator gives
Hence the asymptotic correlation is zero. This is first-order asymptotic independence, not a claim of exact finite-sample independence. Indeed the mean score yields at an interior fit, while the size fit also depends on the observed dispersion. The argument excludes a true boundary such as the Poisson limit .
Use for the intercept, to avoid confusing it with the observation means. Let be the fitted Poisson regression mean. Apart from constants, its log-likelihood is
At a finite interior maximum-likelihood estimate, the intercept score equation gives the Poisson regression margin-matching score equations:
The statistical saturated model fits each mean to , taking the boundary mean zero if . Subtracting fitted from saturated log-likelihood gives the Poisson deviance
The intercept balance cancels the sum of linear terms. Consequently
The unsimplified formula makes nonnegativity transparent; individual terms in the simplified formula need not each be positive.
For the deviance goodness-of-fit test, if the fitted design has rank , compare a suitably calibrated with , rejecting for large values. This approximation applies in a regular large-count regime, such as a fixed set of cells with increasing exposure and positive fitted proportions. It is not automatically accurate for many sparse Poisson observations. Check residual patterns and overdispersion; where the approximation is doubtful, simulate independent Poisson random variables with fitted means, refit each sample, and use a parametric bootstrap distribution of the same statistic. A large p-value means no detected lack of fit, not proof of the model. If a finite interior estimate fails to exist, the score proof needs a boundary-limit interpretation; for example all-zero data give a supremum with every fitted mean tending to zero and limiting deviance zero.
The working score function and its derivative are
At an interior working maximizer, . A Taylor expansion at yields
for an intermediate value . When the last term is negligible relative to the linear one, this gives
This is the Poisson score linearization under proportional variance. Correct specification of the mean alone implies . The stipulated independence and variance relation give
Taking the mean and variance of the linear approximation therefore proves
These are first-order conclusions, not exact finite-sample identities. The mean and variance assumptions alone do not guarantee that the approximation is accurate: an interior consistent solution, increasing information, control of leverage, and a suitable central limit condition are needed for normal inference.
The quasi-likelihood score for variance is , so its zero is unchanged by the unknown common dispersion parameter. Thus the working Poisson estimating equation remains appropriate for the mean parameter, but its unadjusted Poisson variance estimate is wrong when . A usual Pearson dispersion estimator for this one-parameter model is
In particular overdispersion multiplies coefficient standard errors by approximately , even though it leaves the coefficient estimating equation unchanged.
Let be the design matrix with row , let , and write . Independence gives the Poisson regression likelihood function
The score function and negative Hessian matrix are
Because , the score has mean zero; independence and the Poisson distribution variance give . Thus the observed and expected Fisher information matrices are the same here.
Assume has full column matrix rank . For a nonzero vector , . The concavity of the Poisson regression likelihood therefore makes any finite solution of the unique maximum-likelihood estimator. If the design is rank deficient, parameters differing by a vector in give the same distribution, so only identifiable combinations can be estimated. Full rank alone does not ensure a finite maximizer: for an intercept-only model with all observations zero, approaches its supremum as . More generally, directions that decrease only fitted means attached to zero counts can produce boundary fits. A useful sufficient case for a finite fit is full rank with every count positive: each summand tends to in either tail, and some diverges whenever diverges.
For an interior fit, Newton's method and Fisher scoring give the same update:
This is also iteratively reweighted least squares. Define the working response , with , and regress on using weights :
A numerical implementation solves these linear equations rather than explicitly forming the inverse, checks convergence of the score and likelihood, and can shorten a step when necessary.
Under the usual fixed-design regularity conditions, with growing information and no single observation dominating it, a score Taylor expansion about the true parameter gives
Estimate the covariance matrix by ; its diagonal square roots are the coefficient standard errors. This justifies large-sample Wald confidence intervals and Wald tests for specified coefficients or contrasts. Finite-sample unbiasedness is not being asserted. A likelihood-ratio test compares nested fits through twice their maximized log-likelihood difference. The Poisson deviance against the saturated fit is
with . Residual diagnostics and a check of overdispersion assess whether the assumed Poisson variance is adequate; the variance correction required when it is not is derived in the next part.
Each scan() command reads a numeric vector from the entered data: the first creates the nine counts, and the second their nine predictor values. The last command fits a generalized linear model with the Poisson distribution and its default log link, including an intercept, then prints a summary. Thus the model is independent counts with means satisfying
The coefficients are maximum-likelihood estimates, and the reported standard errors come from the inverse fitted Fisher information matrix. Increasing the predictor by one multiplies the fitted mean by , about a increase. The intercept corresponds to a mean at predictor zero, outside the observed range. Approximate coefficient-to-standard-error ratios are and ; the slope is strongly different from zero under the assumed model. A Wald confidence interval for the slope is about , or for the multiplicative change.
The deviance is twice the log-likelihood advantage of the saturated model over the fitted model. For these counts it is
with the logarithmic term interpreted as zero when a count is zero. The saturated model has nine freely fitted means; the fitted model has two independent regression coefficients, so the residual degrees of freedom are .
Under an adequate Poisson model and the usual large-sample approximation, is compared with . The reported is rather large relative to seven, but below the upper critical value about ; its approximate upper-tail probability is . Thus there is some indication of lack of fit or overdispersion, but not a rejection at the level on this diagnostic. The deviance-to-d.f. ratio is about ; it does not by itself prove an overdispersed model, and the chi-square approximation is imperfect for small counts.
There is one inconsistency in the supplied numerical output. Independently solving the Poisson score equations for the displayed nine counts gives , and deviance , agreeing with the printed estimates and deviance. But gives standard errors approximately and . In particular the printed slope standard error is not the standard Poisson-model value for these data. The interpretations above describe the supplied numbers; the directly recomputed slope ratio is and its normal-approximation interval is about . The conclusion of a strong increasing trend is unchanged.
The Poisson distribution mass function is
It is an exponential dispersion family of order one with
Indeed, and . A generalized linear model specifies independent random variables from a response exponential family, together with a linear predictor and a link function relating it to the response mean. The Poisson canonical link is .
For the insurance counts, let class and merit be the reference levels in a regression factor. The fitted Poisson regression assumes
The insured exposure is known; its logarithm is an offset, not a coefficient to estimate. The model has eight free mean parameters and fixes the dispersion parameter at one. It assumes additive class and merit effects on the log-rate scale, hence multiplicative effects on the rate scale without a class-by-merit interaction.
Apart from constants independent of the parameters, the log-likelihood is
Differentiating gives the Poisson regression margin-matching score equations
Thus the fitted totals equal the observed totals in each class and merit category, including the reference categories by subtraction. In design matrix notation these equations are . Fisher scoring solves them iteratively; the reported three iterations describe the numerical fit, not an additional statistical result.
The regression intercept gives the baseline fitted claim rate per insured car year. The merit rate ratios, relative to merit at the same class, are
The class rate ratios, relative to class at the same merit, are
Each predicted cell rate is the baseline rate times its class and merit multipliers. The output's coefficient-to-standard error ratios are asymptotic normal Wald test statistics under the fitted Poisson regression, despite the software label “t value”; there is no estimated Gaussian residual scale in this model. All nonreference effects have very large absolute ratios.
The null Poisson deviance is on nineteen statistical degrees of freedom; adding the seven factor coefficients reduces it by . But the final Poisson deviance is still on twelve statistical degrees of freedom, and the deviance residuals include values near and . These are far beyond what a well-fitting unit-dispersion model would normally produce. The additive Poisson model fits substantially better than a common rate, but remains grossly inadequate. A class-by-merit interaction, overdispersion, or statistical dependence between claims could contribute; the summary alone does not distinguish these explanations. Its very small nominal standard errors and formal Wald tests rely on the rejected model, so improved mean structure and error assumptions are needed before treating them as reliable uncertainty assessments.
The null model uses one parameter, the day model uses nine, and there are grouped observations. The four missing entries, in their table order, are therefore
The test of no day effect is . The nominal binomial likelihood-ratio test statistic is , compared asymptotically with . Its nominal -value is about , so the common-probability model is decisively inadequate relative to the day model. The fitted probabilities in (i) show substantial differences between days, with days 1 and 7 much higher than days 3 and 8.
However, relative improvement does not establish absolute fit. The day model's deviance goodness-of-fit test compares with , giving . The counts are large enough for this approximation to be reasonable. Thus at the day-specific binomial model still shows lack of fit. Among the two printed models it is preferred, but it should not be regarded as a fully satisfactory final model.
The residual scale estimate suggests overdispersion. Directly computing the Pearson statistic from the day means gives
This corroborates extra dish variation rather than the nominal binomial variance. Dish heterogeneity or dependence among cells in a dish can produce such variation. Residual checks and a quasibinomial regression or an explicit model for dish heterogeneity are sensible refinements. Allowing dispersion of this moderate magnitude would enlarge standard errors but would not plausibly remove the very large day effect. Retain day effects, while accounting for the remaining extra-binomial variation.
This is a family-level cluster-randomized trial, but there are only about 1.1 contributing children per family. Most families therefore contribute a single eligible child, leaving little opportunity for within-family intraclass correlation to add much uncertainty. The equal-size exchangeable approximation has design effect , with cluster size and correlation ; when is close to one, this is close to one. A multilevel Poisson regression can consequently give nearly the same standard error as the independent-child working analysis.
Agreement is compatible with limited within-family dependence and little change from covariate adjustment; it does not prove all dependence absent. Mean family size alone does not determine the exact design effect for highly unequal cluster sizes.
Larger differences would be expected with larger families and stronger within-family correlation, especially with unequal family sizes. Pronounced between-family heterogeneity, recurrent attendances concentrated in particular children, or important imbalanced covariates can also create overdispersion or change the adjusted comparison.
A Poisson distribution has probability mass , where . It is an exponential family with , mean and variance . The responses are independent, their linear predictors are , and the log link relates these predictors to their means. These are precisely the components of a generalized linear model; the log link is its canonical link function and the dispersion is one.
The log-likelihood and score function are
Thus a finite maximum-likelihood estimator satisfies
The Hessian is ; with a full-rank design matrix it is negative definite at finite parameter values, so a finite solution is the unique maximum. A finite maximum need not exist for every possible response/design combination; the displayed equations describe it when it does exist. If the first component of every is one, the first score equation gives .
The saturated model fits each mean as , with the limiting mean zero allowed for a zero count. Subtracting the fitted log-likelihood from the saturated log-likelihood gives the Poisson deviance
where . With an intercept, the sum of the second terms is zero, but retaining them is necessary without that score equation.
Take low pH as a reference level. For group , the model with interaction has
where is biomass. The additive model sets every to zero. The interaction model estimates six parameters and the additive model four. In the additive model the log-mean curves are parallel straight lines, while the mean curves are positive exponentials with fixed ratios . In the interaction model the log-mean slopes differ, and the mean ratio is . The following sketches illustrate common versus factor-specific slopes in Poisson regression; their coefficients are illustrative, not estimates from the data.
Figure 1.
Illustrative Poisson mean curves with common and pH-specific biomass slopes
. Details.
The additive model is nested in the interaction model with two restrictions. The likelihood-ratio test therefore uses
whose p-value is . There is strong evidence that the biomass slope on the log-mean scale depends on pH. The interaction-model residual deviance is close to its residual degrees of freedom, giving no obvious indication of overdispersion from this comparison alone. The supplied deviances contain no slope estimates: they do not establish which pH group has more species, whether each slope is positive or negative, or whether any actual curves cross. Those conclusions require the fitted coefficients and their uncertainty.
Index city by and age group by , with the youngest group the reference level. For each of the 15 observed cells, the grouped-binomial logistic regression assumes
with independent cell counts. The response supplied to R is , and the weights specify the binomial numbers of trials . They are not 15 arbitrary precision weights: the conditional variance of the proportion is . The logit link models log odds, and the two sets of factor coefficients use corner-point constraints.
There are nine parameters: one intercept, seven age contrasts and one city contrast. Hence the residual degrees of freedom are , not the total population minus nine. The null model has only an intercept and residual degrees of freedom. Adding age uses seven more parameters and reduces the binomial deviance from to , a drop of . Adding city then uses one parameter and reduces it by to . These are sequential likelihood-ratio tests, asymptotically compared with chi-squared distributions on seven and one degrees of freedom. Both provide extremely strong evidence of an effect; the printed age p-value is rounding, not an exactly zero probability. Because the table is incomplete, sequential main-effect sums need not be invariant to the order of fitting.
The intercept estimate is the log odds for the youngest Minneapolis–Saint Paul group. It implies baseline odds and a fitted probability about . Its standard error is ; its reported Wald test tests log odds zero, or probability , rather than a scientifically interesting comparison of groups.
The age coefficients are log odds ratios relative to the youngest group within the same city. Their exponentials are approximately , , , , , and as age increases through the seven other groups. All these comparisons have large positive Wald statistics and small p-values. Thus the fitted probabilities are much higher in the older groups than in the youngest group. The slightly smaller coefficient in the oldest group than in the preceding group does not itself prove a real decline: that claim needs a contrast and its standard error, including the covariance of the two estimates.
The city coefficient is the log odds ratio for Fort Worth relative to Minneapolis–Saint Paul, adjusted for age. Its standard error gives , so the null city effect is strongly rejected by the Wald test, consistent with the sequential likelihood-ratio test. The fitted constant-over-age city odds ratio and an approximate 95% confidence interval are
This is an odds ratio, not generally a probability ratio. The probabilities here are sufficiently small that the two ratios are close. The absence of an age-by-city interaction is an assumption of the fitted additive log-odds model.
The final binomial deviance is on six degrees of freedom; its approximate upper-tail p-value is . It gives no indication of substantial lack of fit against the saturated observed-cell model. The deviance residuals range from to , with median zero and no conspicuously large value in the five-number summary. Neither statement proves that every model assumption holds. In particular, the small case counts motivate checking the accuracy of the chi-squared asymptotic approximation, for example by a fitted-model parametric bootstrap.
The dispersion is fixed at one by the binomial distribution; it was not estimated as a free scale parameter. Four Fisher scoring iterations describe the numerical optimization, not four additional parameters. Residual and cellwise observed-versus-fitted comparisons would help assess adequacy and potential overdispersion.
Model the count relative to exposure, for example
Here is a measured exposure such as patient-days, contains hospital predictors, and is a random effect. This Poisson regression separates hospital size from rate variation and supplies partial pooling. Use proper, scale-appropriate priors on coefficients and variation; add regional or temporal effects if the data demand them. A gamma mixing law with an estimated shape is another way to allow more flexible overdispersion. Compare the fitted model's counts and dispersion through posterior predictive checks.
The solid Poisson regression profile and dashed negative binomial regression profile peak at essentially the same . The dashed profile is slightly wider and has heavier shoulders: it gives larger relative likelihood to values farther from the common maximizer. Thus the estimated mean ratio is stable, while the negative binomial model expresses slightly greater uncertainty.
The Poisson distribution constrains variance to equal the mean. A common negative binomial parametrization instead has , with additional shape ; it permits overdispersion due, for example, to unexplained between-physician heterogeneity. Profiling this extra parameter lets the data support greater count variability and usually reduces information about the mean contrast. In this two-group model, the fitted group means remain the sample means for fixed , which explains the nearly identical maximizers. The small separation of the profiles indicates a modest effect here, not overwhelming evidence for strong overdispersion. The comparison concerns the original PDF figure; no figure is reproduced.
For pair , use conditionally independent counts and , with a common effect and a separate positive baseline rate for each physician. Equivalently the linear predictor is , with . This Poisson regression controls each physician's stable baseline propensity.
Condition on all twelve pair totals . The paired Poisson conditional likelihood has independent factors
This eliminates every exactly. It is more useful as a nuisance-elimination device than the unpaired calculation, which removes only one common baseline: many pair-specific rates are otherwise estimated from just two measurements each.
A possible concern is loss of information through conditioning on totals that are not ancillary for , especially with sparse pairs; a zero-total pair contributes no conditional information. There is an important qualification in this exact fixed-baseline Poisson model. Maximizing over gives , and substitution leaves precisely the same -dependent factor as the conditional likelihood. Hence there is no extra loss relative to ordinary profiling in this particular model; one should not automatically assert an incidental-parameter bias in its estimate of .
Additional baseline observations, a calibrated distribution of baseline rates, or informative hierarchical constraints can retain information in the pair totals. A Gamma–Poisson hierarchical model is one possible structured model, but merely giving it a completely free common mean does not automatically create extra information about : that mean can absorb the factor in the totals. Such remedies trade exact nuisance elimination for additional data or assumptions. Finally, paired sampling alone does not establish conditional Poisson independence or equidispersion: remaining within-physician dependence or overdispersion should be checked, and an appropriate joint count model or physician-level robust variance used if needed. The common multiplicative-effect assumption is also part of the analysis.
Use grouped-binomial logistic regression, and . Center the year as . Maximizing gives score and information ; these determine the estimates and working covariance matrix.
A straight-line logit fit is , with naive binomial standard errors and . Its yearly odds multiplier is , with naive 95% Wald confidence interval . However, its residual deviance is on 12 degrees of freedom (), so those small standard errors do not describe an adequate independent-binomial fit.
Comparing polynomial mean structures gives residual deviances for degrees zero through three, with respective residual degrees of freedom . A quadratic term alone adds little; the cubic structure captures the middle-period acceleration and later leveling. Even the cubic independent-binomial fit has for its residual deviance goodness-of-fit test. A useful working model is therefore cubic quasibinomial regression, retaining the logistic mean and estimating overdispersion rather than claiming an exact binomial law:
The Pearson estimate is . Using standard errors multiplied by and a reference, the approximate 95% coefficient intervals are , , , and . An approximate quasi-deviance comparison of cubic against linear gives and , supporting the added shape while acknowledging that only fourteen annual groups inform dispersion.
In this preferred mean model the odds change is not constant:
The fitted annual change is larger around the middle than at the ends; the straight-line 4.6% increase is a useful overall summary, not an exact yearly effect in the cubic model. The fitted curve, uncertainty band and residual plot appear in the figure. Singleton success increased overall, but a constant log-odds trend with unit binomial dispersion fits poorly. Quasibinomial intervals remain working-model intervals: serial dependence, changing patient mix and treatment practices cannot be separated from annual aggregates alone.
At several doses the three replicate plates differ much more than the square-root-of-mean scale expected from a Poisson distribution. For example the group at dose has sample mean about and sample variance about , rather than variance near . Its counts span a range of , compared with a Poisson standard deviation about . The dose- and dose- groups likewise have variances above their means. Thus extra plate-to-plate variation is plausible. With only three replicates per dose this is evidence suggesting overdispersion, rather than a precise determination of it; not every group has excess sample variance.