16  Spatial Models

Settling In

Sit with someone you haven’t worked with yet

  • Could be your capstone partner

Introduce yourself

  • Name, pronounciation tips, pronouns
  • Macalester connections (e.g., majors/minors/concentrations, clubs, teams, events regularly attended)
  • How are you feeling about the semester?

Everything on the slides is in the online manual: https://bcheggeseth.github.io/452_fall_2025/

Learning Goals

  • Explain and connect CAR and SAR models to time series models
  • Explain and connect Spatial Mixed Effects models to longitudinal models
  • Implement spatial models in R

Warm up

Recap

Weighting Matrix: \(W\) is a \(n\times n\) matrix with values of \(w_{ij}\) between 0 and 1.

  • The values can reflect whether or not the \(i\) area is a neighbor of the \(j\) area (0: not neighbor, 1: neighbor)
  • The values can reflect the strength of the influence of \(i\) on \(j\) (> 0 if there is an influence).

16.1 Row Standardized

To account for differing number of neighbors, there are cases in which we row-standardized this 0-1 matrix such that the row sums equal 1.

Let’s calculate the total number of neighbors for each region \(i\) and call that \(w_{i.}\),

\[w_{i.} = \sum^n_{j=1}w_{ij}\]

Then, we replace the original values of a binary \(W\) with \(w_{ij}/w_{i.}\).

Conceptual Understanding

Let \(Y\) be the outcome vector and \(W\) be a weighting matrix.

Consider \(WY\). What does this mean?

  • If \(W\) are of binary type…
  • If \(W\) are row-standardized…

Spatial Models

General Approach

To account for deterministic relationships and spatial autocorrelation, we follow a series of steps:

  1. Account for deterministic factors: Fit a regression model to model the mean with OLS, \[Y_i = x_i^T\beta + \epsilon_i\] where \(i\) indexes a spatial region.

  2. Map and test the residuals for spatial autocorrelation with Moran’s I.

  3. If there is spatial autocorrelation as measured by Moran’s I, fit a spatial model to account for that lingering autocorrelation (probably due to unmeasured confounding variables).

Spatial AR Models

There are two common flavors of spatial autoregressive models:

  • Simultaneous Autoregressive Model (SAR)

Spatial Lag Model

\[\mathbf{Y} = \lambda \mathbf{W Y} + \mathbf{X}\boldsymbol \beta + \boldsymbol \epsilon,\quad\quad \boldsymbol\epsilon \sim N(0,\sigma^2I)\]

. . .



\[\mathbf{Y} = \lambda\cdot(\text{average outcome of neighbors}) + \mathbf{X}\boldsymbol \beta + \boldsymbol \epsilon,\quad\quad \boldsymbol\epsilon \sim N(0,\sigma^2I)\]

this can be rewritten as

\[(I-\lambda\mathbf{W})\mathbf{Y} = \mathbf{X}\boldsymbol \beta + \boldsymbol \epsilon,\quad\quad \boldsymbol\epsilon \sim N(0,\sigma^2I)\]

Note: This means that the interpretation of \(\beta\)’s are more complex.

. . .



Spatial Error Model

\[\mathbf{Y} = \mathbf{X}\boldsymbol \beta + \boldsymbol \epsilon,\quad\quad \text{ where } \boldsymbol \epsilon = \lambda \mathbf{W}\boldsymbol \epsilon + \boldsymbol u,\quad \boldsymbol u \sim N(0,\sigma^2I)\]

. . .



Assuming normal errors, this can be rewritten as

\[\mathbf{Y} \sim N(\mathbf{X}\boldsymbol\beta, \sigma^2[(I-\lambda \mathbf{W})^{T}(I-\lambda \mathbf{W})]^{-1})\]

where the matrix \(\mathbf{W}\) should be weighted so that the rows sum to 1 (style = 'W").

. . .



  • Conditional Autoregressive Model (CAR)

\[E(Y_i | Y_j, j\not= i) = x_i^T\beta + \sum^n_{j=1}c_{ij}(Y_j - x^T_j\beta)\]

\[Var(Y_i | Y_j, j\not= i) = \tau^2_i = \tau^2/w_{i.}\]

where \(w_{i.} = \sum^n_{j=1}w_{ij}\), \(c_{ij}\) is nonzero only if \(Y_j\in N_i\), where \(N_i\) is the neighborhood of \(Y_i\). \(c_{ij}\) is typically \(\lambda w_{ij}/w_{i.}\) (row-standardized).

. . .



Assuming normal errors, this can be rewritten as

\[\mathbf{Y} \sim N(\mathbf{X}\boldsymbol\beta, \sigma^2(I-\lambda \mathbf{W})^{-1})\]

Spatial Mixed Effects Models

A spatial mixed effects model is a generalization of the CAR model that includes both fixed effects and random effects. The fixed effects account for deterministic relationships, while the random effects capture spatial correlation.

\[\mathbf{Y} = \mathbf{X}\boldsymbol \beta +\mathbf{b} + \boldsymbol \epsilon,\quad\quad \mathbf{b}\sim N(0,G),\;\boldsymbol\epsilon \sim N(0,\sigma^2I)\]

where \(G\) can be assumed to be a covariance matrix based on an assumed spatial correlation structure such as the Matern correlation structure.

See https://mac-stat.github.io/CorrelatedDataNotes/07-spatial.html#spatial-models for more details and code examples.

Small Group Work

Head to Homework 8 and work with a partner.

Wrap-Up

Finishing the Activity

  • If you didn’t finish the activity, no problem! Be sure to complete the activity outside of class, review the solutions in the online manual, and ask any questions on Slack or in office hours.
  • Re-organize and review your notes to help deepen your understanding, solidify your learning, and make homework go more smoothly!

After Class

Before the next class, please do the following:

  • Take a look at the Schedule page to see how to prepare for the next class.