Tutorials › Generalized Linear Mixed Models (GLMM) › Covariance in Cross-Classified Models

Crossed and Nested Random Effects · Tutorial 489 of 698

Covariance in Cross-Classified Models

Learn to identify which random-intercept variance components contribute to a pair’s marginal covariance, and distinguish that covariance from response-scale covariance under a nonlinear link.

Advanced 10 min read

What You'll Learn

  • Write the marginal covariance for distinct observations in a cross-classified random-intercept model.
  • Determine which variance components contribute by comparing the classifications shared by an observation pair.
  • Separate Gaussian response-scale covariance from covariance on the latent linear-predictor scale.
  • Calculate response-scale covariance for a Poisson log-link model with normal random effects.
  • Diagnose common errors involving unshared classifications, residual variance, and nonlinear links.

Why Shared Classifications Determine Covariance

In a cross-classified design, an observation can belong to a level of each of several classifications, and the classifications are not simply nested within one another. For example, a response might be associated with both a school and a clinician. Two responses from the same school can come from different clinicians; two responses from the same clinician can come from different schools. The random intercepts induce dependence when observations share a classification level.

The key calculation is not to add every variance component in the model. For a pair of distinct observations, include only the components for classifications whose levels they share. In a Gaussian model with an identity link, this gives the marginal response covariance directly. In a GLMM with a nonlinear link, the shared random effects still determine dependence, but the response-scale covariance generally is not just a sum of variance components.

Definition: Let \(Y_r\) denote response \(r\), with \(r=1,\ldots,n\), and let \(q_k(r)\) denote its level in classification \(k\), for \(k=1,\ldots,K\). A cross-classified random-intercept model has linear predictor $$ \eta_r=\mathbf{x}_r^\top\boldsymbol{\beta}+\sum_{k=1}^{K}u_{k,q_k(r)}. $$ Assume the random intercepts have mean zero, variance \(\tau_k^2\) within classification \(k\), and are independent across levels and classifications. For a GLMM, assume responses are conditionally independent given all random effects, with conditional mean \(\mu_r=g^{-1}(\eta_r)\). Here \(g\) is the link function.

The notation \(q_k(r)\) identifies the level of classification \(k\) assigned to response \(r\). The random-intercept assumptions mean that two observations sharing a level have the same random term for that classification, while random terms for different levels are uncorrelated. Conditional independence means that any marginal association between distinct responses comes from the random effects, not from an additional residual dependence after those effects are known.

The Covariance Formula for an Identity-Link Model

First consider a Gaussian mixed model with identity link and an observation-level error: $$ Y_r=\mathbf{x}_r^\top\boldsymbol{\beta}+\sum_{k=1}^{K}u_{k,q_k(r)}+\varepsilon_r, $$ where the errors are independent of the random intercepts and of one another, with mean zero and variance \(\sigma^2\). For distinct observations \(r\) and \(s\), the fixed parts do not vary, and independent random terms contribute zero covariance. A shared random intercept contributes its variance.

Theorem: Under the independent, mean-zero random-intercept assumptions above, the marginal covariance for two distinct responses in the identity-link model is $$ \operatorname{Cov}(Y_r,Y_s)=\sum_{k=1}^{K}\tau_k^2\,\mathbf{1}\{q_k(r)=q_k(s)\},\qquad r\ne s, $$ where \(\mathbf{1}\{\cdot\}\) equals 1 when its condition is true and 0 otherwise. The marginal variance of one response is $$ \operatorname{Var}(Y_r)=\sum_{k=1}^{K}\tau_k^2+\sigma^2. $$

The formula follows by expanding the covariance of the two random-effect sums. For classification \(k\), if the observations share a level, both contain the same random intercept, whose covariance with itself is \(\tau_k^2\). If they do not share a level, they contain independent intercepts and that covariance is zero. Covariances between different classifications are zero by the assumed independence.

$$ \operatorname{Cov}\left(\sum_k u_{k,q_k(r)},\sum_\ell u_{\ell,q_\ell(s)}\right) =\sum_k\sum_\ell \operatorname{Cov}\bigl(u_{k,q_k(r)},u_{\ell,q_\ell(s)}\bigr) =\sum_k \tau_k^2\mathbf{1}\{q_k(r)=q_k(s)\}. $$

The observation-level errors add \(\sigma^2\) to a response’s variance, but not to the covariance of two distinct responses, because their errors are independent. On the diagonal of the covariance matrix, each response is paired with itself and all its random intercepts are shared; the residual variance is also present. Thus the diagonal is not obtained by applying the distinct-observation formula while omitting \(\sigma^2\).

Worked Example: Two Crossed Classifications in a Gaussian Model

Suppose a hypothetical Gaussian model has school random-intercept variance \(\tau_{\text{school}}^2=4\), clinician random-intercept variance \(\tau_{\text{clinician}}^2=1.5\), and observation-level error variance \(\sigma^2=2\). Consider distinct responses from the same school but different clinicians.

They share the school intercept but not the clinician intercept. Therefore, $$ \operatorname{Cov}(Y_r,Y_s)=4(1)+1.5(0)=4. $$ The marginal variance of either response is $$ \operatorname{Var}(Y_r)=4+1.5+2=7.5. $$ Since the two marginal variances are equal, their marginal correlation is $$ \operatorname{Corr}(Y_r,Y_s)=\frac{4}{\sqrt{7.5(7.5)}}=\frac{4}{7.5}\approx 0.5333. $$ Thus, in this model, responses from the same school but different clinicians have covariance 4 response-units squared and correlation about 0.533. If the pair also shared a clinician, the covariance would instead be \(4+1.5=5.5\); the error variance would still not be added to the covariance of distinct responses.

What Changes With a Nonlinear Link?

For a general GLMM, write \(\mu_r=E(Y_r\mid\mathbf{u})=g^{-1}(\eta_r)\), where \(\mathbf{u}\) denotes all random effects. Conditional independence for distinct responses gives the law-of-total-covariance result $$ \operatorname{Cov}(Y_r,Y_s)=\operatorname{Cov}(\mu_r,\mu_s),\qquad r\ne s. $$ Indeed, the law of total covariance states that the marginal covariance is the expected conditional covariance plus the covariance of the conditional means. The first term is zero here for distinct observations, leaving the second. Unlike the identity-link case, the conditional means are nonlinear functions of the random effects. Their covariance therefore depends on the link, the fixed predictors, and the random-effects distributions, not merely on a sum of variances.

A useful explicit case is a Poisson GLMM with a log link and independent normal random intercepts. For responses \(r\) and \(s\), let \(S\) be the sum of the random intercepts they share, and let \(V=\operatorname{Var}(S)\). Write their conditional means as \(\lambda_r=\exp(a_r+S+U_r)\) and \(\lambda_s=\exp(a_s+S+U_s)\), where \(a_r,a_s\) contain fixed terms and \(U_r,U_s\) contain the unshared random terms. Under the assumptions that \(S,U_r,U_s\) are jointly independent, centered normal variables, the shared term gives $$ \operatorname{Cov}(Y_r,Y_s)=E(\lambda_r\lambda_s)-E(\lambda_r)E(\lambda_s) =E(\lambda_r)E(\lambda_s)\{\exp(V)-1\}. $$ This follows from the normal moment-generating function \(E[\exp(tZ)]=\exp(t^2\operatorname{Var}(Z)/2)\) for a mean-zero normal variable \(Z\). In the product \(\lambda_r\lambda_s\), the shared term appears as \(2S\), so its exponential moment is \(\exp(2V)\); in the product of the separate marginal means, the corresponding factor is \(\exp(V)\). The unshared terms cancel from the ratio, yielding the stated factor \(\exp(V)-1\). This result requires the normal random-effects assumption and the log link; it is not a general GLMM covariance formula.

Worked Example: Poisson Covariance From Shared Random Intercepts

Consider a hypothetical Poisson log-link model with fixed linear predictor \(\log(2)\) for each of two distinct responses. Each response has three independent normal random intercepts, from classifications A, B, and C, with variances \(0.10\), \(0.06\), and \(0.09\), respectively. The pair shares its A and B levels but has different C levels. Assume conditional independence of the responses given all random effects.

The total random-intercept variance for either response is \(0.10+0.06+0.09=0.25\), so its marginal mean is $$ m=\exp\{\log(2)+0.25/2\}=2\exp(0.125)\approx 2.2663. $$ The shared random-effect sum has variance \(V=0.10+0.06=0.16\). Therefore, the response-scale covariance is $$ \operatorname{Cov}(Y_r,Y_s)=m^2\{\exp(0.16)-1\} =4\exp(0.25)\{\exp(0.16)-1\}\approx 0.8912. $$ The final value is calculated from the unrounded expression. Rounding \(m\) and the exponential factor separately before multiplying can alter the last displayed digit. The covariance is in squared count units. Although the pair shares two classifications, the covariance is not \(0.16\): that is the shared variance on the log-linear predictor scale, while the displayed covariance is on the response scale.

Reading the Shared-Classification Pattern

A reliable way to apply the formula is to make a short membership ledger for the pair. Record, for each classification, whether the two observations have the same level. In the identity-link model, multiply each “same” entry by its variance component and add; entries marked “different” contribute zero. In a nonlinear model, this ledger identifies the shared random effects, but a response-scale calculation must then use the appropriate link and distribution assumptions.

Worked Example: Adding Only the Components the Pair Shares

Suppose a hypothetical Gaussian model has three crossed classifications with random-intercept variances \(\tau_A^2=0.8\), \(\tau_B^2=0.5\), and \(\tau_C^2=0.3\), plus error variance \(\sigma^2=1.2\). Two distinct responses share their A and C levels but have different B levels.

The covariance calculation is $$ \operatorname{Cov}(Y_r,Y_s)=0.8(1)+0.5(0)+0.3(1)=1.1. $$ Each response has marginal variance \(0.8+0.5+0.3+1.2=2.8\), so their correlation is $$ \operatorname{Corr}(Y_r,Y_s)=\frac{1.1}{\sqrt{2.8(2.8)}}=\frac{1.1}{2.8}\approx 0.3929. $$ The B variance is part of each response’s marginal variance, but not their covariance, because this pair does not share a B level. The observation-level error likewise contributes to the marginal variance but not to the covariance of distinct responses.

Assumptions, Diagnostics, and Common Pitfalls

The covariance formula is only as appropriate as its assumptions. The identity-link sum requires independent random intercepts across classifications and levels, the stated variance components, and independent observation-level errors for the diagonal variance formula. The nonlinear example additionally requires normal random effects and a log link. Conditional independence is important in both settings: if responses remain dependent after conditioning on all random effects, their conditional covariance must also be included.

Useful checks begin with the design. Confirm that the pair really shares the levels indicated by the membership records, and that the factors are represented as crossed rather than incorrectly treated as nested. Then inspect model fit: convergence warnings, variance estimates near zero or implausibly large, and residual patterns can indicate a misspecified random-effects structure or distribution. For a Gaussian model, residual dependence remaining among pairs after accounting for their shared levels challenges the conditional-independence assumption. For a GLMM, examine residual and dispersion diagnostics appropriate to the response distribution; excess variation can make a simple conditional-variance specification inadequate. Raw response covariances also need cautious interpretation in GLMMs, because the mean and link affect covariance on the response scale.

A common mistake is to add every random-intercept variance when calculating the covariance of a pair. That gives the random-intercept contribution to a single response’s variance, not the pair’s covariance. The correction is to include a component only when the pair shares a level of that classification. A second mistake is to use the Gaussian identity-link sum on the observed counts in a Poisson log-link model. There, shared effects determine the dependence, but the response-scale covariance must be derived from the conditional means and the distributional assumptions.

This calculation complements, rather than replaces, other covariance descriptions. A nested random-intercept model has a structured sharing pattern: observations in different lower-level units may still share a higher-level intercept. A cross-classified model uses the same principle, but a pair can share any subset of the crossed classifications. One could also describe the covariance through a full covariance matrix, but the shared-level formula makes each contribution interpretable. These random-effects representations are not a substitute for checking whether the design and assumptions support the covariance structure; sparse overlap, misspecified random effects, or dependence not represented in the model can limit the interpretation.

Key takeaway: For distinct observations in a cross-classified identity-link random-intercept model, marginal covariance is the sum of the variance components for classifications they share. In a nonlinear GLMM, first identify the shared random effects, then calculate covariance on the response scale using the link and distribution assumptions.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. In a Gaussian model, two distinct responses share classification A with variance \(1.2\), but not classification B with variance \(0.7\). What is their marginal covariance?
  2. In the same model, if the observation-level error variance is \(0.9\), does it change the covariance in question 1? What is the marginal variance of one response if it belongs to one level of each classification?
  3. In a Poisson log-link model with normal random effects, two observations share random intercepts whose variances sum to \(0.20\). If their marginal means are 3 and 4, what is their response-scale covariance?
  4. Why is it generally incorrect to report the sum of shared random-intercept variances as the response-scale covariance in a nonlinear GLMM?

Solutions. 1. They share only A, so \(\operatorname{Cov}(Y_r,Y_s)=1.2\). 2. No: independent observation-level errors do not contribute to covariance between distinct responses. The marginal variance is \(1.2+0.7+0.9=2.8\). 3. Here \(V=0.20\), so the covariance is \(3(4)\{\exp(0.20)-1\}=12(0.2214)\approx 2.657\), in squared count units. 4. A nonlinear inverse link transforms the random effects before the conditional means are averaged. The response-scale covariance consequently depends on that transformation, the fixed predictors, and the random-effects distribution, not just on the shared variance sum.

Clinical Biostats