require(spdep)
data(boston)
if (require("spData", quietly=TRUE)) {
########## Rook adjacency-based W
poly <- st_read(system.file("shapes/boston_tracts.gpkg", package="spData")[1])
weig1 <- weigen( poly )
########## knn-based W
coords <- boston.c[,c("LON", "LAT")]
weig2 <- weigen( coords, type = "knn" )
########## Delaunay triangulation-based W
coords <- boston.c[,c("LON", "LAT")]
weig3 <- weigen( coords, type = "tri")
########## User-specified W
dmat <- as.matrix(dist(coords))
cmat <- exp(-dmat)
diag(cmat)<- 0
weig4 <- weigen( cmat, threshold = 0 )
}
Run the code above in your browser using DataLab