Tutorials › Generalized Linear Mixed Models (GLMM) › Conditional and Marginal Fitted Values in Diagnostics

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

Conditional and Marginal Fitted Values in Diagnostics

Distinguish fitted values for observed clusters from population-averaged fitted values, and choose the version that matches the diagnostic question.

Intermediate 11 min read

What You'll Learn

  • Define conditional and marginal fitted means in a generalized linear mixed model.
  • Calculate fitted means for binary, Gaussian, and count outcomes.
  • Integrate over random effects rather than incorrectly setting them to zero.
  • Explain how conditional and marginal fitted values change a response-scale discrepancy.
  • Recognize when a fitted-value comparison answers the wrong predictive question.

Why Two Fitted Values Can Describe the Same Observation

A generalized linear mixed model can describe outcomes both conditionally, for a specified value of the random effects, and marginally, after averaging over their distribution. These are different summaries, not competing calculations of one identical quantity. The distinction matters in diagnostics: a fitted value that tracks an observed cluster's estimated effect asks whether the model describes that cluster, while a fitted value averaged over random effects asks what the model expects across the random-effects population.

The difference can be substantial for binary and count outcomes because the inverse link is nonlinear. For a Gaussian model with an identity link and mean-zero random effects, the two fitted means have a particularly simple relationship; for a logistic or log link, averaging the random effect and then applying the inverse link generally does not give the same answer as applying the inverse link first.

Model and Definitions

Let \(Y_{ij}\) be the response for observation \(i\) in cluster \(j\). A GLMM specifies a conditional response distribution given the random effects \(b_j\), with conditional mean \(\mu_{ij}(b_j)\) satisfying

$$ g\{\mu_{ij}(b_j)\}=x_{ij}^{\mathsf T}\beta+z_{ij}^{\mathsf T}b_j, \qquad b_j\sim N(0,D). $$

Here \(g\) is the link function, \(x_{ij}\) and \(z_{ij}\) are covariate vectors, \(\beta\) is the fixed-effect coefficient vector, and \(D\) is the random-effects covariance matrix. The random effects are assumed to follow the stated distribution, and the conditional response distribution and any conditional dependence structure must be appropriate for the application. In the common conditionally independent specification, responses are independent given the random effects and covariates.

Definition: A conditional fitted mean for an observed cluster plugs an estimate of that cluster's random effect into the conditional mean: $$ \hat{\mu}_{ij,\mathrm{cond}} =g^{-1}\!\left(x_{ij}^{\mathsf T}\hat{\beta} +z_{ij}^{\mathsf T}\hat{b}_j\right). $$ A marginal fitted mean averages the conditional mean over the fitted random-effects distribution: $$ \hat{\mu}_{ij,\mathrm{marg}} =\int g^{-1}\!\left(x_{ij}^{\mathsf T}\hat{\beta} +z_{ij}^{\mathsf T}b\right) \,\phi(b;0,\hat D)\,db, $$ where \(\phi(b;0,\hat D)\) is the density of \(N(0,\hat D)\). Both quantities are on the response-mean scale.

The conditional estimate \(\hat b_j\) is typically an empirical Bayes estimate, such as a conditional mode or conditional mean, obtained using the fitted model and data from cluster \(j\). It is not the unknown true random effect. The marginal fitted mean instead averages over the model's random-effects distribution, usually using estimated parameters \(\hat\beta\) and \(\hat D\). It is not obtained by setting \(b=0\) unless the link and model make that operation equivalent to the required average.

These definitions answer distinct questions. The conditional fitted mean is relevant when describing fitted outcomes in clusters already observed, using their estimated latent effects. The marginal fitted mean describes the model's expected response at the covariate values for a cluster drawn from the modeled random-effects population. It is not a posterior prediction for a particular new cluster: that prediction would require accounting for uncertainty about that cluster's random effect given whatever data are available.

Why Averaging and Inverting the Link Differ

The marginal mean follows directly from the law of total expectation. Conditional on \(b\), the response has mean \(\mu(b)\); therefore, averaging over the random effects gives \(E(Y)=E_b\{E(Y\mid b)\}=E_b\{\mu(b)\}\). This derivation also shows why the marginal mean is an average of response-scale means rather than an average of linear predictors.

$$ E(Y\mid x) =E_b\{E(Y\mid x,b)\} =E_b\!\left[g^{-1}(x^{\mathsf T}\beta+z^{\mathsf T}b)\right]. $$

In general, \(E_b[g^{-1}(a+z^{\mathsf T}b)]\ne g^{-1}(a)\). Nonlinearity prevents taking the inverse link outside the expectation. For an identity link, the mean-zero assumption gives \(E_b(x^{\mathsf T}\beta+z^{\mathsf T}b)=x^{\mathsf T}\beta\), so marginal and zero-random-effect fitted means agree. That does not make them equal to the conditional fitted mean when \(\hat b_j\ne 0\). For a nonlinear link, even the zero-random-effect fitted mean generally differs from the marginal mean.

For example, if \(g^{-1}\) is the logistic function, it is curved rather than linear. A distribution of random intercepts therefore produces an average probability that is not generally the probability evaluated at the average intercept. A useful diagnostic is to compute both quantities for representative covariate patterns and inspect the size and direction of their difference; a large gap is not automatically evidence of model failure.

Worked Example: Binary Outcome With a Random Intercept

Suppose a hypothetical binary-outcome model has a random intercept \(b_j\sim N(0,1)\), fixed linear predictor \(-1\) for a given covariate pattern, and estimated random intercept \(\hat b_j=0.8\) for an observed cluster. Suppose the response for one observation in that cluster is \(y_{ij}=1\). The logistic model assumptions here are a Bernoulli response conditional on the random intercept, the logit link, and the stated normal random-intercept distribution.

The conditional fitted probability uses the observed cluster's estimated effect:

$$ \hat{\mu}_{ij,\mathrm{cond}} =\operatorname{logit}^{-1}(-1+0.8) =\operatorname{logit}^{-1}(-0.2) =\frac{1}{1+\exp(0.2)} \approx 0.4502. $$

The marginal fitted probability averages \(\operatorname{logit}^{-1}(-1+b)\) over \(b\sim N(0,1)\). This integral has no elementary closed form. A five-point Gauss-Hermite calculation, expressed here as standard-normal nodes and weights, gives

$$ \begin{aligned} \hat{\mu}_{ij,\mathrm{marg}} &\approx 0.5333\,\operatorname{logit}^{-1}(-1)\\ &\quad+0.2221\{\operatorname{logit}^{-1}(0.3556) +\operatorname{logit}^{-1}(-2.3556)\}\\ &\quad+0.01126\{\operatorname{logit}^{-1}(1.8570) +\operatorname{logit}^{-1}(-3.8570)\}\\ &\approx 0.5333(0.2689)+0.2221(0.5880+0.0866)\\ &\quad+0.01126(0.8651+0.0207)\\ &\approx 0.3032. \end{aligned} $$

The raw response-minus-fitted-mean discrepancies are \(1-0.4502=0.5498\) conditionally and \(1-0.3032=0.6968\) marginally. These are illustrative differences, not by themselves formal residual diagnostics. The conditional comparison assesses the observation relative to its cluster's estimated effect; the marginal comparison assesses it relative to the mean across the random-intercept population. Neither is universally preferable: the diagnostic question determines which is relevant.

Worked Example: Gaussian Random-Intercept Model

Consider a hypothetical Gaussian model with identity link, fixed-effect linear predictor \(12\) minutes, and an observed cluster's estimated random intercept \(\hat b_j=2.4\) minutes. Assume \(b_j\sim N(0,4)\), so the random-intercept standard deviation is \(2\) minutes. The response is conditionally Gaussian with this mean and a constant residual variance. For an observation with recorded time \(y_{ij}=16\) minutes, calculate both fitted means.

The conditional fitted mean is

$$ \hat{\mu}_{ij,\mathrm{cond}}=12+2.4=14.4\ \text{minutes}. $$

The marginal fitted mean averages \(12+b_j\) over a mean-zero random intercept:

$$ \hat{\mu}_{ij,\mathrm{marg}} =E_b(12+b)=12+E_b(b)=12+0=12\ \text{minutes}. $$

Thus the raw discrepancy is \(16-14.4=1.6\) minutes conditionally and \(16-12=4.0\) minutes marginally. The conditional value uses the estimated cluster elevation; the marginal value describes the mean for the random-intercept population. This equality between the marginal mean and the fixed-effect predictor relies on the identity link and mean-zero random effect; it should not be transferred to a nonlinear link.

Worked Example: Poisson Log-Link Model

Suppose a hypothetical count model has a Poisson response conditional on a random intercept, log link, fixed linear predictor \(\log(2)\), and \(b_j\sim N(0,0.25)\). For one observed cluster, let \(\hat b_j=0.3\), and suppose the observed count is \(y_{ij}=4\). These assumptions imply the conditional mean is \(\exp\{\log(2)+b_j\}\).

For the observed cluster, the conditional fitted count mean is

$$ \hat{\mu}_{ij,\mathrm{cond}} =\exp\{\log(2)+0.3\} =2\exp(0.3) \approx 2.700\ \text{events}. $$

For the marginal mean, a normal random variable with variance \(0.25\) has \(E\{\exp(b)\}=\exp(0.25/2)\). Hence

$$ \hat{\mu}_{ij,\mathrm{marg}} =E_b[2\exp(b)] =2\exp(0.25/2) =2\exp(0.125) \approx 2.266\ \text{events}. $$

The response-minus-mean discrepancies are \(4-2.700=1.300\) events conditionally and \(4-2.266=1.734\) events marginally. Notice that the marginal fitted count is larger than the mean at \(b=0\), which is \(2\) events. The exponential function is convex, so random-intercept variation increases the average response mean in this example. The conditional and marginal values differ because one uses the observed cluster's estimated effect and the other integrates over the random-intercept distribution.

Choosing a Scale for a Diagnostic Question

A fitted value is useful only when its conditioning matches the question. For an observed cluster, conditional fitted values can reveal whether outcomes remain systematically high or low after accounting for the cluster's estimated latent level. Marginal fitted values can reveal whether the population-averaged response pattern is systematically misrepresented. A plot or summary that mixes these targets can make a sound model appear poorly calibrated, or hide a problem by absorbing it into cluster-specific estimates.

ChoiceWhat is held fixed or averaged?Interpretation of a response-minus-mean discrepancy
ConditionalPlug in \(\hat b_j\) for an observed clusterDeparture from the mean for that cluster under its estimated random effect
MarginalAverage over \(N(0,\hat D)\)Departure from the model's mean across the random-effects population
Zero random effectSet \(b=0\)Mean for a cluster at the random-effects distribution's center; not generally the marginal mean

For nonlinear links, marginalization may require numerical integration. With a random intercept \(b\sim N(0,\sigma_b^2)\), for example,

$$ \hat{\mu}_{\mathrm{marg}} =\int g^{-1}(\hat\eta+\hat b)\, \phi(\hat b;0,\hat\sigma_b^2)\,d\hat b. $$

For multiple random effects, the integral is over their joint distribution, including the fitted covariance structure. Numerical quadrature or simulation can approximate it. The integration must use the appropriate fitted covariance, not independent draws for correlated random effects.

Diagnostics, Failure Modes, and Limitations

Several checks help prevent a misleading comparison:

  • Check the target. State whether the diagnostic concerns fit within observed clusters or the population-averaged mean. Do not choose conditional or marginal values merely because one produces smaller discrepancies.
  • Check the integration. For a nonlinear link, confirm that marginal values average inverse-link means over random effects. Applying the inverse link to the fixed-effects predictor alone is generally a zero-random-effect value, not a marginal value.
  • Check the random-effects distribution. Integration is only as credible as the assumed distribution and covariance structure. Strongly nonnormal latent effects or a poorly estimated variance can make the calculated marginal mean misleading.
  • Check sparse clusters and shrinkage. Cluster-specific estimates can be pulled toward zero, especially with little information within a cluster. Conditional fitted values therefore do not reveal the true cluster effect with certainty.
  • Keep plug-in uncertainty in view. These fitted means use estimated fixed effects, covariance parameters, and—in the conditional case—estimated random effects. Their calculation alone does not propagate uncertainty in those estimates.

A common mistake is to claim that the marginal fitted value is \(g^{-1}(x^{\mathsf T}\hat\beta)\) because the random effects have mean zero. That reasoning averages the random effect on the linear-predictor scale and then applies the inverse link. The required quantity is instead \(E_b[g^{-1}(x^{\mathsf T}\hat\beta+z^{\mathsf T}b)]\). The two agree in special cases, such as an identity link with mean-zero random effects, but not generally for binary and count models.

Conditional fitted values are not automatically superior because they use cluster information, and marginal fitted values are not automatically superior because they average across clusters. Conditional values can obscure poor population-level calibration if the estimated random effects absorb a systematic discrepancy. Marginal values can fail to represent a particular observed cluster whose latent effect is far from zero. Also, neither fitted mean alone diagnoses all aspects of a GLMM: a discrepancy can arise from the link, fixed effects, random-effects structure, response distribution, or dependence assumptions. The chosen fitted-value definition clarifies the target; it does not identify the cause of a mismatch.

1
Name the prediction target.
Decide whether the question concerns an observed cluster with its estimated random effect or the average over the random-effects population.
2
Construct the fitted mean on the response scale.
For the conditional target, plug in \(\hat b_j\). For the marginal target, integrate the inverse-link mean over the fitted joint distribution of the random effects.
3
Interpret discrepancies against that target.
Describe what the comparison indicates and check assumptions and uncertainty before attributing a pattern to model failure.

Check Your Understanding

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

  1. A logistic random-intercept model has a mean-zero random effect. Is the inverse-logit of the fixed-effects predictor generally the marginal probability? Explain.
  2. Under an identity-link Gaussian random-intercept model with mean-zero random effects, the fixed predictor is 20 and an observed cluster's estimated intercept is \(-3\). Find both fitted means.
  3. A Poisson log-link model has fixed predictor \(\log(5)\) and a mean-zero normal random intercept with variance \(0.4\). Give the marginal fitted mean.
  4. What does a conditional fitted mean use that a marginal fitted mean averages over?
  5. Why might a conditional fitted value appear close to an observation even when the population-averaged fit is inadequate?

Solutions. (1) No. The marginal probability is \(E_b[\operatorname{logit}^{-1}(x^{\mathsf T}\hat\beta+z^{\mathsf T}b)]\); the inverse-logit of the fixed predictor is the zero-random-effect probability and generally differs. (2) The conditional mean is \(20-3=17\); the marginal mean is \(20+E(b)=20\), in the response's units. (3) Using \(E[\exp(b)]=\exp(\sigma_b^2/2)\), the marginal mean is \(5\exp(0.4/2)=5\exp(0.2)\approx 6.107\) events. (4) The conditional value plugs in the estimated random effect for the observed cluster; the marginal value integrates over the modeled random-effects distribution. (5) The cluster-specific estimated effect can absorb a local departure, so fit within observed clusters does not by itself establish that the population-averaged mean is adequate.

Clinical Biostats