Learn R Programming

GeoXp (version 1.6.2)

makeneighborsw: Spatial weight matrix

Description

The function makeneighborsw() create a spatial weight matrix based on a given number of nearest neighbors (option "neighbor" by default), based on a threshold distance (option method="distance") or both these 2 methods.

Usage

makeneighborsw(coords,method="neighbor",m=1,d,cum=TRUE)

Arguments

coords
a matrix of spatial coordinates
method
"neighbor" by default, "distance" or "both"
m
number of nearest neighbors
d
threshold point
cum
if cum=TRUE, W is the sum of spatial weight matrix based on k nearest neighbours (for $k < m$; if FALSE W is the spatial weight matrix based only on $m^th$ nearest neighbours

Value

A spatial weight matrix of size $n x n$

Details

In the case of method="neighbor", for each site, we order the other sites by their distance from this site. If cum=TRUE, for i, if j is among the $m^th$ nearest sites, then : $$W_{ij}=1$$ else $$W_{ij}=0$$ If cum=FALSE, for $$s_i$$, if $$s_j$$ is the $m^th$ nearest site, then : $$W_{ij}=1$$ else $$W_{ij}=0$$ In case of ties, the nearest neighbour is randomly chosen. In the case of method="distance", if site i is seperated from j by a distance lower or equal to a given threshold : $$W_{ij}=1$$ else $$W_{ij}=0$$ In the case of method="both" W must verify the two first conditions.

References

Thibault Laurent, Anne Ruiz-Gazen, Christine Thomas-Agnan (2012), GeoXp: An R Package for Exploratory Spatial Data Analysis. Journal of Statistical Software, 47(2), 1-23.

Roger S.Bivand, Edzer J.Pebesma, Virgilio Gomez-Rubio (2009), Applied Spatial Data Analysis with R, Springer.

See Also

moranplotmap,normw

Examples

Run this code
##
# data auckland
data(auckland)
coords <- cbind(auckland$Easting[1:10],auckland$Northing[1:10])

# matrix based on 5 nearest neighbors
W<-makeneighborsw(coords,method="neighbor",m=3)

# matrix based on a threshold distance
W1<-makeneighborsw(coords,method="distance",d=20)

# matrix based on the two methods
W2<-makeneighborsw(coords,method="both",m=3,d=20)

# representation of the 3 spatial weight matrices
op<-par(mfrow=c(2,2))
plot(mat2listw(W),coords,col="lightblue1",main="neighbor")
plot(mat2listw(W1),coords,col="lightblue2",main="distance")
plot(mat2listw(W2),coords,col="lightblue3",main="both")
par(op)

Run the code above in your browser using DataLab