Why Check Calibration by Groups?
A count model can give reasonable predictions overall while systematically underpredicting some observations and overpredicting others. Comparing a single observed total with a single predicted total may hide that pattern. A grouped calibration check asks a more targeted question: among observations with similar fitted means, do the observed counts add up to roughly what the fitted GLMM predicts?
This check is especially useful for sparse counts. Individual observations may be zero most of the time, and a residual for one observation can be difficult to interpret. Aggregating observations into groups can make a pattern visible. But aggregation does not make the observations independent: the model’s cluster structure still matters when deciding whether a discrepancy is unusually large.
Definitions and the Prediction Target
Write \(Y_{ij}\) for the count for observation \(i\) in cluster \(j\). Let \(\hat{\mu}_{ij}\) be its fitted expected count under the prediction target being checked. For example, a check may assess predictions for the observed clusters or predictions intended to average over the random-effects distribution. The target must be chosen explicitly, and the fitted means and simulations must represent the same target.
The group expected total is a sum of fitted means, not an average of them. If a group contains many observations with small expected counts, its total expected count can still be substantial. Groups should be formed from fitted means, not from observed counts: sorting observations by their outcomes and then comparing totals would use the very information the check is meant to assess.
There is no universal best number of groups. Too few groups can hide a trend across the fitted-mean range; too many can leave unstable totals, particularly when expected counts are very small. Choose a grouping rule that leaves enough observations and expected count in each group to make the summaries interpretable. Report the cut points and group sizes so the check can be reproduced.
Worked Totals and What They Do Not Show
Worked Example: Summing Counts Within Fitted-Mean Groups
Suppose a hypothetical GLMM is fitted to 12 count observations, which are grouped by fitted expected count. Assume the stated predictions target the observed clusters. The grouped data are:
| Fitted-mean group | Number of observations | Observed total \(O_g\) | Expected total \(E_g\) |
|---|---|---|---|
| Low | 5 | 2 | 1.6 |
| Middle | 4 | 3 | 4.2 |
| High | 3 | 11 | 8.0 |
For the low group, \(D_g=2-1.6=0.4\), and the observed-to-expected ratio is \(2/1.6=1.25\). For the middle group, \(D_g=3-4.2=-1.2\), with ratio \(3/4.2\approx0.714\). For the high group, \(D_g=11-8.0=3.0\), with ratio \(11/8.0=1.375\). Thus the high group has 3 more observed counts than expected, while the middle group has 1.2 fewer.
Across all groups, the observed total is \(2+3+11=16\), and the expected total is \(1.6+4.2+8.0=13.8\). The overall difference is \(16-13.8=2.2\). That overall difference does not tell us whether the high-group excess is unusually large. Nor do the group ratios by themselves show whether the deviations are surprising under the fitted GLMM. That requires a reference distribution that reflects the model’s variability and dependence.
Why the GLMM Structure Must Be Preserved
The variability of a group total depends on more than its expected total. For a group with observations indexed by \(k\), the variance of its total satisfies
The second sum contains the within-group covariances. In a GLMM, observations in the same cluster may be dependent through their shared random effects. Treating every count as an independent Poisson variable would generally omit this dependence, so it could give the wrong variability for the group totals even if the expected totals were correct.
A simulation check uses the fitted GLMM to generate replicated count data while retaining the observed design: covariates, offsets or exposure values, cluster membership, and the count model’s structure. Each replicate must be generated according to the prediction target being checked. Keep the grouping rule fixed as specified for the check; if the rule itself is data-adaptive, apply that same rule in each replicate. The point is not to simulate a collection of unrelated counts, but to ask what grouped totals the fitted model would typically produce for this design.
One useful discrepancy is the largest standardized departure across groups. Let \(D_g^{(b)}=O_g^{(b)}-E_g\) be the discrepancy in replicate \(b\), calculated against the original fitted expected total. From the \(B\) replicates, calculate the simulated mean \(\bar{D}_g^*\) and standard deviation \(s_g^*\) for each group. Then define
For each replicate, calculate \(T_b\) using the same simulated centers and standard deviations. A large \(T_{\mathrm{obs}}\) relative to the replicated \(T_b\) values indicates that at least one group departs more than is typical under the fitted model. The maximum statistic accounts for looking across the groups as a set; simply reporting the most unusual group without considering that search can exaggerate the evidence.
Worked Simulation Check
Worked Example: Assessing the Largest Group Discrepancy
Consider a second hypothetical sparse-count data set with three fitted-mean groups. The observed totals are 1, 3, and 15; the fitted expected totals are 1.5, 4.2, and 8.1. Suppose 999 GLMM-preserving replicates are generated using the same design and grouping rule. Across those replicates, the simulated discrepancy centers are 0.0, 0.1, and 0.2 counts, and the simulated standard deviations are 1.2, 2.4, and 3.5 counts.
The observed discrepancies are \(1-1.5=-0.5\), \(3-4.2=-1.2\), and \(15-8.1=6.9\) counts. Their standardized departures from the simulated centers are
Therefore \(T_{\mathrm{obs}}=\max(0.417,0.542,1.91)=1.91\). Suppose 14 of the 999 replicated maximum statistics are at least 1.91. Using the usual plus-one estimate, the simulation tail proportion is
In this hypothetical check, the observed maximum discrepancy is near the most extreme 1.5% of the simulated discrepancies. That is evidence that the fitted model has difficulty reproducing this grouped calibration pattern, particularly the excess in the high group. It is not the probability that the model is true or false. Because the model was estimated from the data, a plug-in simulation tail proportion is a diagnostic rather than an exact, universally calibrated hypothesis-test p-value.
A Short Justification for Simulation-Based Scaling
If a group’s replicate discrepancies have simulated mean \(\bar{D}_g^*\) and standard deviation \(s_g^*\), the standardized observed discrepancy compares its departure from the model’s simulated center with the variability the model produces for that group. This is preferable to dividing every discrepancy by the same number: groups with different sizes and expected counts generally have different scales of variation.
The maximum over groups then summarizes whether any group is unusually far from its simulated center. To see why the replication step matters, write a group total as \(S_g=\sum_{k\in G_g}Y_k\). Its variance includes both the individual variances and the pairwise covariances shown above. Replicated data generated under the fitted GLMM reproduce those terms through the model’s joint structure. An independent-count shortcut would set the covariance terms to zero, which is not justified when the GLMM implies dependence. This argument does not guarantee a perfect diagnostic: it depends on the fitted model and simulation procedure being appropriate for the intended prediction target.
Worked Example: Unequal Exposure and Group Construction
Worked Example: Adding Expected Counts, Not Averaging Them
Suppose a hypothetical low-mean group contains four observation units with exposures of 1, 2, 1, and 4 units. Their fitted rates are all 0.10 expected counts per exposure unit, so their fitted expected counts are 0.10, 0.20, 0.10, and 0.40. The observed counts are 0, 1, 0, and 1.
The group expected total is \(E_g=0.10+0.20+0.10+0.40=0.80\) counts. The observed total is \(O_g=0+1+0+1=2\) counts, so the discrepancy is \(D_g=2-0.80=1.20\) counts and the observed-to-expected ratio is \(2/0.80=2.50\). Averaging the four fitted expected counts gives 0.20 counts per observation, not the group’s expected total. Comparing the observed total of 2 with that average would mismatch the quantities being compared.
The four observations may also belong to clusters, so this calculation alone does not establish that the excess is unusual. The check must compare this group’s discrepancy with replicated discrepancies generated for the same exposures and cluster arrangement under the fitted model. Here, the ratio 2.50 is a descriptive signal to investigate, not a standalone significance measure.
Reading the Check and Recognizing Failure Modes
A useful calibration display reports, for each fitted-mean group, its cut points, number of observations, observed total, expected total, difference, and often the observed-to-expected ratio. Showing simulated intervals or the simulated distribution of a chosen discrepancy adds the reference needed to judge magnitude. The display should make clear whether the check concerns conditional predictions for the observed clusters or a target averaged over random effects.
Several patterns deserve attention. A steadily increasing positive discrepancy across higher fitted-mean groups can indicate systematic underprediction at the upper end. Persistent negative discrepancies can indicate overprediction. An isolated discrepancy may instead reflect ordinary count variability, a small group, or a few influential observations. Grouped totals can locate a broad calibration problem, but they cannot identify its cause.
- Too many narrow groups: Sparse counts can make each total highly variable and the ratios unstable. Use fewer groups or a grouping rule that leaves interpretable totals, and report how the rule was chosen.
- Grouping on observed counts: This can manufacture apparent differences. Form groups from fitted means, not from the outcomes.
- Ignoring cluster dependence: Independent simulations may produce an inappropriate reference distribution. Retain the fitted clustering structure.
- Changing the prediction target mid-check: Conditional fitted means compared with simulations for a different target do not form a coherent calibration check. State the target and use it throughout.
- Treating a ratio as a test: A ratio can be large when the expected total is tiny. It is descriptive; use a model-based reference distribution to assess whether the discrepancy is surprising.
- Ignoring failed or implausible simulations: Check that replicated data are generated as intended and that group totals are finite and calculable. A faulty simulation pipeline cannot provide a trustworthy benchmark.
Grouped calibration is complementary to residual plots and dispersion summaries. Residual displays preserve observation-level patterns that grouping can hide; an overall dispersion summary compresses variation into a different single-number view. In contrast, this check focuses on whether aggregate counts align with fitted means across the prediction range. Its limits are equally important: results depend on the chosen bins, the fitted model, and the simulation setup. A good grouped check cannot establish that every individual prediction is accurate, and an apparently good check cannot prove the model is correct.
Check Your Understanding
Work through these questions, then compare with the solutions.
- A group has observed counts 0, 2, and 1, and fitted expected counts 0.4, 0.9, and 0.7. Find its observed total, expected total, discrepancy, and observed-to-expected ratio.
- Why can independently simulating each count give a misleading reference distribution for a grouped total in a GLMM?
- A group has a ratio of observed total to expected total equal to 4. Does that alone establish poor calibration? Explain.
- What should be kept the same when generating replicated data for a grouped calibration check?
Solutions. (1) \(O_g=0+2+1=3\), \(E_g=0.4+0.9+0.7=2.0\), \(D_g=3-2.0=1.0\) count, and the ratio is \(3/2.0=1.50\). (2) Counts in a cluster may be dependent through shared random effects; independent simulation omits the covariance contributions to the total’s variance. (3) No. A ratio can be large when the expected total is small, and it does not account for the fitted model’s variability; compare the discrepancy with a suitable simulation reference. (4) Retain the observed design, including covariates, exposures or offsets, cluster membership, fitted count structure, grouping rule, and the prediction target being assessed.