##
# 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