Weight Matrices

Constructing, standardizing, inspecting and reading weight matrices.

SpatialEconometrics.SpatialWeights.SpatialConnectivity — Type
SpatialConnectivity

Summary of a weight matrix's structure, returned by spatial_connectivity. Worth looking at before fitting anything.

Fields

  • N, n_nonzero, density: size and sparsity.
  • avg_neighbors, min_neighbors, max_neighbors: the degree distribution.
  • n_islands: units with no neighbours at all.
  • is_symmetric: whether W == W'. Row-standardizing a symmetric contiguity matrix generally destroys symmetry, so false here is normal and not a problem.
  • spectral_radius: largest eigenvalue magnitude; 1 for a row-standardized matrix.
Warning

n_islands > 0 deserves attention. An isolated unit contributes nothing to the spatial likelihood and its row of W*y is zero, so it is effectively dropped from the spatial part of the model while still counting towards N.

source
SpatialEconometrics.SpatialWeights.distance_weights — Function
distance_weights(coords, cutoff; decay=:inverse, alpha=1.0, row_standardize=true)

Build distance-decay spatial weights. Pairs beyond cutoff get zero weight.

Decay functions:

  • :inverse — 1 / d^alpha
  • :negative_exponential — exp(-alpha * d)
  • :power — d^(-alpha) (same as inverse, explicit name)
  • :bisquare — (1 - (d/cutoff)^2)^2
source
SpatialEconometrics.SpatialWeights.knn_weights — Function
knn_weights(coords, k; binary=false, row_standardize=true, symmetrize=false)

Build a spatial weight matrix from k-nearest neighbors. coords is N×D (rows = observations). Returns a sparse N×N matrix.

source
SpatialEconometrics.SpatialWeights.read_gal — Function
read_gal(path; ids=nothing) → (W, ids)

Read a GeoDa GAL contiguity weights file. Returns the row-standardized sparse weight matrix and the observation ID vector, where row i of W corresponds to ids[i].

The ordering comes from the file's observation records, in record order. Pass ids to impose an external table's ordering instead. A neighbour id with no observation record raises an error.

source
SpatialEconometrics.SpatialWeights.read_gwt — Function
read_gwt(path; ids=nothing) → (W, ids)

Read a GeoDa GWT (general weights) file. Returns the sparse weight matrix and the observation ID vector, where row i of W corresponds to ids[i].

A GWT file is only an edge list and carries no ordering of its own, so the ids found in it are sorted — numerically when they all parse as integers, else lexicographically. Pass ids to impose an external table's ordering instead.

source
SpatialEconometrics.SpatialWeights.row_standardize — Function
row_standardize(W) -> SparseMatrixCSC

Row-standardized copy of W: every row with at least one neighbour sums to 1. See row_standardize! for the in-place version.

This is the conventional normalization, and most of this package assumes it. It makes W*y a neighbourhood average, bounds the spatial parameter inside (-1, 1), and makes Moran's I equal the slope in a Moran scatter plot. Rows with no neighbours stay all-zero.

source
SpatialEconometrics.SpatialWeights.spectral_standardize — Function
spectral_standardize(W) -> SparseMatrixCSC

Copy of W divided by its spectral radius. See spectral_standardize! for the in-place version.

Bounds the spatial parameter in (-1, 1) as row-standardization does, but without rescaling rows relative to one another, so differences in connectedness between units are preserved. Preferable when the number of neighbours is itself meaningful; the cost is that W*y is no longer a simple neighbourhood average.

source