Tutorials › Generalized Linear Mixed Models (GLMM) › Centering Predictors Within Nested Groups

Crossed and Nested Random Effects · Tutorial 517 of 698

Centering Predictors Within Nested Groups

You will learn to decompose a predictor into within-group and between-group components, interpret their GLMM coefficients, and assess which variation can inform a random slope.

Advanced 12 min read

What You'll Learn

  • Compute within-group deviations and between-group means, and reconstruct the original predictor.
  • Specify a nested GLMM with separate within-group and between-group effects.
  • Interpret fixed and random within-group slopes on the model’s link scale.
  • Distinguish the data variation that informs within-group slopes from that informing between-group effects.
  • Recognize when centering cannot resolve confounding, weak information, or a misspecified random-effects structure.

Why Separate Within-Group and Between-Group Variation?

Suppose a clinical service records how many hours each patient spends in a self-management program, with patients nested within clinics. A patient who attends more hours than other patients in the same clinic differs in a within-clinic way. A clinic whose patients attend more hours on average differs in a between-clinic way. Those are distinct comparisons, and their associations with an outcome need not be equal.

A model using only the raw predictor can combine these sources into one coefficient. Group-mean centering makes the within-group deviation explicit; including the group mean as a second predictor represents between-group differences separately. In a GLMM, this distinction applies to the conditional model, given the random effects. It does not by itself make an association causal or remove all assumptions about how predictors relate to random effects.

Definition: For observation \(i\) in group \(j\), let \(x_{ij}\) be a predictor and let \(\bar{x}_j\) be its observed mean in group \(j\). The within-group deviation is \(x_{W,ij}=x_{ij}-\bar{x}_j\). The between-group component is the group mean, often centered at a chosen reference \(\bar{x}\): \(x_{B,j}=\bar{x}_j-\bar{x}\). Thus \(x_{ij}=x_{W,ij}+x_{B,j}+\bar{x}\).

Here \(\bar{x}\) may be the observation-weighted grand mean, \(\sum_j n_j\bar{x}_j/\sum_j n_j\), or a group-weighted mean, \(\sum_j\bar{x}_j/J\). The choice changes the reference point and intercept, not the within-group deviations. State the choice, especially with unequal group sizes. A group-mean centered predictor alone is not the full within-between decomposition: including \(x_{B,j}\) allows a separate between-group association.

A Conditional GLMM for the Decomposition

For a nested random-intercept and random-within-slope model, write

$$ g\{E(Y_{ij}\mid b_{0j},b_{1j})\} = \beta_0+\beta_W x_{W,ij}+\beta_B x_{B,j} +b_{0j}+b_{1j}x_{W,ij}. $$

The conditional response distribution is from the chosen GLM family, with its variance and link specified for the outcome. Responses are conditionally independent given the random effects and predictors. The group effects satisfy \((b_{0j},b_{1j})^\mathsf{T}\sim N_2(0,\Sigma_b)\), independently across groups, with an estimated covariance matrix \(\Sigma_b\). The model also assumes that this random-effects distribution is appropriate and that the predictors are suitably independent of the random effects under the model’s conditioning assumptions. Inference requires enough groups and enough informative within-group data for the parameters to be estimated; centering does not guarantee that.

The fixed within-group coefficient \(\beta_W\) describes the average change in the conditional linear predictor for a one-unit increase in the predictor relative to the group mean. In this random-slope model, group \(j\)’s conditional within-group slope is \(\beta_W+b_{1j}\). The fixed between-group coefficient \(\beta_B\) describes the change in the conditional linear predictor associated with a one-unit increase in the centered group mean, holding the within deviation and random effects fixed. These are link-scale interpretations; conditional means generally require applying the inverse link.

Key distinction: Within-group deviations supply the within-group contrasts that inform \(\beta_W\) and the random-slope variation \(b_{1j}\). Differences among group means supply the between-group contrasts that inform \(\beta_B\). A random slope multiplying \(x_{W,ij}\) is not a random slope for the group mean.

Deriving the Within-Between Representation

The decomposition follows directly by adding and subtracting the group mean. Its value is that it makes explicit what a raw-predictor model assumes.

1
Split the predictor.
\(x_{ij}=(x_{ij}-\bar{x}_j)+\bar{x}_j=x_{W,ij}+x_{B,j}+\bar{x}\).
2
Use separate coefficients.
A linear predictor with distinct within and between effects is \(\beta_Wx_{W,ij}+\beta_Bx_{B,j}\), in addition to the intercept and random effects.
3
Identify the restriction in a raw-predictor model.
Since \(x_{ij}=x_{W,ij}+x_{B,j}+\bar{x}\), a single coefficient \(\beta x_{ij}\) assigns coefficient \(\beta\) to both components; it imposes \(\beta_W=\beta_B=\beta\), with the constant \(\beta\bar{x}\) absorbed into the intercept.

This algebra holds for the linear predictor in a GLMM just as it does for a linear model. It does not assert that the marginal mean, after averaging over random effects, has the same coefficient interpretation. The link-scale coefficients are conditional on the random effects.

Worked Example: Calculate the Two Components

Consider hypothetical predictor values in three clinics: Clinic A has \(2,4,6\) hours; Clinic B has \(10,12\); Clinic C has \(3,9\). The clinic means are \(4,11,6\), respectively. There are seven observations, so the observation-weighted grand mean is \(\bar{x}=46/7\approx6.571\) hours.

For the value \(x_{ij}=6\) in Clinic A, \(x_{W,ij}=6-4=2\) hours and \(x_{B,j}=4-46/7=-18/7\approx-2.571\) hours. Adding the components and reference gives \(2-18/7+46/7=6\) hours, recovering the original value. Equivalently, the value is \(0.571\) hours below the grand mean because \(x_{W,ij}+x_{B,j}=2-2.571=-0.571\).

The within-group value \(2\) says this observation is two hours above its own clinic mean. The between-group value \(-2.571\) says Clinic A’s mean is about 2.571 hours below the observation-weighted grand mean. Those are different comparisons, not two descriptions of the same effect.

Worked Conditional Interpretation

Worked Example: A Random Slope in a Logistic GLMM

Suppose a hypothetical fitted model for a binary outcome uses a logit link and gives \(\beta_0=-1.00\), \(\beta_W=0.30\), and \(\beta_B=0.80\). For an observation with \(x_{W,ij}=2\) hours and \(x_{B,j}=1\) hour, suppose the estimated conditional random effects used for illustration are \(b_{0j}=0.20\) and \(b_{1j}=-0.05\) per hour.

The conditional log-odds are

$$ \eta_{ij} =-1.00+(0.30)(2)+(0.80)(1)+0.20+(-0.05)(2) =0.50. $$

The corresponding conditional probability is \(\operatorname{logit}^{-1}(0.50)=1/(1+e^{-0.50})\approx0.6225\). This is the model-based probability conditional on the stated random effects and covariates.

For this clinic, the within-group slope is \(\beta_W+b_{1j}=0.30-0.05=0.25\) log-odds per hour, so the conditional odds ratio for a one-hour increase in the within-group deviation is \(e^{0.25}\approx1.284\). At \(b_{1j}=0\), the slope would be \(0.30\) and the corresponding odds ratio \(e^{0.30}\approx1.350\). Thus, with a random slope, \(\exp(\beta_W)\) is the odds ratio only at random slope zero; it is not the odds ratio for every group. The between-group coefficient is \(0.80\) log-odds per hour of higher group mean, conditional on the random effects, giving \(e^{0.80}\approx2.226\) for that conditional contrast. Neither odds ratio is an unconditional comparison after integrating over random effects.

Which Variation Informs Which Slope?

Within-group effects are learned from differences among observations in the same group. Between-group effects are learned from differences among group means. A random slope for \(x_{W,ij}\) allows the within-group association to vary across groups, so its variance is informed by the pattern of within-group contrasts across groups. Groups with no within-group variation in \(x\) have \(x_{W,ij}=0\) for every observation and provide no direct within-group slope contrast. Repeated observations and adequate within-group spread are important; a large total sample does not compensate automatically for too few groups or little within-group variation.

The following design calculation illustrates the separation. For the clinic data above, the within-group sum of squares is

$$ \sum_j\sum_i(x_{ij}-\bar{x}_j)^2 =(4+0+4)+(1+1)+(9+9)=28\ \text{hours}^2. $$

The weighted sum of squares of group means around the grand mean is

$$ \sum_j n_j(\bar{x}_j-\bar{x})^2 =3(4-46/7)^2+2(11-46/7)^2+2(6-46/7)^2 =\frac{2926}{49}\approx59.71\ \text{hours}^2. $$

These are predictor-design summaries, not estimates of outcome variance or a direct comparison of coefficient precision. They show that the data contain both within-clinic and between-clinic predictor variation. If the within sum of squares were zero, the data could not estimate a within-clinic slope from observed within-clinic contrasts. If all clinic means were identical, there would be no between-clinic variation to estimate \(\beta_B\).

Alternatives, Diagnostics, and Limits

SpecificationWhat it representsMain caution
Raw \(x_{ij}\) onlyOne coefficient shared by within- and between-group variationImposes equality of the two associations on the linear-predictor scale.
Within deviation onlyWithin-group association, with no separate group-mean predictorDoes not estimate a distinct between-group association; omitting it may be consequential if that association matters.
Within deviation and group meanSeparate within- and between-group fixed effectsNeeds both sources of predictor variation and sufficient groups to support estimation.
Grand-mean centering onlyChanges the predictor’s reference point but retains its raw variationDoes not separate within- and between-group associations.

Useful checks include tabulating group sizes and within-group ranges, plotting \(x_{W,ij}\) by group, and checking the distribution of group means. Inspect fitted random-slope variation, its uncertainty, and convergence; a variance estimate near zero or a poorly determined intercept-slope correlation can indicate weak information or a model that is too ambitious for the design. Check whether the assumed conditional response distribution and link are reasonable, and examine residual or predictive diagnostics appropriate to the GLMM. A converged fit alone does not establish that the decomposition or random-effects assumptions are appropriate.

Centering is a change of predictor representation, not a remedy for confounding or a substitute for design. The model still relies on its assumptions about the relationship between covariates and random effects. Measurement error in group means, very small groups, missing observations, and informative group sizes can complicate interpretation. The random slope specified here concerns within-group deviations; adding a random slope for a group-level predictor is a different model choice, requiring enough groups and support for that variation.

Common pitfall: “I centered \(x\) within groups, so the model now estimates both within- and between-group effects.” Not if the group mean is absent from the linear predictor. Group-mean centering creates \(x_{W,ij}\); a separate \(x_{B,j}\) term is needed to estimate a distinct between-group coefficient.

Check Your Understanding

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

  1. In one group, observations have predictor values \(3\) and \(7\). Find the group mean and both within-group deviations.
  2. A model has a logit link and a random within-group slope. What is group \(j\)’s conditional odds ratio for a one-unit within-group increase?
  3. What equality does a raw-predictor-only model impose when expressed using within- and between-group components?
  4. Every group has at least two observations, but the predictor is constant within each group. Which slope is unsupported by within-group contrasts, and why?

Solutions. (1) The mean is \((3+7)/2=5\). The deviations are \(3-5=-2\) and \(7-5=2\); they sum to zero. (2) The group-specific conditional slope is \(\beta_W+b_{1j}\), so the odds ratio is \(\exp(\beta_W+b_{1j})\). (3) Since \(x_{ij}=x_{W,ij}+x_{B,j}+\bar{x}\), a single raw-\(x\) coefficient assigns the same coefficient to both components: \(\beta_W=\beta_B\). (4) The within-group slope is unsupported by within-group contrasts: each deviation is zero, so changing \(x_{W,ij}\) within a group is never observed. Between-group predictor differences may still exist and can inform a between-group association.

Clinical Biostats