if (requireNamespace("sf", quietly = TRUE)) {
if (requireNamespace("spdep", quietly = TRUE)) {
library(sf)
library(spdep)
data(properties)
summary(properties$prpsqm)
pr.nb.800 <- dnearneigh(properties, 0, 800)
pr.listw <- nb2listw(pr.nb.800)
moran.test(properties$prpsqm, pr.listw)
moran.plot(properties$prpsqm, pr.listw, xlab = "Price/m^2", ylab = "Lagged")
}
}
Run the code above in your browser using DataLab