Back to Browse

R Spatial Data 1: Read in SHP File

30.8K views
Aug 1, 2017
21:16

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/burkeyacademy.com/spatial/home/files/R%20Spatial%201%20Data.zip Link to Playlist of all Spatial Videos: https://www.youtube.com/playlist?list=PLlnEW8MeJ4z6Du_cbY6o08KsU6hNDkt4k My Website: http://www.burkeyacademy.com/ Support me on Patreon! https://www.patreon.com/burkeyacademy Buy me a cup of coffee on PayPal? http://paypal.me/BurkeyAcademy Talk to me on my SubReddit: https://www.reddit.com/r/BurkeyAcademy/ Link to download R: https://cloud.r-project.org/ Link to Download RStudio: https://www.rstudio.com/products/rstudio/download/ 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))

Download

0 formats

No download links available.

R Spatial Data 1: Read in SHP File | NatokHD