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

Crossed and Nested Random Effects · Tutorial 502 of 698

Random Slopes in Cross-Classified Models

Learn how crossed random slopes represent heterogeneous predictor effects across subjects and items, and how to judge what variation in the design supports each slope.

Advanced 12 min read

What You'll Learn

  • Write a GLMM with crossed subject and item random intercepts and slopes.
  • Match each random slope to the predictor and grouping factor it describes.
  • Distinguish direct within-unit information from assumption-dependent indirect information about slope variance.
  • Derive how crossed random effects contribute to the latent-predictor variance and covariance.
  • Diagnose weak support, confounding, and overfitting in crossed random-slope models.

Why Crossed Random Slopes Need Design-Based Interpretation

In a crossed experiment, each subject may respond to several items, and each item may be seen by several subjects. A random intercept allows subjects or items to differ in their baseline response. A random slope goes further: it allows the association between a predictor and the response to vary across the units named by that slope. The model is useful only if its terms correspond to the design and its assumptions are plausible.

The key design question is not simply whether a predictor appears in the model. Ask where it varies. A predictor that changes across observations within subjects can provide direct information about variation in its subject-specific slope. If it also changes within items, it can provide direct information about item-specific slope variation. Other patterns can sometimes inform a slope-variance component indirectly through the assumed random-effects distribution, but they do not supply the same within-unit slope contrast.

Model and Assumptions

Definition: In a cross-classified random-slope model, observations belong to two or more crossed grouping factors, and at least one grouping factor has a random coefficient multiplying a predictor. For subjects \(i=1,\ldots,I\), items \(j=1,\ldots,J\), and observed subject-item pairs \((i,j)\), one possible GLMM is $$ g\{E(Y_{ij}\mid \mathbf b_i,\mathbf c_j)\} =\beta_0+\beta_x x_{ij}+\beta_z z_{ij} +b_{0i}+b_{1i}x_{ij}+c_{0j}+c_{1j}z_{ij}. $$ Here \(g\) is the link function; \(\beta\) terms are fixed effects; \(b_{0i},b_{1i}\) are subject-specific random intercept and slope; and \(c_{0j},c_{1j}\) are item-specific random intercept and slope. The corresponding random-effect vectors are commonly modeled as \(\mathbf b_i=(b_{0i},b_{1i})^\mathsf T\sim N(\mathbf 0,G_s)\) and \(\mathbf c_j=(c_{0j},c_{1j})^\mathsf T\sim N(\mathbf 0,G_j)\), independently across subjects and items and, in this model, independently between the two grouping factors.

Conditional on all random effects, observations are assumed to follow the specified response distribution, with the mean related to the linear predictor through \(g\). For binary outcomes, for example, one may use a Bernoulli distribution and the logit link. The random-effects normality and independence assumptions are part of the model; they are not guaranteed by crossing. The predictor values, observed subject-item pairings, and outcome distribution must also be recorded and modeled appropriately.

The formula above assigns \(x_{ij}\) a subject-specific slope and \(z_{ij}\) an item-specific slope. It does not automatically imply that both predictors vary within both kinds of unit. In particular, a subject slope for \(x\) has a direct within-subject contrast when subjects are observed at different \(x\) values. An item slope for \(z\) has a direct within-item contrast when an item is observed at different \(z\) values. These are design statements, not consequences of including a term in software.

Worked Example: Assigning Slopes to the Crossed Factors

Worked Example: Assigning Slopes to the Crossed Factors

Suppose 24 subjects each respond to 12 items, with each item presented to many subjects. Each subject sees both versions of a binary treatment, coded \(x=-1\) or \(x=1\), and each item is presented under both versions. The outcome is a correct/incorrect response. Which slopes have direct within-unit design support?

Use a Bernoulli response with a logit link. A suitable starting model is $$ \operatorname{logit}\{P(Y_{ij}=1\mid\mathbf b_i,\mathbf c_j)\} =\beta_0+\beta_x x_{ij}+b_{0i}+b_{1i}x_{ij}+c_{0j}+c_{1j}x_{ij}. $$

For each subject, treatment changes from \(-1\) to \(1\) across observations. Thus the within-subject treatment contrast directly informs that subject's treatment slope \(b_{1i}\), subject to sufficient observations and the model assumptions. Each item also appears under both treatment versions across subjects, so treatment changes within item as well. This supplies direct design information about item-specific treatment slope \(c_{1j}\).

The treatment contrast in the linear predictor for subject \(i\) and item \(j\), holding the random effects fixed, is $$ (\beta_x+b_{1i}+c_{1j})(1-(-1))=2(\beta_x+b_{1i}+c_{1j}). $$ For item \(j\), the corresponding contrast includes its slope contribution \(2c_{1j}\). The factor of 2 occurs because treatment is coded from \(-1\) to \(1\); with 0/1 coding, the contrast would be one coefficient unit. The model therefore describes variation in treatment effects across both subjects and items, not just variation in baseline response.

A direct contrast does not guarantee precise estimation. It requires adequate observations and enough independent subjects and items to estimate distributions of slopes. Missing treatment-by-unit combinations, sparse outcomes, and imbalance can weaken the information even when a predictor technically varies within a unit.

How Crossed Slopes Contribute to Variation

The random-effects terms add on the linear-predictor scale. Under a diagonal covariance structure, suppose the subject intercept and slope variances are \(\tau_{00}\) and \(\tau_{11}\), and the item intercept and slope variances are \(\omega_{00}\) and \(\omega_{11}\). With independent subject and item effects, the random contribution for observation \((i,j)\) has variance

$$ \operatorname{Var}(b_{0i}+b_{1i}x_{ij}+c_{0j}+c_{1j}z_{ij}) =\tau_{00}+\tau_{11}x_{ij}^{2}+\omega_{00}+\omega_{11}z_{ij}^{2}. $$

This expression shows why the predictor values matter: a random slope contributes variance in proportion to the square of its predictor value. If intercept and slope are allowed to covary, additional terms appear. For example, the subject contribution becomes \(\tau_{00}+2x_{ij}\tau_{01}+x_{ij}^{2}\tau_{11}\), where \(\tau_{01}\) is their covariance.

Two observations sharing a subject share that subject's random effects; two sharing an item share that item's effects. For example, under the diagonal structure, the covariance between the two random contributions for observations \((i,j)\) and \((i',j')\) is

$$ \mathbf 1(i=i')\{\tau_{00}+\tau_{11}x_{ij}x_{i'j'}\} +\mathbf 1(j=j')\{\omega_{00}+\omega_{11}z_{ij}z_{i'j'}\}, $$

where \(\mathbf 1(A)\) equals 1 when \(A\) is true and 0 otherwise. This is a covariance on the random contribution to the linear predictor. In a non-Gaussian GLMM, it is not generally the covariance of the observed responses themselves; the link and response distribution also affect the latter.

Worked Example: Calculating Shared Random-Effect Covariance

Worked Example: Calculating Shared Random-Effect Covariance

In a hypothetical logit model, let the subject intercept and slope variances be \(\tau_{00}=0.36\) and \(\tau_{11}=0.16\). Let item intercept and slope variances be \(\omega_{00}=0.25\) and \(\omega_{11}=0.09\). Assume all intercept-slope covariances are zero. Consider two observations from the same subject, at \(x=-1\) and \(x=1\), on different items. Calculate their random-contribution covariance.

They share the subject but not the item. Therefore the item term is zero, and $$ \operatorname{Cov}(\text{random contributions}) =\tau_{00}+\tau_{11}(-1)(1) =0.36-0.16=0.200. $$

The positive covariance reflects their shared subject intercept; the negative product of their opposite treatment values reduces it. If instead both observations were at \(x=1\), on different items, the covariance would be \(0.36+0.16(1)(1)=0.520\). These are covariances of latent linear-predictor contributions, not response probabilities or response-scale covariances.

For a single observation with \(x=1\) and \(z=-1\), the total random-contribution variance is $$ 0.36+0.16(1)^2+0.25+0.09(-1)^2 =0.36+0.16+0.25+0.09=0.860. $$ All terms are nonnegative in this variance calculation because the predictor values are squared.

What Supports a Slope Variance?

Within-unit predictor variation gives the clearest design-based support for a random slope: it creates contrasts that can differ from unit to unit. For a subject slope on \(x\), compare observations from the same subject at different \(x\) values while accounting for their item effects. For an item slope on \(x\), compare observations from the same item at different \(x\) values while accounting for their subject effects. Replication across the crossed factor is important because the shared effects of the other factor must not be mistaken for the slope variation of interest.

However, it is too strong to say that a random-slope variance can be informed only by within-unit predictor changes. Under restrictive parametric assumptions, between-unit predictor variation and replication can sometimes inform it indirectly. Consider an item-level predictor \(z_j\) that is constant for every observation of item \(j\). With a diagonal item random-effects covariance, the item contribution \(c_{0j}+c_{1j}z_j\) has variance

$$ \operatorname{Var}(c_{0j}+c_{1j}z_j)=\omega_{00}+\omega_{11}z_j^2. $$

If items are replicated and \(z_j\) takes several values, a model may use the way item-level heterogeneity changes across those values to inform \(\omega_{11}\). This is information supplied through the assumed random-effects distribution and variance structure. No item has a within-item contrast in \(z\), so it is not a direct observation of an item-specific slope contrast. The separation may be weak or confounded with other sources of variation and relies heavily on the parametric assumptions.

Worked Example: Between-Item Variation and Indirect Information

Suppose a hypothetical set of replicated items has feature values \(z_j=0,1,2\). Consider item random intercepts and slopes with independent distributions, \(\operatorname{Var}(c_{0j})=\omega_{00}=0.25\) and \(\operatorname{Var}(c_{1j})=\omega_{11}=0.09\). The feature is constant within each item. What random-effect variance does the model imply at each feature value?

At \(z=0\), the variance is \(0.25+0.09(0)^2=0.250\). At \(z=1\), it is \(0.25+0.09(1)^2=0.340\). At \(z=2\), it is \(0.25+0.09(2)^2=0.610\). Under the specified model, the item contribution is more variable at higher absolute feature values.

If the replicated responses and the rest of the model provide adequate information about item-level heterogeneity, this pattern can contribute to estimation of the slope variance. But the data do not show how a particular item's response changes as its \(z\) changes: that item was observed at only one feature value. The inference is indirect and depends on the distributional structure, including the assumed zero intercept-slope covariance. It should not be presented as equivalent to having within-item predictor contrasts.

Diagnostics, Alternatives, and Limitations

Before fitting, tabulate how each proposed slope predictor varies within each grouping factor. Check the number of units with observations at multiple predictor values, the number of observations per unit and condition, and whether the crossed structure is substantially incomplete. After fitting, inspect convergence messages, estimated variances, and the random-effects covariance estimates. A slope variance near zero or a singular covariance estimate can indicate that the data do not support the requested complexity; it does not establish that the true variation is exactly zero. Sparse binary outcomes and few grouping units can make these problems more acute.

A random-intercept-only model is simpler, but assumes no unit-to-unit variation in the predictor's conditional effect on the linear-predictor (link) scale. A random-slope model relaxes that assumption, at the cost of additional variance parameters and stronger data demands. A fixed interaction can describe systematic differences in effects between observed predictor groups, but does not by itself represent residual variation in slopes across subjects or items. A nested random-slope model is appropriate when the actual membership structure is nested, not when subjects and items are crossed. The choice should follow the design and scientific target, rather than an automatic preference for the most elaborate model.

The random-effect scale depends on predictor coding. Changing units or centering a predictor changes the interpretation of intercepts and can change the covariance parameterization. Also, a model with separate subject and item slope terms makes a particular assumption about how those sources of variation relate; it should not be read as evidence that all possible dependencies have been modeled. Inference is conditional on the chosen link, response distribution, random-effects distribution, and design structure.

Common pitfall: “A random slope is supported only if its predictor changes within every unit.” That is too absolute: within-unit change supplies direct slope-contrast information and is generally needed for a design-supported interpretation, but restrictive parametric models may obtain some indirect information from between-unit predictor variation and replication. The correction is to distinguish those two sources, assess how strongly the design supports the direct contrast, and describe any indirect identification as assumption-dependent.
Key takeaway: Name the grouping factor and predictor for every random slope. Then verify where that predictor varies. Within-unit contrasts are the clearest support for heterogeneous slopes; indirect information through modeled heterogeneity is possible in some designs but warrants more caution.

Check Your Understanding

Answer each question, then compare with the brief solutions below.

  1. A treatment predictor varies within subjects but is constant within each item. Which treatment slope has direct within-unit support, and which does not?
  2. With diagonal item random-effects covariance, \(\omega_{00}=0.20\), \(\omega_{11}=0.05\), and \(z_j=2\), calculate the variance of the item contribution.
  3. Why is an item slope for a feature constant within item not a direct within-item slope contrast?
  4. Two observations share an item but not a subject. Under a diagonal item covariance, \(\omega_{00}=0.30\), \(\omega_{11}=0.10\), and both have \(z=1\). What is their random-contribution covariance?
  5. State one reason a crossed random-slope fit might be singular or unstable.

Solutions. (1) The subject treatment slope has direct support because treatment changes within subjects. The item treatment slope does not have a within-item treatment contrast because treatment is constant within each item; any information about its variance would be indirect and assumption-dependent. (2) \(0.20+0.05(2)^2=0.20+0.20=0.400\). (3) Each item is observed at only one feature value, so its response change across feature values is not observed; inference would rely on the modeled distribution and comparisons across items. (4) They share the item, so the covariance is \(0.30+0.10(1)(1)=0.400\). (5) For example, there may be too few independent subjects or items, sparse outcomes, or insufficient predictor variation within units to estimate the extra variance reliably.

Clinical Biostats