Deviance goodness-of-fit test Created 2026-10-06 Updated 2026-11-05
A deviance goodness-of-fit test compares a fitted generalized linear model with its saturated statistical model. With independent response groups, an identifiable rank- mean model and known common dispersion parameter , the candidate statistic is the scaled devianceIn an appropriate large-information regime, compare it with a chi-squared distribution on statistical degrees of freedom. For a normal linear model this is exact when is known: is the residual sum of squares. For Poisson regression, ; adequate expected cell counts are still needed for a useful approximation.[ref]
More individual Bernoulli observations do not automatically justify comparing their residual deviance with . Small cell counts, dependence and overdispersion can invalidate that calibration. An unknown dispersion parameter also needs an explicit estimation and testing convention; estimating it from and then treating as an independent goodness-of-fit check is circular.
Past exam of the mathematics course of the University of Cambridge 2003 iii Paper 38 4 Solution Created 2026-10-03 Updated 2026-10-14
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 isAt 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 devianceThe intercept balance cancels the sum of linear terms. ConsequentlyThe 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.
Past exam of the mathematics course of the University of Cambridge 2005 iii Paper 41 2 i Solution Created 2026-10-03 Updated 2026-10-14
The Poisson deviance compares the fitted Poisson regression with a saturated statistical model:using . If the usual deviance goodness-of-fit test approximation is adequate, compare with a chi-squared distribution on statistical degrees of freedom. Its upper-tail p-value is about , and . There is no detected lack of fit or evidence of substantial overdispersion from this deviance. This neither proves the Poisson regression correct nor establishes that the slope is nonzero. Small expected counts, dependence or inadequate covariate specification can undermine the reference approximation, so deviance residuals and other regression diagnostics still matter.
Past exam of the mathematics course of the University of Cambridge 2005 iii Paper 41 4 Solution Created 2026-10-03 Updated 2026-10-14
read.table(...,header=T) reads four grouped rows with column names. The displayed outcome counts give the observed risks in the indicated factor order. rbind in the first test pools over predisposition: the two rows represent no cannabis use and some use, with event/non-event counts and . Thus the pooled risks are and . This test concerns the marginal statistical association between use and outcome, not an association adjusted for predisposition.Under independence, expected counts in the two-by-two contingency table are . The ordinary Pearson chi-squared statistic is . The printed is reproduced by the default two-by-two Yates continuity correction:All absolute differences here exceed one half. Comparison with a chi-squared distribution on one statistical degree of freedom gives . There is strong evidence of marginal association. The simplified output omits the usual continuity-correction wording, but its numerical value shows which statistic was used.
attach makes the data columns available by name, and tot=with+without obtains group sizes . The grouped binomial regression fits , with response and prior weights . These weights tell R the binomial denominator; treating the four proportions as four equally precise individual observations would be wrong. The default logit link isLet indicate some use and indicate predisposition. The additive logistic regression specifies . Its log-likelihood, including the binomial constants, isDifferentiation gives score equations and Fisher information matrix , where . Fisher scoring solves these equations, and the inverse fitted Fisher information matrix gives the reported approximate coefficient variances. The number of scoring iterations records numerical convergence, not degrees of freedom or statistical evidence.The intercept corresponds to no use and no predisposition and gives baseline fitted risk . The additive coefficients imply common adjusted odds ratios:They multiply the odds, not the risks. The Wald tests divide the estimates by their standard errors and use a standard normal distribution; both predictors have small two-sided p-values. Approximate confidence intervals for these odds ratios are and , obtained by exponentiating the log-scale intervals. The intercept test against zero asks whether the reference risk equals one half, and is not a test of either exposure association. The binomial dispersion is assumed to be one because ; the output does not demonstrate independence or rule out extra-binomial variation.
There are four grouped probabilities and three fitted coefficients, leaving one residual degree of freedom. The fitted risks are approximately . The binomial deviance compares this fit with the four unrestricted observed proportions:The deviance goodness-of-fit test against has p-value . The common-odds-ratio fit is not rejected at , although the doubly exposed group's observed risk exceeds its fitted risk appreciably and suggests possible interaction.
The second formula adds . Its four coefficients fit all four probabilities, making a saturated statistical model with zero grouped residual degrees of freedom. The near-zero deviance is roundoff from exact interpolation; it supplies no remaining grouped lack-of-fit test. Unlike Q1's unreplicated Gaussian fit, however, these grouped responses represent many independent Bernoulli trials, and their binomial variances are specified by their sizes and probabilities. Coefficient standard errors remain available from binomial information without estimating dispersion from the zero residual degrees of freedom.
Indeed, let be the fitted cell logit link value. The saturated coefficients areThese calculations yield the printed estimates. The delta method gives , and independent groups make the variance of the sum of all eight reciprocal counts. Its square root is , reproducing the printed standard error.
The saturated logistic regression describes the conditional odds ratios as follows:Thus the main coefficients now concern effects at the other factor's reference level. Logistic interaction as a ratio of odds ratios gives , with approximate confidence interval . The interaction Wald test has , while the nested likelihood-ratio test uses deviance difference on one statistical degree of freedom and has . The data suggest a larger odds association in predisposed subjects, but do not establish this interaction at the conventional level. This conclusion is specific to the odds scale; absolute-risk differences can vary even with no logit-scale interaction.
The Akaike information criterion is . The additive fit has and AIC ; the interaction fit has and AIC . The extra coefficient improves twice the log-likelihood by but incurs penalty , so AIC falls by only . It weakly favors the larger fit rather than decisively establishing an interaction, and AIC is not a p-value.
The marginal odds ratio and the fitted conditional odds ratios are different quantities. Predisposition is associated with both use frequency and outcome, so confounding is a substantive possibility; noncollapsibility of the odds ratio also means marginal and conditional odds ratios need not agree. This is an observational association analysis with only one adjustment factor. It does not by itself establish a causal effect, exclude other confounding, or validate the assumed independent binomial sampling.
Past exam of the mathematics course of the University of Cambridge 2006 iii Paper 41 4 Solution Created 2026-10-03 Updated 2026-10-14
For independent binomial distributions, the log-likelihood, up to known binomial coefficients, isThe saturated statistical model maximizes each term at . Under the logit link, the fitted probabilities are . Subtracting the fitted log-likelihood from the saturated log-likelihood gives the binomial devianceA zero-count summand uses the continuous convention . For the restricted model, replace by to obtain . Since the saturated likelihood cancels, is the likelihood-ratio test statistic. For the nested restriction setting coefficients to zero, Wilks theorem gives the asymptotic chi-squared distribution under regularity and an interior true parameter; reject for a large difference.
For the six anther cells, gives a common success probability, gives a separate probability for each storage condition, gives a common intercept and a log-force slope, and gives storage-specific intercepts with a common log-force slope. Their parameter counts are , so their residual statistical degrees of freedom are . In , storage has a constant effect on log odds; multiplying force by multiplies the odds by in either storage group.
The relevant nested likelihood-ratio tests at the level are:
- Adding storage to gives on one statistical degree of freedom, with .
- Adding log-force to gives on one statistical degree of freedom, with .
- Adding log-force to the storage model gives on one statistical degree of freedom, with .
- Adding storage to the log-force model gives on one statistical degree of freedom, with .
- Adding both terms to gives on two statistical degrees of freedom, with .
The two two-parameter models and are not nested, so their deviance difference has no ordinary nested chi-squared distribution calibration. The preferred parsimonious model is , with a storage effect and no log-force effect. Its deviance goodness-of-fit test is acceptable: on four statistical degrees of freedom. The common-probability model also passes its separate goodness-of-fit comparison, , but this does not contradict the relative evidence for adding storage: the two tests assess different null hypotheses. These are large-sample approximations; sufficiently large expected successes and failures, not merely the number of anthers, underpin their calibration.
Past exam of the mathematics course of the University of Cambridge 2007 iii Paper 43 3 ii Solution Created 2026-10-03 Updated 2026-10-14
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 thereforeThe 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 givesThis 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.
Past exam of the mathematics course of the University of Cambridge 2009 iii Paper 102 2 b Solution Created 2026-10-03 Updated 2026-10-14
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.
Past exam of the mathematics course of the University of Cambridge 2010 iii Paper 37 3 c Solution Created 2026-10-03 Updated 2026-10-14
For separate binary observations, the saturated model fits each outcome exactly and has maximized log-likelihood zero. With , the residual deviance is thereforeUse the identity in part (b) to replace by in its first term:Thus the deviance is twice the sum of the fitted binary information entropies. A deviance goodness-of-fit test against is unreliable for individual ungrouped binary observations: there is only one trial per saturated-model parameter, so the usual large-cell-count approximation fails. Deviance differences between fixed-dimensional nested logistic regression models can still support a likelihood-ratio test, subject to its usual regularity assumptions.
The three tree models are respectively , , and , with independent Bernoulli random variables conditional on the covariates. Testing the additional severity effect givesUnder , its reference distribution is asymptotically . The -value is approximately , giving overwhelming evidence that severity improves the fitted model. Holding severity fixed, doubling increases by one and multiplies the odds byThis is an odds ratio, not a multiplication of the event probability itself.
Past exam of the mathematics course of the University of Cambridge 2010 iii Paper 37 4 c Solution Created 2026-10-03 Updated 2026-10-14
The second Poisson exposure model allows each location its own baseline accident rate:The last equality is the corner-point constraint. The common after-to-before incidence rate ratio remains . This model is appropriate because the sites can have different background risks; treating those differences as unexplained Poisson variation made the first model fit poorly, with deviance on 14 residual degrees of freedom.
Adding seven location effects to the first fitted model reduces the deviance by , which is large relative to . The supplied sequential analysis of deviance reports a slightly different location contribution because it enters locations before the period indicator. The full model is much better but its deviance on 7 degrees of freedom still gives an approximate goodness-of-fit -value . That suggests residual lack of fit or overdispersion, although sparse accident counts make the asymptotic deviance goodness-of-fit test approximate.
Past exam of the mathematics course of the University of Cambridge 2014 iii Paper 33 4 c Solution 2026-10-06
The residual deviance is on residual degrees of freedom. Under a suitable Poisson deviance goodness-of-fit test approximation it is compared with , whose supplied 95th percentile is . Since is much larger, the chosen Poisson model does not provide a satisfactory absolute fit, despite being preferred among the three candidates.
The ratio suggests substantial overdispersion or mean-model misspecification. It is a deviance ratio, not the exact Pearson dispersion estimator, which cannot be computed from the excerpt. Check residual patterns, nonlinear effects, unusual rivers and dependence. A Quasi-Poisson regression could adjust uncertainty under an estimated dispersion, and a negative binomial regression could model extra count variation; a more adequate mean model may also be needed. The nominal Poisson tests in part (a) should be interpreted in light of this failure, rather than treated as a validated final analysis.
Past exam of the mathematics course of the University of Cambridge 2015 iii Paper 33 3 b Solution Created 2026-10-03 Updated 2026-10-06
Let be the number of maintenance jobs, average temperature and average precipitation. The fitted Poisson regression assumes independent conditional responses withThe logarithm is the Poisson canonical link, so fitted means are always positive. The estimated regression coefficients areAt fixed precipitation, one unit of temperature multiplies the fitted mean by , a decrease of about . The fitted precipitation multiplier is per unit, but its large p-value gives little evidence for that effect. These are conditional associations, not established causal effects.
The intercept-only model has residual degrees of freedom, and the full model has . Both imply months.
For an approximate deviance goodness-of-fit test of the full Poisson regression, compare residual deviance with . Its upper-tail p-value supplies no evidence of lack of fit. The ratio also gives no striking indication of overdispersion, though deviance per degree of freedom is only a rough dispersion check. Fitted count means around fifty make the usual chi-squared approximation plausible. Independence between months, the conditional variance-equals-mean assumption and the absence of residual structure still need diagnostics. Failure to reject is not proof that the model is correct.
The null deviance on degrees of freedom has , suggesting the constant-mean model is inadequate. In the sequential analysis of deviance for nested generalized linear models, adding temperature to that model reduces deviance by on one degree of freedom, giving . Adding precipitation after temperature reduces it by only , with . Therefore retain temperature; these data give no reason to retain precipitation after temperature. The temperature-only residual deviance is on degrees of freedom. This prediction-oriented reduced model should be refitted before reporting its coefficients: the printed temperature coefficient belongs to the full model. The Wald test results, and , broadly support the same conclusion, while the sequential deviance tests answer the stated nested-model questions.