Tutorials › Generalized Linear Mixed Models (GLMM) › Comparing Observed and Replicated Outcome Distributions

Diagnostics and Predictive Checks for Sparse and Overdispersed Outcomes · Tutorial 632 of 698

Comparing Observed and Replicated Outcome Distributions

Use replicated outcome distributions to assess whether a fitted GLMM reproduces the overall pattern of observed binary or count responses.

Intermediate 12 min read

What You'll Learn

  • Define replicated response datasets under a fitted GLMM and keep the observed design fixed.
  • Compare observed and simulated frequencies for binary outcomes.
  • Construct and interpret count-outcome histograms, including grouped upper-tail categories.
  • Summarize replicate-to-replicate variability without treating it as parameter uncertainty.
  • Recognize how pooled summaries can conceal differences among clusters.
  • Identify the limits of distributional overlays and when another diagnostic is needed.

Why Compare Outcome Distributions?

A fitted GLMM can describe the relationship between predictors and a response while still failing to reproduce important features of the responses themselves. For example, a model may predict the overall proportion of binary successes reasonably well but produce too few clusters with unusually high success counts. For count outcomes, it may reproduce the mean count while missing the observed spread or the frequency of large counts. Comparing the observed response distribution with distributions generated under the fitted model gives a direct visual check of this kind of mismatch.

The comparison is between the observed data and replicated datasets generated from the fitted GLMM, not between the data and a single fitted mean. Replicated datasets vary because responses are simulated from the model. A useful plot therefore displays both the observed frequencies and the range of frequencies that occur across many replications.

Definition: Let \(Y_{ij}\) be the response for observation \(i\) in cluster \(j\), and let \(\hat{\theta}\) denote the fitted model parameters. A replicated dataset \(Y^{(r)}\) is generated by simulating responses under the fitted GLMM, using the same observed covariates, cluster structure, and other design information as the original dataset. The replication scheme must follow the fitted model’s response and random-effects specification. Repeating this procedure produces \(R\) datasets \(Y^{(1)},\ldots,Y^{(R)}\).

For example, a binary-response GLMM may specify \(Y_{ij}\mid b_j\sim\operatorname{Bernoulli}(p_{ij})\), with a link relating \(p_{ij}\) to fixed and random effects. A count-response GLMM might specify a Poisson response with a log link. The distributional comparison uses the model’s fitted response law to generate the replicated outcomes; it does not replace that law with a normal approximation. The usual interpretation assumes that the response family and link are appropriate, the fitted model has converged to a usable estimate, and the replication procedure respects the observed design and the model’s dependence structure.

The purpose here is descriptive diagnosis. Replicates are generated under estimated parameters, so the resulting reference distribution is conditional on the fitted model and its estimates. A close visual match does not establish that the model is true, and a mismatch does not by itself identify which part of the model should change.

Frequencies and Replicate Summaries

For a discrete response, first choose categories that make the observed distribution readable. For binary data the categories are 0 and 1. For counts, categories may be exact values or grouped values such as 0, 1, 2, and 3 or more. Use the same categories for the observed and every replicated dataset. If \(C_k\) is the number of observed responses in category \(k\), and \(C_k^{(r)}\) is the number in that category in replicate \(r\), then the observed frequency can be compared with the distribution of the \(R\) replicated frequencies.

$$ \bar{C}_k^{\,\mathrm{rep}}=\frac{1}{R}\sum_{r=1}^{R}C_k^{(r)} $$

The replicate average \(\bar{C}_k^{\,\mathrm{rep}}\) describes the typical number of responses in category \(k\) under the fitted model. A useful plot overlays the observed frequency with the replicate average and displays replicate-to-replicate variation—for instance, by showing the middle 95% of the simulated frequencies. Such a range is a simulation reference range, not a confidence interval for a model parameter.

Interpretation: A distributional overlay asks whether the observed category frequencies look unusual relative to the frequencies generated by the fitted model. It does not assign a probability that the model is true. A frequency within a central replicate range is not proof of adequate fit; a frequency outside it is a signal to investigate the discrepancy and its context.

The reason the replicate average is informative follows directly from simulation. Given the fitted model and the replication scheme, each \(C_k^{(r)}\) is a draw from the model-implied distribution of the category count. If that count has finite expectation, then

$$ E\!\left(\bar{C}_k^{\,\mathrm{rep}}\mid\hat{\theta}\right) =\frac{1}{R}\sum_{r=1}^{R}E\!\left(C_k^{(r)}\mid\hat{\theta}\right) =E\!\left(C_k^{(1)}\mid\hat{\theta}\right). $$

Thus the replicate average estimates the model-implied expected category frequency. Increasing \(R\) reduces simulation noise in that average, but it does not remove uncertainty from estimating the GLMM parameters. The simulated distribution of \(C_k^{(r)}\), rather than only its average, is important: a difference of two observations may be ordinary when replicate frequencies vary widely and notable when they vary little.

Worked Example: Binary Outcome Frequencies

Hypothetical data. A fitted binary GLMM is used for 20 observations from several clusters. The observed responses contain 13 zeros and 7 ones. Generate \(R=400\) replicated datasets under the fitted model using the same design. Suppose their average category frequencies are 13.8 zeros and 6.2 ones; the middle 95% of replicate frequencies are 9–18 zeros and 2–11 ones.

The observed proportions are \(13/20=0.65\) for zero and \(7/20=0.35\) for one. The replicate-average proportions are \(13.8/20=0.69\) for zero and \(6.2/20=0.31\) for one. The observed count of ones, 7, is within its simulated range of 2–11, as is the observed count of zeros, 13, within 9–18.

The plot would show the observed and replicate-average frequency for each response value, with the replicate ranges alongside them. Here the observed distribution is somewhat more weighted toward ones than the replicate average, but neither observed frequency is unusual relative to the simulated variation. This is a descriptive indication that the fitted model can reproduce a distribution like the one observed; it is not a formal acceptance of the model.

Count Distributions and Grouped Tails

For counts, a histogram or a table of category frequencies makes the shape visible. Exact categories are useful when counts are small and numerous observations occupy each value. When large counts are rare, grouping the upper tail—for example, into “3 or more”—can prevent a plot from becoming dominated by many nearly empty categories. Grouping should be decided in a way that is interpretable and then applied identically to observed and replicated data.

Worked Example: Comparing a Sparse Count Distribution

Hypothetical data. There are 30 observed count outcomes. Their frequencies in categories 0, 1, 2, and 3 or more are 12, 9, 5, and 4, respectively. Across \(R=500\) replicated datasets, the average frequencies are 10.5, 8.7, 6.1, and 4.7. The middle 95% replicate ranges are, respectively, 6–15, 4–13, 2–10, and 1–9.

The observed proportions are \(12/30=0.400\), \(9/30=0.300\), \(5/30=0.167\), and \(4/30=0.133\). The corresponding replicate-average proportions are \(10.5/30=0.350\), \(8.7/30=0.290\), \(6.1/30=0.203\), and \(4.7/30=0.157\). Both sets of frequencies sum to 30 (apart from rounding of the displayed averages), as each dataset contains 30 outcomes.

The observed frequency of zero is higher than the replicate average by \(12-10.5=1.5\) outcomes, while the observed frequency of 2 is lower by \(5-6.1=-1.1\). However, every observed frequency lies within its stated replicate range. The overlay therefore shows some differences in the shape but no category frequency that is especially extreme against these simulation ranges. It does not rule out a more specific mismatch, such as an unusual pattern within clusters.

For a distributional comparison, keep the plotted scale consistent. Frequencies are appropriate when every replicate has the same number of responses as the observed dataset; proportions can make comparisons easier to read and are equivalent up to division by that fixed number. If denominators differ, raw frequencies are not directly comparable without accounting for the different totals. The reference ranges should also be reported or plotted by category: a single overall average can hide which parts of the outcome distribution differ.

Look Beyond the Pooled Distribution

A pooled distribution combines responses across clusters. It can look satisfactory even if the model does not reproduce how outcomes are distributed across clusters. For instance, the total number of binary successes can agree with the model while the observed data contain more clusters with all successes or all failures than the replicates typically do. A second comparison can therefore summarize the response distribution within clusters, using the same cluster summaries for observed and replicated data. This is a different view of the data, not a substitute for checking the pooled response frequencies.

Worked Example: Cluster Success Counts

Hypothetical data. Ten clusters each contribute four binary responses. Their observed numbers of successes are 0, 0, 0, 1, 1, 1, 2, 2, 3, and 4. Thus there are \(14\) successes in \(40\) observations, giving a pooled success proportion of \(14/40=0.35\). The frequencies of clusters with 0, 1, 2, 3, and 4 successes are 3, 3, 2, 1, and 1.

Suppose 300 replicated datasets give average cluster-frequency counts of 1.6, 3.4, 3.2, 1.4, and 0.4 in those same categories. These average counts sum to 10 clusters. The observed number of clusters with four successes is 1, compared with a replicate average of 0.4; the observed number with zero successes is 3, compared with an average of 1.6. These two differences suggest that the observed cluster totals may be more concentrated at the extremes than typical replicates, even though the pooled success proportion is readily summarized by 0.35.

The average frequencies alone do not establish that either discrepancy is unusual. The replicate ranges are needed to see whether counts of 3 clusters with zero successes or 1 cluster with four successes are common under the fitted model. If those counts are near the edges of their ranges or beyond them, the cluster-level pattern merits follow-up. If they are ordinary, the apparent difference from the averages may simply reflect simulation variability.

Diagnostics, Alternatives, and Limits

Read the plot for patterns rather than treating one visual feature as a verdict. A repeated excess of high counts, too few zeros, an overall shift in binary proportions, or a mismatch that occurs only for particular clusters can each be a useful clue. Check first that categories, denominators, and the observed design were handled consistently. Also check that the simulation code generated the intended response family and preserved the model’s specified structure. A coding error or an inconsistent grouping rule can create an apparent lack of fit.

Distribution overlays complement other diagnostics. Residual displays can show whether discrepancies relate to fitted values, covariates, or cluster ordering; calibration checks focus on agreement between predicted and observed event rates or counts in relevant groups. Pearson and deviance dispersion summaries compress information into a statistic, whereas an outcome-distribution plot retains the category-by-category pattern. None of these approaches replaces the others: a pooled histogram can miss predictor-specific misfit, and a residual summary may not make a sparse tail discrepancy easy to see.

The replicate ranges also have limitations. A central 95% range is a pointwise description for one category at a time; looking across many categories makes it increasingly likely that at least one observed frequency will fall outside its range by chance. Conversely, ranges can be wide in small or highly variable datasets, making meaningful departures hard to notice. The result depends on the fitted model, the estimates used, the replication scheme, the number of replications, and the chosen categories. Distributional agreement is evidence about the model’s ability to reproduce the displayed features, not a guarantee of correct predictions for new settings.

A common mistake is to compare the observed histogram only with the histogram of fitted means, then conclude that the model fits because the bars look similar. A mean response is not a replicated response distribution: it omits the variation expected from the response model and, in a GLMM, the model’s clustering structure. The correction is to generate full replicated datasets from the fitted GLMM, summarize each replicate using the same categories and design, and compare the observed frequencies with the resulting distribution of frequencies.

Key takeaway: Compare the observed outcome frequencies with the range of frequencies produced by replicated datasets, not merely with fitted averages. Use the comparison as a focused diagnostic, inspect cluster-level summaries when pooling may conceal structure, and follow up any mismatch with diagnostics suited to its location and form.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions below.

  1. A binary dataset has 50 responses and 18 observed successes. What is the observed success proportion? If the replicate-average number of successes is 20, what is the replicate-average proportion?
  2. For a count outcome, why must the same count categories be used for the observed data and every replicated dataset?
  3. An observed count of 3 or more occurs 8 times. Across 400 replicates, the average is 5 times and the middle 95% range is 2–9. What can and cannot be concluded from this comparison?
  4. Why can a satisfactory pooled binary distribution coexist with a concerning distribution of cluster success counts?

Solutions. (1) The observed proportion is \(18/50=0.36\). The replicate-average proportion is \(20/50=0.40\), using the same 50-response denominator. (2) Identical categories ensure each observed frequency is compared with the frequency for the same outcome values in the simulations; changing categories would make the comparison inconsistent. (3) Eight lies within 2–9, so this category count is not outside the stated pointwise simulation range. That alone does not prove adequate fit, rule out other discrepancies, or give the probability that the model is true. (4) Pooling retains the total number of successes but discards their allocation among clusters. The same total can arise from evenly distributed successes or from clusters with unusually extreme success counts, so cluster-level frequencies can reveal a pattern hidden by the pooled proportion.

Clinical Biostats