Spatial Filtering

Eigenvector spatial filtering (ESF) and its random-effects variant.

SpatialEconometrics.SpatialFiltering.ESFModel — Type
ESFModel

An eigenvector spatial filtering fit, returned by fit_esf.

Spatial structure is absorbed by adding selected eigenvectors of the doubly-centred weight matrix to the design as synthetic regressors, chosen stepwise. Because they are orthogonal to the intercept and to each other, the covariate coefficients stay interpretable as ordinary regression coefficients — the appeal of the method over a lag model.

Inspect the chosen basis with selected_eigenvectors.

Note

Selecting zero eigenvectors is a valid outcome, not a failure: it means the residuals were already free of spatial autocorrelation.

source
SpatialEconometrics.SpatialFiltering.REESFModel — Type
REESFModel

A random-effects eigenvector spatial filtering fit, returned by fit_re_esf.

Instead of selecting eigenvectors stepwise as fit_esf does, this keeps the whole screened pool and shrinks every coefficient towards zero, governed by one variance ratio theta = tau2/sigma2 estimated by profile REML. That avoids the model-selection variance stepwise search introduces.

Warning

The reported residual Moran coefficient is for the conditional residual and is supposed to be substantially negative — do not compare it against zero. Subtracting the fitted spatial term leaves the remainder in the orthogonal complement of the retained eigenvectors, which is itself negatively autocorrelated. Compare it against moran_reference, the closed-form expectation stored on the model.

source
SpatialEconometrics.SpatialFiltering.SpatialEigen — Type
SpatialEigen

A screened eigenvector basis for spatial filtering, as returned by spatial_eigenvectors.

Fields

  • values::Vector{T}: eigenvalues of Ω = M Wᵤ M, in descending order.
  • vectors::Matrix{T}: the corresponding eigenvectors, one per column. Columns are orthonormal and each sums to zero.
  • moran::Vector{T}: each eigenvector's Moran coefficient, (N/S₀)λᵢ.
  • S0::T: the sum of all weights, Σᵢⱼ wᵢⱼ.
  • N::Int: the number of spatial units.

Pass an instance as the eigen_basis keyword of fit_esf or fit_re_esf to reuse one decomposition across several fits.

source
SpatialEconometrics.SpatialFiltering.fit_esf — Function
fit_esf(X, y, W; family=:gaussian, max_eigenvectors=20, criterion=:moran, ...)

Eigenvector spatial filtering (Griffith, 2003). Selected eigenvectors of the doubly-centred W enter as extra regressors, absorbing the spatial autocorrelation so the remaining coefficients can be read as aspatial:

\[g(\mu) = \alpha + X\beta + E_{sel}\gamma\]

family is :gaussian (OLS), :poisson, :logit, or :negbin; the last three are fit by IRLS, with the negative binomial's dispersion updated by method of moments between IRLS passes (Chun et al., 2016). This makes ESF usable wherever a GLM is, which parametric SAR/SEM cannot match.

Eigenvectors are added greedily. criterion=:moran picks, at each step, the candidate that most reduces the absolute Moran coefficient of the residuals (Pearson residuals for GLM families); criterion=:aic picks the one that most reduces AIC. Selection stops at max_eigenvectors, when no candidate improves the criterion, or — under :moran — once |MC| falls below moran_tol.

min_moran_ratio screens the candidate pool to eigenvectors with MCᵢ/max(MC) ≥ ratio (default 0.25, the usual positive-SA screen). Pass a precomputed SpatialEigen as eigen_basis to reuse one decomposition across several fits.

Cost is O(max_eigenvectors × n_candidates) model fits, so keep the pool bounded for GLM families.

source
SpatialEconometrics.SpatialFiltering.fit_re_esf — Function
fit_re_esf(X, y, W; min_moran_ratio=0.25, n_candidates=nothing, varnames=nothing)

Random-effects eigenvector spatial filtering (Murakami & Griffith, 2015):

\[y = X\beta + E\gamma + \varepsilon, \quad \gamma \sim N(0, \tau^2\Lambda), \quad \varepsilon \sim N(0, \sigma^2 I)\]

Rather than selecting eigenvectors discretely, every positive-eigenvalue eigenvector is retained and its coefficient shrunk toward zero, with the shrinkage governed by the single variance ratio θ = τ²/σ² estimated by profile REML. This sidesteps the model-selection variance of stepwise ESF.

Because E has orthonormal columns, V = σ²(I + θEΛE') inverts in closed form — its eigenvalues are 1 + θλₗ inside span(E) and 1 outside — so each REML evaluation is O(NL), not O(N³). The decomposition itself is still O(N³).

Only positive-eigenvalue eigenvectors are used, the standard choice for positive spatial autocorrelation, and min_moran_ratio screens them further to MCᵢ/max(MC) ≥ ratio.

Reading the residual Moran coefficient

moran_final is the Moran coefficient of the conditional residual y - Xβ̂ - Eγ̂, and it is expected to be substantially negative — do not compare it against zero. Subtracting Eγ̂ removes the positively autocorrelated directions, leaving a residual that lives mostly in the orthogonal complement of span(E); a vector drawn at random from that complement has Moran coefficient

\[\frac{N}{S_0}\cdot\frac{-S_0/N - \sum_l \lambda_l}{N - 1 - L}\]

which is reported as moran_reference. On correctly specified data with N = 121 and L = 40 this reference is −0.304 and the fitted residual lands near −0.24, i.e. slightly less negative than chance. A moran_final close to or above moran_reference is the healthy case; one far below it suggests the random effects are absorbing noise, as does an edf (effective degrees of freedom, P + Σ θλ/(1+θλ)) approaching N.

source
SpatialEconometrics.SpatialFiltering.spatial_eigenvectors — Function
spatial_eigenvectors(W; n_candidates=nothing, min_moran_ratio=0.0)

Eigendecomposition of the doubly-centred weight matrix Ω = (I - 11'/N) Wsym (I - 11'/N), following Griffith (2003).

The eigenvectors are mutually orthogonal and uncorrelated, and each carries Moran coefficient MCᵢ = (N/S₀)λᵢ. Eigenvectors with large positive eigenvalues describe positive spatial autocorrelation patterns; large negative eigenvalues describe negative ones. Results are sorted by eigenvalue, descending.

An asymmetric W (e.g. row-standardised) is symmetrised as (W + W')/2 so the eigenvalues are real.

The constant vector is removed by construction rather than by discarding an eigenvector afterwards: with Q an orthonormal basis of 1's orthogonal complement, Q'ΩQ = Q'WsymQ, so eigendecomposing the reduced (N-1)×(N-1) matrix and mapping back as E = QV yields vectors that are orthonormal and exactly mean-zero. Decomposing Ω directly would not: its null space is multi-dimensional, the solver may return any rotation within it, and the constant direction then smears across several near-zero eigenvectors that are each partly collinear with the intercept.

n_candidates keeps only the leading eigenvectors; min_moran_ratio keeps those with MCᵢ / max(MC) ≥ ratio, the usual screen for positive-SA filtering (0.25 is a common choice). Both are applied after sorting.

Dense eigen is O(N³) — intended for moderate N.

source