kNearestNeighbors {spatialprobit}R Documentation

Build Spatial Weight Matrix from k Nearest Neighbors

Description

Build a spatial weight matrix W using the k nearest neighbors of (x, y) coordinates

Usage

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 \times 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.

Value

The method returns a sparse spatial weight matrix W with dimension (n \times n) and k non-zero entries per row which represent the k nearest neighbors.

Author(s)

Stefan Wilhelm <wilhelm@financial.com>

See Also

nb2listw and knearneigh for computation of neighbors lists, spatial weights and standardisation.

Examples

require(Matrix)
# build spatial weight matrix W from random (x,y) coordinates
W <- kNearestNeighbors(x=rnorm(100), y=rnorm(100), k=6)
image(W, main="spatial weight matrix W")

[Package spatialprobit version 1.0.4 Index]