R Spatial Data 1: Read in SHP File
Here we use R and RStudio to read in a spatial data file (as a SHP file), read in a contiguity (GAL) file created in GeoDa, create the same queen contiguity matrix in R and check that the two are the same, and compute a Moran’s I.
Here are the commands we used:
NCVACO = readOGR(dsn = “.”, layer = “NCVACO”)
#Rook would be rook.R.nb=poly2nb(NCVACO,queen=FALSE)
#moran(variable, listw, no. regions, sum of weights)
moran(NCVACO$SALESPC,nb2listw(queen.nb), length(NCVACO$SALESPC), Szero(nb2listw(queen.nb)))