Tutorials › Generalized Linear Mixed Models (GLMM) › Spatial Confounding Between Covariates and Random Effects

Spatial and Temporal Correlation · Tutorial 603 of 698

Spatial Confounding Between Covariates and Random Effects

Understand when spatial patterns in a covariate and latent field compete to explain the same variation, and what that means for interpreting a GLMM coefficient.

Advanced 12 min read

What You'll Learn

  • Define spatial confounding in terms of covariate patterns and plausible latent spatial fields.
  • Distinguish finite-sample competition from a claim that a correctly specified GLMM must be biased.
  • Derive the omitted-field shift in a linear predictor and relate it cautiously to GLMM fitting.
  • Diagnose alignment using maps, projections, and within-region covariate variation.
  • Compare joint spatial models, nonspatial models, and spatial-effect restrictions.
  • Explain why orthogonalizing a spatial effect changes the model rather than automatically recovering a uniquely correct coefficient.

Why Spatial Alignment Matters

A spatial GLMM may include both measured covariates and an unobserved spatial field. If the covariate itself changes smoothly over space, the field can exhibit a similar pattern. The model must then distinguish two explanations for the same broad spatial structure: a systematic contribution from the measured predictor, and residual spatial variation represented by the latent effect. This competition is called spatial confounding.

The issue is interpretive as well as computational. A fitted coefficient describes the covariate contribution conditional on the model’s spatial effect and other terms. When the observed covariate pattern closely resembles plausible latent spatial patterns, the data may provide limited information for separating those contributions. This does not mean that every spatial GLMM estimate is biased, nor that a spatial random effect should always be removed. The consequences depend on the model, the design, and the inferential target.

Definition: Spatial confounding occurs when a fixed covariate pattern is aligned with spatial patterns that can be represented by a latent spatial effect. The alignment makes the covariate contribution and the latent-field contribution compete to explain variation in the linear predictor. It is a property of the model and design, not by itself evidence of a causal confounder.

Model and Interpretation

For a response \(Y_i\) observed at spatial location \(i\), a basic spatial GLMM can be written as

$$ Y_i\mid u_i \sim \text{a distribution with mean }\mu_i,\qquad g(\mu_i)=\boldsymbol{x}_i^\mathsf{T}\boldsymbol{\beta}+u_i+\boldsymbol{o}_i^\mathsf{T}\boldsymbol{\gamma}. $$

Here \(g\) is the link function, \(\boldsymbol{x}_i\) is the fixed-effect covariate vector, \(\boldsymbol{\beta}\) its coefficient vector, \(u_i\) is a latent spatial effect, and the offset term is included when appropriate. The spatial effects are jointly modeled, commonly as a mean-zero Gaussian field with a covariance structure that depends on locations and covariance parameters. Conditional on the latent effects and modeled covariates, responses are assumed to follow the specified response distribution and are typically conditionally independent across locations.

The coefficient of a covariate is interpreted on the link scale, conditional on the latent field and other terms. For example, in a logit model a coefficient is a conditional log-odds contrast per unit increase in the covariate, holding the other linear-predictor components fixed. It is not automatically a marginal effect after averaging over the random field. Nonlinearity of the link means these conditional and marginal interpretations need not coincide.

The key geometric question is whether the covariate vector has substantial projection onto spatial patterns that the field can represent. A smooth covariate may align with low-frequency spatial modes, for example. The field is random and has mean zero under its model, but its realized pattern in a particular data set can still align with a fixed covariate. A zero-mean assumption does not eliminate that finite-sample competition.

A Link-Scale Derivation of the Competition

The mechanism is easiest to see in a Gaussian identity-link special case. Let \(\boldsymbol{x}\) be a centered, single covariate and write the observed response vector as

$$ \boldsymbol{y}=\beta\boldsymbol{x}+\boldsymbol{u}+\boldsymbol{\varepsilon}, $$

where \(\boldsymbol{u}\) is the realized spatial field and \(\boldsymbol{\varepsilon}\) is residual noise. If the field is omitted and the response is regressed on \(\boldsymbol{x}\), the slope is

$$ \widehat{\beta}_{\text{omit}} =\frac{\boldsymbol{x}^{\mathsf T}\boldsymbol{y}}{\boldsymbol{x}^{\mathsf T}\boldsymbol{x}} =\beta+ \frac{\boldsymbol{x}^{\mathsf T}\boldsymbol{u}}{\boldsymbol{x}^{\mathsf T}\boldsymbol{x}}+ \frac{\boldsymbol{x}^{\mathsf T}\boldsymbol{\varepsilon}}{\boldsymbol{x}^{\mathsf T}\boldsymbol{x}}. $$

The middle term is the shift attributable to the realized field’s projection onto the covariate. If the model includes the field and its distribution is correctly specified, this expression is not the estimator from that full model. It shows instead why omitting a spatial pattern aligned with the covariate can change the estimated slope. In a GLMM, the same expression is not an exact formula for the fitted coefficient: fitting is nonlinear and integrates or conditions on latent effects. A local working-response approximation can nevertheless have a similar weighted projection structure, which is useful for understanding the source of competition.

Worked Example: A Spatial Trend Shifts an Omitted-Field Slope

Suppose six hypothetical locations have centered covariate values \(\boldsymbol{x}=(-2,-1,0,0,1,2)^\mathsf{T}\). On an identity link, let the true coefficient be \(\beta=0.5\), the realized spatial field be \(\boldsymbol{u}=0.4\boldsymbol{x}\), and the residuals be \(\boldsymbol{\varepsilon}=(0.1,-0.2,0.1,-0.1,0.2,-0.1)^\mathsf{T}\). These values are illustrative, not observations from a real study.

The residual contribution to the slope is zero because \( \boldsymbol{x}^{\mathsf T}\boldsymbol{\varepsilon}=(-2)(0.1)+(-1)(-0.2)+(1)(0.2)+(2)(-0.1)=0 \). Also, \( \boldsymbol{x}^{\mathsf T}\boldsymbol{x}=4+1+0+0+1+4=10 \), and \( \boldsymbol{x}^{\mathsf T}\boldsymbol{u}=0.4(10)=4 \). Thus the regression that omits the field has slope

$$ \widehat{\beta}_{\text{omit}} =0.5+\frac{4}{10}+\frac{0}{10} =0.9. $$

The \(0.9\) is the slope for a model that has assigned the aligned spatial trend to the covariate. In the data-generating decomposition, the fixed-effect coefficient is \(0.5\) and the field contributes the other \(0.4\) units of slope. This example isolates the mechanism; it does not assert that a fitted spatial GLMM will recover either component exactly from a finite sample.

What Alignment Looks Like in a Logistic GLMM

The same issue occurs with binary and count responses, although the response-scale relationship is nonlinear. Consider a hypothetical binary-outcome model with a logit link and linear predictor \( \eta_i=-1+0.6x_i+u_i \). The conditional event probability is \( \mu_i=1/(1+\exp(-\eta_i)) \). If the realized field follows a spatial trend that is also linear in the covariate, a model without the field can attribute some of that trend to the fixed coefficient.

Worked Example: Aligned Covariate and Field in a Logit Model

At four hypothetical locations, let \(x=(0,1,2,3)\) and let the realized spatial effects be \(u=(-0.6,-0.2,0.2,0.6)\). These field values equal \(0.4(x-1.5)\), so they are perfectly aligned with the increasing covariate in this small illustration. The conditional linear predictors under the stated model are:

$$ \begin{aligned} \eta_1&=-1+0.6(0)-0.6=-1.6,\\ \eta_2&=-1+0.6(1)-0.2=-0.6,\\ \eta_3&=-1+0.6(2)+0.2=0.4,\\ \eta_4&=-1+0.6(3)+0.6=1.4. \end{aligned} $$

Applying the inverse-logit gives conditional probabilities approximately \(0.1680,\ 0.3543,\ 0.5987,\) and \(0.8022\). Since \(u_i=0.4x_i-0.6\), the same four linear predictors can be written as \( \eta_i=-1.6+1.0x_i \). A model that omits the field therefore has a linear predictor with slope \(1.0\) for these values, rather than the fixed coefficient \(0.6\) in the full conditional model.

This algebra demonstrates how the pattern can be assigned to either component. Actual logistic regression estimates depend on the binary outcomes, their sampling variability, and the full likelihood; the displayed slope is not a guarantee about any particular fitted estimate. In particular, probabilities cannot be treated as if they were Gaussian responses and the identity-link formula applied exactly.

Checking for Spatial Confounding

Confounding is not diagnosed by a single universal test. The goal is to assess whether the fixed-effect design contains enough spatially distinct information to separate a covariate trend from plausible latent-field patterns. Checks should be performed for the scientific covariates of interest and in relation to the spatial structure actually used in the model.

  • Map the covariate. A smooth gradient or a few large regions with different values may overlap strongly with broad spatial modes. Mapping is descriptive, but it can reveal where the available contrast comes from.
  • Compare the covariate with plausible spatial patterns. For a specified spatial basis or covariance structure, examine projections or correlations between the covariate vector and spatial basis patterns. A large projection indicates geometric overlap; it is not by itself proof of a biased estimate.
  • Inspect support and within-area variation. If a covariate is nearly constant within broad regions, its effect may be estimated mostly from between-region contrasts, which are also where a smooth field can vary. More within-region variation can help distinguish the terms.
  • Assess sensitivity to defensible specifications. Compare the coefficient and its uncertainty under scientifically reasonable spatial and nonspatial specifications. A large change signals that interpretation depends on how spatial structure is allocated; it does not identify which specification is correct.
  • Check whether the model is trying to explain the same pattern twice. If a fixed spatial trend and a flexible latent field both describe broad-scale variation, inspect their fitted contributions and uncertainty rather than relying only on a good overall fit.

These checks are most informative when paired with knowledge of the sampling design. If all high-exposure locations are in one region and all low-exposure locations in another, no modeling adjustment can create local comparisons that the design did not observe. Sparse spatial coverage, few independent regions, and a narrow covariate range can make the separation especially fragile.

Worked Example: Quantifying Alignment by Projection

For six hypothetical sites, let the centered covariate be \( \boldsymbol{x}=(-2,-1,0,0,1,2)^\mathsf{T} \) and consider the spatial pattern \( \boldsymbol{u}=(0.8,0.4,-0.1,0.1,-0.4,-0.8)^\mathsf{T} \). The projection coefficient of this pattern onto the covariate is

$$ \frac{\boldsymbol{x}^{\mathsf T}\boldsymbol{u}} {\boldsymbol{x}^{\mathsf T}\boldsymbol{x}} =\frac{(-2)(0.8)+(-1)(0.4)+(1)(-0.4)+(2)(-0.8)}{10} =\frac{-4}{10}=-0.4. $$

The component aligned with the covariate is therefore \( -0.4\boldsymbol{x} \). Removing that projection leaves \( \boldsymbol{u}_{\perp}=\boldsymbol{u}-(-0.4\boldsymbol{x})=(0,0,-0.1,0.1,0,0)^\mathsf{T} \). Its inner product with the covariate is \( \boldsymbol{x}^{\mathsf T}\boldsymbol{u}_{\perp}=0 \), so this remaining component is orthogonal to the covariate in the ordinary Euclidean geometry.

The projection is a diagnostic calculation, not proof that the field truly equals the displayed vector. It illustrates how much of a candidate spatial pattern lies in the covariate direction. A different weighting, spatial basis, or covariance model can produce a different relevant geometry.

Modeling Responses and Their Trade-Offs

There is no universally best correction for spatial confounding. The right choice depends on whether the goal is prediction, a conditional association, or a particular causal or scientific estimand, as well as on the design and assumptions.

ApproachWhat it doesMain caution
Joint fixed-effect and spatial-field modelIncludes both covariates and a structured latent field in the same linear predictor.Can leave substantial uncertainty or dependence between their contributions when patterns overlap.
Nonspatial GLMMDoes not allocate residual variation to a spatial field.If residual spatial structure is important, the model may misrepresent dependence and assign spatial pattern to fixed effects.
Restrict or orthogonalize the spatial effectConstrains the field to be orthogonal to the fixed-effect design, under a chosen inner product or weighting.Changes the allowed field and reallocates aligned variation to fixed effects by construction; it does not establish that the resulting coefficient is uniquely correct.
Use a different spatial basis or explicit spatial trendRepresents broad-scale and local spatial variation with chosen components.Results depend on the basis, scale choices, and assumptions about which component should represent the covariate pattern.

A restricted spatial regression model can be useful when its constraint matches the inferential goal, but orthogonality is not a neutral technical fix. In a model constrained to have no component in the covariate space, the field cannot explain any variation in that direction. Consequently, the fixed-effect term must carry that component. A coefficient may become more stable or precise under the restriction, but that change can reflect the imposed allocation rather than new information in the data.

A joint model with an unconstrained field allows the data and specified field distribution to share the spatial pattern, typically representing uncertainty about that allocation. A nonspatial model makes a different assumption: spatially structured residual variation is not represented by a field. Neither comparison alone proves the scientific interpretation. Report sensitivity and explain the target of the coefficient instead of selecting a specification only because it yields a preferred estimate.

Common Mistake and Limitations

  • Wrong reasoning: “The spatial field has mean zero, so it cannot be correlated with the covariate, and spatial confounding is impossible.”
    Correction: Mean zero is a statement about the field distribution across realizations. In the realized data, the field can align with a fixed covariate. That alignment can affect how much information the data provide to separate their contributions.
  • Wrong reasoning: “A large covariate coefficient change after adding a spatial effect proves the nonspatial estimate was biased.”
    Correction: The change shows sensitivity to the model’s allocation of spatial pattern. Bias is defined relative to a target and a data-generating process; the change alone does not reveal which estimate is closer to that target.
  • Wrong reasoning: “Orthogonalizing the field removes confounding without changing the fixed-effect meaning.”
    Correction: The restriction changes the allowable spatial effects, assigning covariate-aligned variation to the fixed term by design. State this modeling choice and justify it for the intended interpretation.

Spatial confounding is distinct from the general question of whether covariance parameters can be estimated reliably; those issues can coexist but are not interchangeable. It is also limited by the available design: strong overlap cannot always be resolved by a more elaborate model. Estimates remain conditional on the link, response distribution, covariate specification, spatial covariance assumptions, and sampling support.

Key takeaway: Spatial confounding is competition on the linear-predictor scale. Examine the overlap between covariate patterns and plausible spatial fields, state whether coefficients are conditional or marginal, and treat specification sensitivity as evidence about interpretive uncertainty—not as an automatic verdict that one model is correct.

Check Your Understanding

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

  1. In a spatial GLMM, what does it mean for a fixed covariate to be aligned with a latent spatial field?
  2. For the identity-link model in the derivation, suppose \( \boldsymbol{x}^{\mathsf T}\boldsymbol{x}=8 \), \( \boldsymbol{x}^{\mathsf T}\boldsymbol{u}=2 \), and \( \boldsymbol{x}^{\mathsf T}\boldsymbol{\varepsilon}=0 \). How far does omitting the field shift the slope from \(\beta\)?
  3. Why does a mean-zero spatial field not rule out spatial confounding in a realized data set?
  4. What does orthogonalizing the spatial effect against the covariate accomplish, and what is its principal interpretive caution?
  5. If a covariate varies only between two broad regions, why might its effect be difficult to distinguish from a smooth spatial field?

Solutions. (1) The covariate pattern resembles spatial patterns allowed for the field, so both can explain similar linear-predictor variation. (2) The shift is \(2/8=0.25\), so the omitted-field slope is \(\beta+0.25\) under the stated identity-link decomposition. (3) Mean zero describes the field’s distribution over realizations, not its projection onto a fixed covariate in one realization. (4) It forbids the field from explaining variation in the covariate direction; therefore the fixed term must carry that component, and the restriction changes the model rather than supplying new identifying information. (5) The available contrast is primarily a broad between-region difference, which a smooth spatial field can also represent; the design provides little within-region information to separate the two explanations.

Clinical Biostats