The spatial weights matrix formalises "neighbour" for a spatial model: \(w_{ij}\) is non-zero when \(j\) is a neighbour of \(i\) and zero otherwise. Everything downstream — the spatial lag \(Wy\), Moran's I, a spatial autoregressive model — is defined relative to this choice, which is why the choice is an assumption rather than an estimate.
Arguments
- coords
Numeric matrix of \((n, d)\) coordinates, one row per unit. A plain vector is read as \(n\) points on a line.
- method
One of
"distance","knn","inverse".- k_or_threshold
Distance band for
"distance"and"inverse", or the number of neighbours \(k\) for"knn".- alpha
Distance decay exponent for
"inverse". Default 1.- row_standardize
Divide each non-empty row by its sum. Default
TRUE.
Value
Named list with weights, n, scheme,
row_standardized, n_links, n_islands,
pct_nonzero, method.
Details
Three coordinate-based schemes are offered.
"distance"Distance band: \(w_{ij} = 1\) when \(0 < d_{ij} \le\)
k_or_threshold, else 0. A unit with no neighbour inside the band keeps an all-zero row."knn"k nearest neighbours: \(w_{ij} = 1\) for the
k_or_thresholdunits nearest to \(i\). This relation is not symmetric."inverse"Inverse distance: \(w_{ij} = d_{ij}^{-\alpha}\) for \(0 < d_{ij} \le\)
k_or_threshold, else 0. The threshold may beInf, which connects every pair.
Distances are Euclidean and the diagonal is always zero: a unit is not
its own neighbour. With row_standardize the rows that have at
least one neighbour are divided by their sum, so a spatial lag is a
weighted average of neighbours; all-zero rows are left alone.
Contiguity weights (rook, queen) are not constructed here. They need a lattice or polygon topology rather than points — two units are rook-contiguous when their boundaries share an edge, which a coordinate pair does not determine.
Mirrors morie.fn.wmtwgt on the Python side.
