For independent groups each containing independent Bernoulli trials with common probability , the group count has a binomial distribution. If groups have count , the maximum-likelihood estimate is . Form the Pearson chi-squared statistic using . With all categories retained, an interior true parameter, and sufficiently large expected counts, its null limit is a chi-squared distribution with statistical degrees of freedom: one degree is removed by the fixed total and another by fitting . Small expected counts require care with this approximation. If categories are pooled, the fitted parameter and calibration should correspond to the pooled statistical model; simply pooling a statistic after fitting the unpooled model does not automatically give the usual chi-squared limit.
For independent Poisson counts, the log-likelihood at mean vector is
The saturated model maximizes each cell separately at , including the boundary value zero. If is the fitted mean under the log-linear regression, twice the saturated-minus-fitted log-likelihood is the full Poisson deviance
with understood by continuity. The fitted intercept has score function , since differentiating the logarithmic mean with respect to that intercept gives one. Its maximum-likelihood equation therefore gives . This is why Poisson deviance simplifies when an intercept is fitted:
Without the fitted unpenalized intercept, one cannot generally discard the two linear terms. The individual logarithmic terms in the simplified sum need not each be positive; nonnegativity belongs to the full deviance, or to the full cell contributions before cancellation.
For the approximation, write and expand . When relative residuals are small,
Consequently the quadratic Pearson approximation to the Poisson deviance is
the Pearson chi-squared statistic for unit Poisson dispersion. Adequate expected counts and small relative residuals are what make the quadratic approximation useful; it is not an exact identity and can be poor for sparse cells, especially a zero count with positive fitted mean. Any further chi-squared goodness-of-fit reference needs its own large-count regularity assumptions.
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 is
Let indicate some use and indicate predisposition. The additive logistic regression specifies . Its log-likelihood, including the binomial constants, is
Differentiation 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 are
These 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.
Let denote the maximized log-likelihood in the saturated model, with one fitted mean per observation. With known dispersion, define the deviance of a fitted model as ; for an exponential-dispersion convention that scales deviance by the dispersion , divide that scaled quantity by in the following test.
Let be the fitted deviances under the null and full models. Their difference is the likelihood-ratio test statistic
Under the regular identifiable interior null hypothesis, Wilks theorem gives the limiting distribution. Reject for an observed difference above its chosen upper-tail critical value. This concerns the difference of fitted model deviances, not simply the full-model deviance compared with zero.
For a Poisson regression, the means are and . Saturation sets , taking the limiting value at . Consequently the Poisson deviance is
with . The intercept score implies at a finite fit, although retaining that term makes the individual deviance contributions clear.
For with small, expand . The linear term cancels and the result is . Therefore
the Pearson chi-squared statistic. The approximation requires adequately large fitted counts and small relative residuals; it is not an identity for sparse observations.
Assuming independent digits under Benford law, put and . The count vector has a multinomial distribution, with expected counts . Suitable predictive discrepancy statistics include the Pearson chi-squared statistic and multinomial deviance:
The zero-count terms of have limiting value zero. A Monte Carlo method gives a direct null comparison even when expected counts are small.
For example, an original R implementation is:
benford_check <- function(y, B = 9999L) {
  p <- log10(1 + 1/(1:9))
  n <- sum(y)
  expected <- n*p
  observed <- sum((y - expected)^2/expected)
  replicas <- rmultinom(B, size = n, prob = p)
  simulated <- colSums((replicas - expected)^2/expected)
  (1 + sum(simulated >= observed))/(B + 1)
}
Each column returned by rmultinom is a replicated count vector. R recycles the nine expected counts down each column. The add-one ratio is a Monte Carlo test estimate. In WinBUGS, alternatively generate a replicated dmulti vector using fixed , compute its discrepancy and monitor exceedance of the observed value. The null does not estimate unknown digit probabilities. Dependence or selection in the accounts would require an appropriate simulation model.
For observed proportions and fitted proportions , the binomial deviance is
A second-order Taylor expansion around gives
the generalized Pearson chi-squared statistic. Under the fitted binomial model this is approximately . The observed deviance is , whose upper-tail probability is about . Since this exceeds , there is no significant evidence of overdispersion.
The researcher computed the Pearson chi-squared statistic
and compared it with a distribution, using residual degrees of freedom. Under an adequate large-sample Poisson regression, should be roughly the residual degrees of freedom. The reported tail probability rounds numerically to zero and gives strong evidence of overdispersion.
Possible causes include unobserved heterogeneity or omitted covariates, dependence among respondents, excess zeros, or an incorrect mean function. The conclusion that the Poisson variance assumption fails is well supported, although this test alone does not identify the cause or establish that the Quasi-Poisson regression variance is correct.
The reported Pearson dispersion estimator is , so
up to rounding.
For the Poisson variance function , the code computes the Pearson chi-squared statistic
and the Pearson dispersion estimator
The first quantity measures goodness of fit; the second estimates the dispersion parameter, which equals one in a correctly specified Poisson regression. A standard rough calculation substitutes the residual deviance for the Pearson statistic and gives
If the reported upper-tail probability is inverted numerically, the actual Pearson statistic used by the code is about , giving . Either calculation reveals severe overdispersion.
The quasi-Poisson standard errors are the Poisson standard errors multiplied by , and the Pearson estimator divides the Pearson chi-squared statistic by the residual degrees of freedom . Therefore the requested sum of squared Pearson residuals is
up to the rounding in the printed standard errors.
Write . For small, the cell contribution to the Poisson deviance expands as
Summing gives the Pearson chi-squared statistic as the quadratic approximation. The approximation can be inaccurate for sparse expected counts or cells with relative residuals near minus one.
For a two-by-two contingency table, subtracting one half from each absolute observed-minus-expected count difference, with truncation at zero, gives the displayed corrected Pearson chi-squared statistic. Expected counts use the independence model . The subtraction compensates approximately for using a continuous chi-squared distribution for discrete counts. It can make the test conservative. The corrected statistic should be distinguished from the ordinary uncorrected Pearson chi-squared statistic.