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. Link to Data File: https://sites.google.com/a/burkeyacad... Link to Playlist of all Spatial Videos:    • Spatial Econometrics (NEW 2017-2018)   My Website: http://www.burkeyacademy.com/ Support me on Patreon!   / burkeyacademy   Buy me a cup of coffee on PayPal? http://paypal.me/BurkeyAcademy Talk to me on my SubReddit:   / burkeyacademy   Link to download R: https://cloud.r-project.org/ Link to Download RStudio: https://www.rstudio.com/products/rstu... Here are the commands we used: library(spdep) library(rgdal) NCVACO = readOGR(dsn = ".", layer = "NCVACO") queen.nb=read.gal("queen.gal", region.id=NCVACO$FIPS) summary(queen.nb) queen.R.nb=poly2nb(NCVACO, row.names=NCVACO$FIPS) #Rook would be rook.R.nb=poly2nb(NCVACO,queen=FALSE) summary(queen.R.nb) isTRUE(all.equal(queen.nb,queen.R.nb,check.attributes=FALSE)) #moran(variable, listw, no. regions, sum of weights) moran(NCVACO$SALESPC,nb2listw(queen.nb), length(NCVACO$SALESPC), Szero(nb2listw(queen.nb))) moran.test(NCVACO$SALESPC,nb2listw(queen.nb))