Tutorials › Generalized Linear Models › Calibrating Dispersion Checks With Simulation

Detecting Overdispersion · Tutorial 660 of 981

Calibrating Dispersion Checks With Simulation

Use a fitted-model simulation to judge whether an observed dispersion statistic is unusually large when its usual asymptotic calibration may be unreliable.

Intermediate 12 min read

What You'll Learn

  • Define a parametric simulation check for Pearson and deviance statistics
  • Calculate observed Poisson and binomial statistics
  • Simulate responses under a fitted GLM while keeping the design fixed
  • Refit each simulated data set before calculating its statistic
  • Interpret Monte Carlo tail probabilities and their simulation error
  • Distinguish a plug-in calibration from an exact test under a fully specified null

Why Calibrate a Dispersion Check by Simulation?

A Pearson or deviance statistic can indicate that a fitted binomial or Poisson model leaves more variation unexplained than its mean–variance specification allows. In many settings, a reference distribution based on a large-sample approximation is used to judge whether the statistic is unusually large. That approximation can be doubtful when the sample is small, the data are sparse, or the fitted model has features that make the approximation unreliable.

Parametric simulation offers a direct alternative calibration. It asks: if the fitted model generated new responses under the same design, how often would the same diagnostic statistic be at least as large as the one observed? The procedure is useful only if the simulation reproduces the model being assessed and the fitting and diagnostic steps are repeated consistently.

Definition and Simulation Procedure

Definition: A parametric simulation calibration for a dispersion statistic generates replicate responses from a specified fitted model, refits that model to each replicate, and recalculates the statistic using the replicate fit. The simulated upper tail of the statistic is compared with its observed value. This is a plug-in calibration because the simulation uses estimated model parameters.

Suppose the observed responses are \(Y_1,\ldots,Y_n\), with fixed covariates or design, and a binomial or Poisson GLM is fitted. Write \(\hat{\mu}_i\) for the fitted mean of a Poisson response and \(\hat{p}_i\) for the fitted success probability of a binomial response with \(m_i\) trials. The usual Pearson statistics are

$$ X^2_{\mathrm{P}}=\sum_{i=1}^{n}\frac{(Y_i-\hat{\mu}_i)^2}{\hat{\mu}_i} \quad\text{(Poisson)},\qquad X^2_{\mathrm{B}}=\sum_{i=1}^{n}\frac{(Y_i-m_i\hat{p}_i)^2}{m_i\hat{p}_i(1-\hat{p}_i)} \quad\text{(binomial)}. $$

The corresponding residual deviances are

$$ D_{\mathrm{P}}=2\sum_{i=1}^{n}\left\{Y_i\log\!\left(\frac{Y_i}{\hat{\mu}_i}\right)-(Y_i-\hat{\mu}_i)\right\}, $$ $$ D_{\mathrm{B}}=2\sum_{i=1}^{n}\left\{Y_i\log\!\left(\frac{Y_i}{m_i\hat{p}_i}\right)+(m_i-Y_i)\log\!\left(\frac{m_i-Y_i}{m_i(1-\hat{p}_i)}\right)\right\}. $$

In these formulas, a term of the form \(0\log(0/a)\), for \(a>0\), is defined to be zero by continuity. Larger values are evidence of a discrepancy between the observations and the fitted model, but they do not by themselves identify the reason for it.

For each of \(B\) simulations, generate responses from the fitted model conditional on the observed design, refit the same model using the same fitting rules, and calculate the same statistic. Denote the resulting values by \(T_1^*,\ldots,T_B^*\), and the observed value by \(T_{\mathrm{obs}}\). A common Monte Carlo upper-tail estimate is

$$ \hat{p}_{\mathrm{MC}}=\frac{1+\sum_{b=1}^{B} I(T_b^*\geq T_{\mathrm{obs}})}{B+1}. $$

The added one prevents a zero estimate when no simulated value reaches the observed statistic. It does not make a fitted-model simulation an exact test for a composite model: the fitted parameter values are estimates, not known null parameters.

Worked Examples

Worked Example: A Poisson Intercept-Only Fit

Consider three independent Poisson counts \(Y=(0,1,2)\) under an intercept-only model, so every observation has mean \(\mu\). The maximum-likelihood estimate is the sample mean:

$$ \hat{\mu}=\frac{0+1+2}{3}=1. $$

The observed Pearson statistic is

$$ X^2_{\mathrm{P,obs}}=\frac{(0-1)^2}{1}+\frac{(1-1)^2}{1}+\frac{(2-1)^2}{1}=1+0+1=2. $$

For the deviance, the zero count contributes \(1\), since its logarithmic term is zero. The count of 1 contributes \(1\log(1/1)-(1-1)=0\), and the count of 2 contributes \(2\log(2/1)-(2-1)=2\log 2-1\). Thus

$$ D_{\mathrm{P,obs}}=2\{1+0+(2\log 2-1)\}=4\log 2\approx 2.7726. $$

To generate a replicate, draw three independent Poisson variables with mean 1, then fit the intercept-only model again by taking their sample mean. For example, if a simulated response is \((0,0,3)\), its refitted mean is also 1. Its Pearson statistic is \(1+1+4=6\), and its deviance is

$$ 2\{1+1+3\log 3-(3-1)\} =2(3\log 3)\approx 6.5917. $$

This replicate illustrates why the model must be refitted: the diagnostic is calculated from the fitted replicate, not from a fixed reference mean copied into every calculation. The observed statistic alone does not determine a calibrated tail probability; that requires the full set of simulated replicates.

Worked Example: A Binomial Intercept-Only Fit

Suppose four independent groups each have \(m_i=5\) trials, with observed success counts \(Y=(1,2,4,5)\). Under a common-probability model, the fitted probability is

$$ \hat{p}=\frac{1+2+4+5}{4(5)}=\frac{12}{20}=0.6. $$

Each fitted success count is \(5(0.6)=3\), and the Pearson denominator in each group is \(5(0.6)(0.4)=1.2\). Therefore

$$ X^2_{\mathrm{B,obs}}=\frac{(1-3)^2+(2-3)^2+(4-3)^2+(5-3)^2}{1.2} =\frac{10}{1.2}\approx 8.3333. $$

The four contributions inside half the deviance are, in order,

$$ \begin{aligned} &1\log(1/3)+4\log(4/2)\approx 1.673976,\\ &2\log(2/3)+3\log(3/2)\approx 0.405465,\\ &4\log(4/3)+1\log(1/2)\approx 0.457581,\\ &5\log(5/3)+0\log(0/2)\approx 2.554128. \end{aligned} $$

The sum is approximately \(5.091151\), giving \(D_{\mathrm{B,obs}}\approx 10.1823\). For each simulation, generate four independent \(\operatorname{Bin}(5,0.6)\) counts and refit the common probability from their total. For instance, a replicate \((0,3,3,5)\) has total 11 and refitted probability \(11/20=0.55\). Its fitted count per group is 2.75, and its Pearson statistic is

$$ \frac{(-2.75)^2+(0.25)^2+(0.25)^2+(2.25)^2}{5(0.55)(0.45)} =\frac{12.75}{1.2375}\approx 10.3030. $$

This single replicate exceeds the observed Pearson statistic, but it is not itself a tail probability. The proportion of all simulated statistics at least as large as 8.3333 supplies the calibration estimate.

Worked Example: Interpreting a Monte Carlo Tail Estimate

Suppose a correctly specified simulation run uses \(B=999\) replicates, and 23 replicate statistics are at least as large as the observed statistic. The plus-one estimate is

$$ \hat{p}_{\mathrm{MC}}=\frac{1+23}{999+1}=0.024. $$

This says that the simulated upper tail is about 2.4% under the fitted-model simulation procedure. It is not a probability that the model is true, and, because the parameters were estimated, it is not generally an exact null p-value.

There is also Monte Carlo error: a finite simulation estimates a tail probability with noise. Treating the 999 exceedance indicators as Bernoulli outcomes gives the approximate standard error

$$ \sqrt{\frac{(23/999)(1-23/999)}{999}}\approx 0.0047. $$

The estimate is therefore imprecise at this simulation size; a small change in the simulated exceedance count can noticeably change the reported tail estimate. If a decision depends on distinguishing a small tail probability from a nearby threshold, increase \(B\) and report enough information to show the simulation size and exceedance count.

Why Refit Every Replicate?

The statistic being calibrated is calculated after estimating model parameters from data. If simulated responses are generated from the fitted model but the original estimates are reused for every replicate, the simulated statistics omit the variability introduced by fitting. Refitting mimics the complete analysis applied to the observed data: generate responses, estimate parameters, then calculate the diagnostic.

1
Fix the design and fit the observed model.
Keep the observed covariates, trial counts, or exposures fixed, and record the observed Pearson or deviance statistic.
2
Generate a response under the fitted model.
For a Poisson GLM, draw independent counts with the fitted means. For a binomial GLM, draw counts with the specified trial counts and fitted probabilities.
3
Repeat the fitting and diagnostic steps.
Apply the same model specification and fitting rules to the replicate, then calculate the same statistic from its refitted values.
4
Compare the simulated upper tail with the observation.
Count replicate statistics greater than or equal to the observed statistic and report the Monte Carlo estimate with its simulation size.

If a replicate fit fails or reaches a boundary where the statistic is undefined, that event must not be silently discarded. The fitting procedure and a rule for handling such replicates should be stated; frequent failures can indicate that this calibration is not reliable for the problem at hand.

What the Calibration Does—and Does Not—Establish

A simple-null Monte Carlo rank calculation has a precise validity property. Suppose the null distribution is fully specified, the observed statistic and \(B\) simulated statistics are independent draws from that same distribution, and ties are handled by counting simulated values greater than or equal to the observed value. Then the plus-one upper-tail value is conservative: its probability of being at most \(\alpha\) is no greater than \(\alpha\). To see this, let \(N=B+1\) and randomly break any ties among the \(N\) exchangeable statistics. The rank of the observed statistic in this ordering is uniform on \(1,\ldots,N\). The count using “greater than or equal to” is at least that tie-broken rank, so the plus-one tail value is at least the tie-broken rank divided by \(N\). Consequently, the event that the tail value is at most \(\alpha\) is contained in the event that the uniform rank divided by \(N\) is at most \(\alpha\), whose probability is \(\lfloor \alpha N\rfloor/N\leq\alpha\). Thus the test is conservative, including when ties occur. \(\square\)

In a fitted GLM, however, the observed data and the simulated data are not generally exchangeable under a composite null: the simulation uses estimated parameters. The rank argument therefore does not establish exact finite-sample validity for the plug-in calibration. Its purpose is to approximate the diagnostic’s null behavior under the fitted model, especially when a standard asymptotic reference is doubtful.

The Monte Carlo error calculation also has a direct justification. If the model and fitted parameters are held fixed and each replicate is generated independently, define \(I_b=I(T_b^*\geq T_{\mathrm{obs}})\). Each \(I_b\) is Bernoulli with success probability \(q=P(T^*\geq T_{\mathrm{obs}})\), so \(E[I_b]=q\), \(\operatorname{Var}(I_b)=q(1-q)\), and independence gives

$$ E\!\left[\frac{1}{B}\sum_{b=1}^{B}I_b\right]=q,\qquad \operatorname{Var}\!\left(\frac{1}{B}\sum_{b=1}^{B}I_b\right)=\frac{q(1-q)}{B}. $$

This describes simulation error conditional on the fitted model; it does not account for uncertainty in the fitted parameters or for whether the model itself is adequate.

Common Pitfall and Practical Interpretation

Wrong reasoning: “The observed statistic is large, so the fitted model must have overdispersion.” A large statistic relative to a simple reference can instead reflect the behavior of the fitted statistic in a small or sparse sample, or a departure from the assumed mean structure. Simulation calibrates how unusual the statistic is under the chosen fitted model; it does not diagnose the cause of a discrepancy.

Correction: State the model used to generate replicates, keep the design fixed, refit every replicate, and interpret the upper-tail estimate as a model-conditional diagnostic. A small simulated tail indicates that the observed statistic is unusual under that procedure. It is a reason to investigate the model and data, not a standalone proof of extra variation.

Key takeaway: When asymptotic calibration of a Pearson or deviance statistic is doubtful, simulate responses from the fitted binomial or Poisson model and repeat the entire fitting-and-diagnostic procedure. Report the simulated tail estimate and its finite simulation size, while remembering that plug-in calibration is not automatically an exact test.

Check Your Understanding

Use these questions to check both the mechanics and the interpretation of simulation calibration.

  1. Why should the model be refitted for every simulated response before calculating its Pearson statistic?
  2. In a Poisson GLM simulation, which parts of the observed data are held fixed, and which are generated anew?
  3. If 8 of 499 replicate deviances are at least as large as the observed deviance, calculate the plus-one Monte Carlo estimate.
  4. Why does the exact rank argument for a fully specified simple null not automatically prove exact validity for a plug-in fitted-model calibration?
  5. What does a small simulated upper-tail estimate indicate, and what does it not establish about the source of the discrepancy?
Clinical Biostats