Tutorials › Generalized Linear Mixed Models (GLMM) › Spatial Covariance in Binary and Count GLMMs

Spatial and Temporal Correlation · Tutorial 587 of 698

Spatial Covariance in Binary and Count GLMMs

You will formulate spatial binary and count GLMMs and derive how their latent Gaussian covariance affects marginal outcome dependence.

Advanced 12 min read

What You'll Learn

  • Specify Bernoulli-logit and Poisson-log models with a Gaussian spatial field.
  • Distinguish conditional independence from marginal dependence.
  • Derive the covariance between outcomes using the law of total covariance.
  • Calculate exact marginal moments for Poisson outcomes with a Gaussian log field.
  • Use a delta-method approximation to interpret dependence in binary-logit outcomes.
  • Identify assumptions, diagnostic warnings, and limitations of spatial latent effects.

Why Put Spatial Dependence in a GLMM?

Binary and count outcomes are often observed at several locations. After accounting for measured predictors, nearby locations may still have related outcomes. A generalized linear mixed model can represent this pattern by adding a spatial Gaussian field to the linear predictor. The field is latent: it is not an extra observed response, but a location-specific random contribution whose covariance describes how those contributions vary together.

The key distinction is between conditional independence and marginal dependence. The outcome observations can be independent once the spatial field is known, yet dependent when that unobserved field is integrated out. This tutorial develops that distinction for Bernoulli-logit and Poisson-log models. The covariance function or matrix used for the field must be valid, as established in the earlier material on spatial covariance structures.

Definition: At locations \(s_1,\ldots,s_n\), let \(\mathbf{U}=(U(s_1),\ldots,U(s_n))^\mathsf{T}\) be a mean-zero Gaussian spatial effect with covariance matrix \(\boldsymbol{\Sigma}\), where \(\Sigma_{ij}=C(s_i,s_j)\). A spatial GLMM places \(U(s_i)\) in the linear predictor for the response at location \(s_i\). Conditional on the full field \(\mathbf{U}\) and the model parameters, responses at distinct locations are assumed independent.

Bernoulli-Logit and Poisson-Log Specifications

For a binary response \(Y_i\), the Bernoulli-logit model is

$$ Y_i\mid \mathbf{U}\sim\operatorname{Bernoulli}(q_i),\qquad \operatorname{logit}(q_i)=\log\left(\frac{q_i}{1-q_i}\right) =\mathbf{x}_i^\mathsf{T}\boldsymbol{\beta}+U(s_i). $$

Here \(\mathbf{x}_i\) is the predictor vector and \(\boldsymbol{\beta}\) is the fixed-effect coefficient vector. For a count response, the Poisson-log specification is

$$ Y_i\mid \mathbf{U}\sim\operatorname{Poisson}(\lambda_i),\qquad \log(\lambda_i)=\mathbf{x}_i^\mathsf{T}\boldsymbol{\beta}+U(s_i)+\log(e_i), $$

where \(e_i\) is a known positive exposure, if exposure is required; its logarithm is an offset. When there is no exposure offset, take \(e_i=1\). Conditional on the field, a Bernoulli response has mean \(q_i\) and variance \(q_i(1-q_i)\); a Poisson response has mean and variance \(\lambda_i\).

These specifications assume the chosen conditional response distribution and link are appropriate, the predictor and offset are correctly specified, and the spatial covariance matrix is positive semidefinite. They also assume conditional independence across locations given the field. Conditional independence does not assert that the responses are independent marginally.

How Latent Covariance Becomes Outcome Dependence

Let \(m_i(\mathbf{U})=E(Y_i\mid\mathbf{U})\). The law of total covariance gives

$$ \operatorname{Cov}(Y_i,Y_j) =E\!\left[\operatorname{Cov}(Y_i,Y_j\mid\mathbf{U})\right] +\operatorname{Cov}\!\left(E(Y_i\mid\mathbf{U}),E(Y_j\mid\mathbf{U})\right). $$

For distinct locations, conditional independence makes the first term zero. Therefore

$$ \operatorname{Cov}(Y_i,Y_j)=\operatorname{Cov}\{m_i(\mathbf{U}),m_j(\mathbf{U})\},\qquad i\ne j. $$

Thus the latent covariance affects responses through the covariance of their conditional means. This identity is the central justification for interpreting a spatial field as a source of residual outcome dependence.

Result: In the Poisson-log model, write \(\eta_i=\mathbf{x}_i^\mathsf{T}\boldsymbol{\beta}+\log(e_i)\), so \(\lambda_i=\exp\{\eta_i+U(s_i)\}\). If \(U(s_i)\) and \(U(s_j)\) are jointly Gaussian with mean zero and covariance \(C_{ij}\), then $$ E(Y_i)=\exp\left(\eta_i+\frac{\Sigma_{ii}}{2}\right),\qquad \operatorname{Cov}(Y_i,Y_j)=E(Y_i)E(Y_j)\{\exp(C_{ij})-1\},\quad i\ne j. $$

To see the covariance formula, conditional independence reduces it to \(\operatorname{Cov}(\lambda_i,\lambda_j)\). The moment-generating function of a jointly Gaussian pair gives \(E(\lambda_i\lambda_j)=\exp\{\eta_i+\eta_j+(\Sigma_{ii}+\Sigma_{jj}+2C_{ij})/2\}\). Subtracting \(E(\lambda_i)E(\lambda_j)\) yields the stated result. The marginal variance at a single location also includes both Poisson variation and field variation:

$$ \operatorname{Var}(Y_i) =E\{\operatorname{Var}(Y_i\mid\mathbf{U})\} +\operatorname{Var}\{E(Y_i\mid\mathbf{U})\} =E(Y_i)+E(Y_i)^2\{\exp(\Sigma_{ii})-1\}. $$

For Bernoulli-logit outcomes, the conditional mean is \(m_i(\mathbf{U})=\operatorname{logit}^{-1}(\mathbf{x}_i^\mathsf{T}\boldsymbol{\beta}+U(s_i))\). Integrating this logistic function over a Gaussian distribution generally has no closed-form expression. For a small field variance, a first-order Taylor approximation around the fixed predictor gives

$$ \operatorname{Cov}(Y_i,Y_j) \ \approx\ q_i^0(1-q_i^0)\,q_j^0(1-q_j^0)\,C_{ij}, \qquad q_i^0=\operatorname{logit}^{-1}(\mathbf{x}_i^\mathsf{T}\boldsymbol{\beta}). $$

This approximation is useful for interpretation, not a replacement for integrating the fitted model. Because the inverse-logit is increasing, a bivariate Gaussian field with positive covariance induces nonnegative covariance between these conditional means; negative latent covariance induces nonpositive covariance. The magnitude on the response scale depends on the predictor values as well as on \(C_{ij}\).

Worked Example: Approximate Dependence Between Two Binary Outcomes

Suppose two hypothetical locations have fixed linear predictors equal to zero. Their spatial effects each have variance \(0.04\) and correlation \(0.5\). The covariance is therefore \(C_{12}=0.5\sqrt{0.04(0.04)}=0.02\). Use the first-order approximation to assess the response covariance.

At either location, the fixed-predictor probability is \(q_i^0=\operatorname{logit}^{-1}(0)=0.5\), so the derivative of the inverse-logit is \(q_i^0(1-q_i^0)=0.5(0.5)=0.25\). Hence

$$ \operatorname{Cov}(Y_1,Y_2)\approx(0.25)(0.25)(0.02)=0.00125. $$

The marginal success probability at each site is exactly \(0.5\): the field is symmetric about zero, and \(\operatorname{logit}^{-1}(u)+\operatorname{logit}^{-1}(-u)=1\). Each binary outcome therefore has marginal variance \(0.5(1-0.5)=0.25\). The approximate marginal correlation is \(0.00125/\sqrt{0.25(0.25)}=0.005\). This is a small positive dependence, not conditional dependence: given the field, the two outcomes remain independent. The covariance approximation is first order in the small field variance, not an exact integration result.

Worked Example: Exact Poisson Outcome Covariance

Consider two hypothetical count observations with unit exposure and the same fixed predictor \(\eta=\log(2)-0.125\). Each spatial effect has variance \(0.25\), and their correlation is \(0.6\). Thus \(C_{12}=0.6(0.25)=0.15\). Calculate their marginal means and covariance.

For each location, the marginal mean is

$$ E(Y_i)=\exp\left\{\log(2)-0.125+\frac{0.25}{2}\right\} =\exp\{\log(2)\}=2. $$

The covariance is

$$ \operatorname{Cov}(Y_1,Y_2) =(2)(2)\{\exp(0.15)-1\} =4(1.1618-1) \approx 0.6473. $$

For context, the marginal variance at either location is \(2+2^2\{\exp(0.25)-1\}\approx2+4(0.2840)=3.136\). The marginal correlation is therefore \(0.6473/3.136\approx0.2064\). The spatial effect creates positive dependence even though the counts are independent conditional on that effect.

Worked Example: Same Marginal Means, Different Spatial Covariance

Suppose two hypothetical Poisson observations have marginal means of \(1.5\), and their latent-effect covariance is \(0.05\). Their outcome covariance is

$$ (1.5)^2\{\exp(0.05)-1\} =2.25(0.05127)\approx0.1154. $$

For a second pair with the same marginal means but latent covariance \(0.15\), the outcome covariance is

$$ (1.5)^2\{\exp(0.15)-1\} =2.25(0.1618)\approx0.3641. $$

The expected counts are unchanged, but the second pair has greater residual covariance because the latent effects covary more strongly. This comparison assumes that both covariance values belong to a valid spatial covariance matrix and that the conditional Poisson model is adequate.

Interpreting and Checking a Spatial GLMM

A coefficient in \(\boldsymbol{\beta}\) describes the conditional linear predictor with the spatial effect held fixed. For example, a Poisson-log coefficient \(\beta_k\) corresponds to a conditional rate ratio of \(\exp(\beta_k)\) for a one-unit increase in predictor \(k\), holding other predictors and the field fixed. It is not generally a marginal effect after averaging over the field. Likewise, the Bernoulli-logit coefficient is conditional on the field; the nonlinear inverse link means that marginal probabilities need not follow the same simple coefficient interpretation.

Useful checks focus on whether the model's assumptions and spatial structure are plausible. Examine residual patterns over locations, compare observed and model-implied marginal variation, and check whether remaining spatial pattern persists after fitting. A spatial field that is too smooth may leave localized residual structure; a field that is too flexible may absorb broad fixed-effect patterns. If a spatial predictor changes gradually across the region, its effect can be difficult to distinguish from a similarly smooth latent field. This is a limitation of the data and model structure, not proof that either component is absent.

The assumptions can fail in several ways. Excess zeros or count variation beyond that implied by the Poisson mixture may remain; a Gaussian log field does not automatically solve every form of count overdispersion. Binary outcomes may show residual dependence not captured by the selected covariance. Incorrect locations, an unsuitable covariance structure, or an invalid covariance matrix undermine the intended interpretation. Conditional independence is also a substantive assumption: repeated measurements or other shared causes may require additional structure rather than being attributed entirely to spatial covariance.

The main alternatives answer different questions. An ordinary GLM assumes no latent spatial dependence after accounting for predictors, so it is inadequate when spatial clustering remains. A single shared random intercept can induce dependence, but it does not generally represent covariance that changes with the spatial relationship between locations. Conditional autoregressive models use adjacency-based structure, while Gaussian spatial fields can use covariance based on locations; the appropriate choice depends on the spatial support and scientific design. These approaches should be compared as alternative dependence structures, not treated as interchangeable.

1
Specify the response model.
Choose Bernoulli-logit or Poisson-log, include relevant predictors and any known exposure offset, and state the conditional response distribution.
2
Specify the field.
Define the Gaussian vector over observed locations and use a valid covariance matrix consistent with the intended spatial structure.
3
State conditional independence.
Make clear that responses are independent given the field and parameters; marginal dependence is induced by integrating over the shared field.
4
Interpret and diagnose.
Separate conditional coefficients from marginal outcomes, then check residual spatial pattern, dispersion, and possible confounding between predictors and the field.

Common Pitfall

A common mistake is to say that a spatial GLMM makes observations independent because the model assumes conditional independence. That omits the conditioning. The correct statement is: outcomes are independent given the field, while generally dependent marginally. Another mistake is to read a latent covariance as though it were the response covariance. For Poisson-log outcomes the exact response covariance is \(E(Y_i)E(Y_j)\{\exp(C_{ij})-1\}\), not \(C_{ij}\) itself; for Bernoulli-logit outcomes the relationship is nonlinear and usually requires integration or approximation.

Key takeaway: A spatial Gaussian field enters the conditional linear predictor, and its covariance induces marginal dependence through the conditional means. The response family and link determine how that latent covariance translates to the outcome scale.

Check Your Understanding

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

  1. For distinct locations, what term in the law of total covariance remains when responses are conditionally independent given the field?
  2. In a Poisson-log model with marginal means \(1\) and \(3\), and latent covariance \(C_{12}=0.1\), calculate the outcome covariance.
  3. Why is the first-order binary-logit covariance approximation not an exact formula in general?
  4. Does a positive spatial covariance imply that outcomes are dependent conditional on the field?

Solutions. (1) The remaining term is \(\operatorname{Cov}\{E(Y_i\mid\mathbf{U}),E(Y_j\mid\mathbf{U})\}\). (2) The covariance is \((1)(3)\{\exp(0.1)-1\}=3(0.1052)\approx0.3155\). (3) The inverse-logit of a Gaussian variable generally has no closed-form expectation, and the delta-method expression omits higher-order terms. (4) No. Conditional independence is assumed; positive latent covariance induces marginal, not conditional, dependence.

Clinical Biostats