Spatial Regression
Regression does not become spatial merely because rows contain coordinates. A spatial model must say where dependence enters: observed covariates, a latent field, the outcome, the error process, varying coefficients, or the sampling design.
Prerequisites
Complete spatial interpolation, spatial autocorrelation, and the site's regression foundations. You should recognize that diagnostics are conditional on a selected weight matrix.
Learning goals
- Fit a transparent baseline and test whether residual structure remains.
- Distinguish spatial-lag, spatial-error, and spatially varying relationships.
- Explain simultaneity and identification concerns in models containing .
- Keep association, prediction, and causal claims separate.
Begin with the data-generating question
An ordinary linear baseline is . A spatial-error model represents dependence in the disturbance, for example . A spatial-lag outcome model includes , making outcomes jointly determined under the specified . A spatially lagged covariate instead represents neighboring exposures. These terms are not interchangeable, and coefficients can have direct, indirect, or scale-dependent interpretations.
The example uses a lattice, rook weights, a covariate equal to column position, and a row-structured omitted process. The outer boundary has fewer neighbors. OLS recovers the constructed slope, but its residuals retain positive Moran dependence. That flags model inadequacy or dependence for further investigation; it does not select a unique remedy.
Worked example
import numpy as np
cells = np.array([(row, column) for row in range(4) for column in range(4)], dtype=float)
x = cells[:, 1]
omitted_spatial_process = np.repeat(np.array([-2, -1, 1, 2], dtype=float), 4)
y = 5 + 2 * x + omitted_spatial_process
design = np.column_stack([np.ones(len(x)), x])
coefficients = np.linalg.lstsq(design, y, rcond=None)[0]
residuals = y - design @ coefficients
weights = np.array([
[int(abs(row - other_row) + abs(column - other_column) == 1)
for other_row, other_column in cells]
for row, column in cells
], dtype=float)
centered = residuals - residuals.mean()
residual_i = len(y) / weights.sum() * (weights * np.outer(centered, centered)).sum() / (centered @ centered)
print(f"observations={len(y)} design_rank={np.linalg.matrix_rank(design)} weights=rook_binary")
print(f"ols_intercept={coefficients[0]:.2f} ols_slope={coefficients[1]:.2f} residual_rmse={np.sqrt(np.mean(residuals ** 2)):.3f}")
print(f"residual_moran_i={residual_i:.3f} interpretation=diagnostic causal_claim=False")
Expected output:
observations=16 design_rank=2 weights=rook_binary
ols_intercept=5.00 ols_slope=2.00 residual_rmse=1.581
residual_moran_i=0.700 interpretation=diagnostic causal_claim=False
The coefficient is exactly known because the omitted field is orthogonal to the column covariate in this constructed design. Real omitted spatial processes can bias coefficients as well as standard errors.
Inference, prediction, and causality
For descriptive inference, report the sampling frame, functional form, weight construction, residual diagnostics, and uncertainty estimator. For prediction, validate at the distance and geography of intended use. For causal interpretation, a spatial coefficient still needs a defensible intervention, assignment mechanism, interference assumptions, exposure mapping, confounding strategy, and identification argument. Adding coordinates, fixed effects, or a spatial lag does not automatically remove confounding.
Limitations and common mistakes
- Choosing to maximize significance turns a scientific assumption into outcome-driven tuning.
- OLS standard errors can be wrong under dependent or heteroskedastic residuals even when coefficients appear stable.
- A lagged outcome is endogenous in common simultaneous autoregressive formulations; plain OLS is generally not the estimator.
- Residual Moran tests can have low power, depend on scale, and do not reveal the omitted mechanism.
- Areal coefficients can change with zoning and must not be read as individual effects.
Practice
Draw a directed acyclic graph for a proposed neighboring-outcome effect. Identify whether is an exposure, a simultaneous outcome, or a proxy for an omitted field. State what data and assumptions would distinguish those cases.
Next steps
Next, evaluate geographic generalization directly in spatial cross-validation and leakage.
Primary sources
Checked 2026-10-18: L. Anselin, Spatial Econometrics: Methods and Models; L. Anselin, Thirty Years of Spatial Econometrics; PySAL spreg, spatial regression model reference; P. A. P. Moran, original spatial-dependence note.