Why Predictor Origins and Factor Codes Matter
A predictor’s units and range affect numerical optimization, but its origin also matters. In a generalized linear mixed model (GLMM), the origin determines what the random intercept represents. With a random slope, it also determines the covariance between that intercept and the slope. Changing factor contrasts can have a similar effect: the fitted model may be unchanged while the individual random-effect coefficients, and their covariance, are expressed differently.
This distinction is useful when diagnosing a fit. If recentering produces different-looking random-effect variances, that alone does not show that the model fit changed. Conversely, if the covariance structure is constrained, a change of coding can change the model itself. The relevant question is whether the transformation preserves the model’s linear-predictor space and covariance assumptions.
Model and Assumptions
Let \(Y_{ij}\) be the response for observation \(j\) in cluster \(i\), and let \(b_i\) be that cluster’s random-effects vector. A GLMM specifies a conditional response distribution from an exponential-family model, with conditional mean \(\mu_{ij}=E(Y_{ij}\mid b_i)\) and link \(g\), such that
Here \(x_{ij}\) and \(z_{ij}\) are fixed- and random-effects design vectors, \(\beta\) is the fixed-effects coefficient vector, and \(G\) is the random-effects covariance matrix. The usual setup assumes clusters are independent, and responses are conditionally independent given the random effects and the model covariates. The response distribution, link, and random-effects structure are held fixed when comparing alternative codings.
For one continuous predictor \(x_{ij}\), a random intercept and random slope give the linear predictor
The random intercept \(b_{0i}\) is the cluster-specific deviation at \(x=0\); the random slope \(b_{1i}\) is the cluster-specific deviation in slope per one-unit increase in \(x\). Thus \(\sigma_{01}\) is tied to the chosen zero of \(x\), not just to the data.
Centering a Continuous Predictor
Choose a constant \(c\), and define the centered predictor \(x_{c,ij}=x_{ij}-c\). Substituting \(x_{ij}=x_{c,ij}+c\) into the linear predictor gives
The fixed intercept and random intercept have therefore changed, while the fixed slope and random slope have not. Define \(b_{0i}^{*}=b_{0i}+cb_{1i}\) and \(b_{1i}^{*}=b_{1i}\). Since these are linear transformations of a multivariate normal vector, their covariance matrix is
This is an exact change of coordinates, not an approximation. The transformed intercept is the random deviation at \(x=c\), because \(x_c=0\) there. The slope variance is unchanged, but the intercept variance and intercept–slope covariance generally change.
Worked Covariance Transformation
Worked Example: Re-centering at a Meaningful Predictor Value
Suppose a hypothetical fitted model has random-intercept variance \(0.50\), random-slope variance \(0.040\), and intercept–slope covariance \(0.10\). The predictor is measured in tens of units, and we recenter it at \(c=2\), meaning the original predictor value is 20 units.
The transformed intercept variance is
The transformed intercept–slope covariance is
The slope variance remains \(0.040\). The new intercept describes each cluster’s deviation at the original predictor value 20, rather than at zero. The change from covariance \(0.10\) to \(0.18\) is expected under this re-expression; it does not, by itself, indicate a different fit. For a check, the random-effect variance in the linear predictor at \(x=2\) under the original coding is \(0.50+2(2)(0.10)+2^2(0.040)=1.06\), exactly the new intercept variance.
Centering and Numerical Conditioning
Centering can improve numerical conditioning when a predictor’s values are far from zero. In a design matrix with an intercept, a large predictor mean can make the intercept and slope columns strongly related. Centering around a representative value makes the intercept column and centered-predictor column less correlated in the unweighted design. In a GLMM, the likelihood curvature also depends on fitted means and random effects, so centering is not a guarantee of a well-conditioned optimization problem. The eigenvalue and Hessian checks discussed in the earlier material remain relevant.
Worked Example: Comparing Predictor Design Matrices
Consider four hypothetical predictor values, \(100,110,130,140\). The unweighted fixed-effects design has an intercept and a slope column. Before centering, its cross-product matrix is
Center at \(c=120\). The centered values are \(-20,-10,10,20\), which sum to zero and have squared sum \(1000\). The centered cross-product matrix is
The determinant is unchanged, as expected for this invertible reparameterization, but the off-diagonal term disappears. The raw matrix has a condition number of roughly \(8.6\times10^5\), while the centered matrix has condition number \(1000/4=250\). This illustrates why centering can substantially improve the geometry of a design matrix even though it does not add information. The numbers describe an unweighted design; the effective curvature in a GLMM is not generally equal to this cross-product matrix.
Factor Contrasts and Random Effects
For a two-level factor coded \(x=0\) or \(x=1\), treatment coding makes the intercept refer to the \(x=0\) level. An alternative is \(q=x-\tfrac12\), which codes the levels as \(-\tfrac12\) and \(+\tfrac12\). With a random intercept and random factor slope, substituting \(x=q+\tfrac12\) shows that the new random intercept is \(b_{0i}^{*}=b_{0i}+\tfrac12 b_{1i}\), while the random slope is unchanged. The new intercept is the cluster deviation at the midpoint of the coded factor, on the linear-predictor scale.
More generally, a full-rank contrast transformation changes the coordinates used to represent factor effects. If the fixed-effects design spans the same columns and the random-effects covariance is transformed consistently without restrictive constraints, the implied linear predictors and likelihood can remain the same. However, a model that sets certain covariances to zero, or uses a diagonal covariance matrix, is not generally invariant to such transformations. The restriction may describe different possible cluster effects after recoding.
Worked Example: Treatment Coding Versus Effect Coding
Suppose a hypothetical random-intercept–random-slope model for a two-level factor has treatment-coded covariance entries \(\operatorname{Var}(b_{0i})=0.50\), \(\operatorname{Var}(b_{1i})=0.040\), and \(\operatorname{Cov}(b_{0i},b_{1i})=0.10\). Under effect coding \(q=x-\tfrac12\), the transformed intercept is \(b_{0i}^{*}=b_{0i}+0.5b_{1i}\).
Its variance is
Its covariance with the slope is
The factor slope variance remains \(0.040\). These transformed entries describe the same random linear predictors under a full covariance model. The intercept now refers to the midpoint of the two factor codes, not specifically to the \(x=0\) reference level. In a logistic GLMM, this midpoint is on the log-odds scale; it is not an average of the two level-specific probabilities.
How to Diagnose a Coding-Sensitive Fit
A useful diagnostic is to fit the same substantive model under a sensible recentering or alternative full-rank factor contrast, then compare quantities that should be invariant with quantities that are expected to change. For an equivalent parameterization, fitted linear predictors for the same observations should agree up to numerical tolerance, and fixed-effect estimates should obey the corresponding transformation. Random-effect covariance entries should match the transformation formula, not necessarily their original numerical values.
Write down the predictor units, centering constant, factor levels, and contrast columns. An intercept is interpretable only relative to these choices.
Use the algebraic re-expression of the linear predictor and the covariance transformation. Do not compare covariance entries as if their meanings were unchanged.
Compare fitted linear predictors or likelihood values for models that truly have the same design space and covariance freedom. Material discrepancies can indicate numerical instability, different constraints, or a coding implementation error.
If centering leaves weak curvature or unstable estimates, the problem may be limited design information, a sparse factor level, or a random-effects structure that the data do not support. Reparameterization cannot create information.
Common Pitfalls and Alternatives
- Misreading covariance changes. It is wrong to conclude that a changed intercept–slope covariance proves the fitted model changed. The correction is to transform the covariance matrix and compare implied predictions.
- Assuming centering always improves conditioning. Centering often reduces intercept–slope column dependence, but the best choice depends on the design and the GLMM’s weighted likelihood curvature. It cannot fix all optimization problems.
- Ignoring covariance constraints. Setting intercept–slope covariance to zero before recentering does not generally imply zero covariance afterward. A constrained model can therefore change when recoded.
- Overinterpreting a coded intercept. In a nonlinear-link model, a linear-predictor value at a contrast midpoint does not equal an average response probability or mean count.
Centering at the sample mean is a common numerical choice; centering at a scientifically meaningful value can make the intercept easier to interpret. Factor alternatives include treatment, sum, or other full-rank contrasts, selected to support the intended comparisons. Neither centering nor contrast coding is universally best. The choice should be documented, and comparisons should distinguish changed coordinates from changed model restrictions.
Check Your Understanding
Answer each question, then check the brief solutions.
- A random-intercept–random-slope model has \(\sigma_0^2=0.30\), \(\sigma_{01}=0.05\), and \(\sigma_1^2=0.02\). What are the transformed intercept variance and intercept–slope covariance when centering at \(c=1\)?
- Why can the covariance between a random intercept and slope change when the predictor is centered even if the fitted model is equivalent?
- Does centering guarantee that the GLMM likelihood Hessian will be well-conditioned? Give the reason.
- For a two-level factor, what does the random intercept represent under coding \(q=x-\tfrac12\)?
- Why can a zero-covariance random-effects assumption lead to a different model after changing factor contrasts?
Solutions. (1) The transformed variance is \(0.30+2(1)(0.05)+1^2(0.02)=0.42\), and the covariance is \(0.05+1(0.02)=0.07\). (2) The intercept is defined at a different predictor origin; its transformed value includes a multiple of the random slope, changing its covariance with that slope. (3) No. Centering may improve design geometry, but GLMM curvature also depends on fitted means, random effects, and the available information. (4) It is the cluster deviation at the midpoint of the factor codes, on the linear-predictor scale. (5) Zero covariance is a coordinate-dependent restriction; after a contrast transformation, the corresponding covariance is generally nonzero.