Build Spatial Weight Matrix from k Nearest Neighbors
Build Spatial Weight Matrix from k Nearest Neighbors
Build a spatial weight matrix W using the k nearest neighbors of (x, y) coordinates
kNearestNeighbors(x, y, k =6)
Arguments
x: x coordinate
y: y coordinate
k: number of nearest neighbors
Details
Determine the k nearest neighbors for a set of n points represented by (x, y) coordinates and build a spatial weight matrix W (n x n). W will be a sparse matrix representation and row-standardised.
This method is a convenience method for quickly creating a spatial weights matrix based on planar coordinates. More ways to create W are available in knearneigh of package spdep.
Returns
The method returns a sparse spatial weight matrix W with dimension (n x n) and k non-zero entries per row which represent the k nearest neighbors.
See Also
nb2listw and knearneigh
for computation of neighbors lists, spatial weights and standardisation.