Creating County level Adjacency Matrix for different states

Viewed 175

I'm attempting to create an adjacency matrix for counties in AL, SC, and GA and I tried one approach which seemed to work well. I used the following libraries and code to generate the adjacency matrix (Adj_mat).

library(tidyverse)
library(spdep)
library(urbnmapr)

counties_sf <- get_urbn_map("counties", sf = TRUE)

counties_south <- filter(counties_sf, state_abbv %in% c("AL", "GA", "SC" ))

south_counties_polylist <- poly2nb(counties_south)

Adj_mat <- nb2mat(south_counties_polylist, style = "B", zero.policy = T)           # Adjacency matrix

The total adjacencies for this matrix are 1526 as obtained by m1 <- apply(Adj_mat, 2, sum).

This was a bit concerning since I have another adjacency matrix for AL, GA, and SC that I have been using for a while now and has 1528 total adjacencies. I don't have the code that was used to create this matrix and I'm a bit unsure if my approach was wrong or the existing adjacency matrix that I have been using is not correct.

Based on the package description, urbnmapr library uses shapefiles from the US Census Bureau. I would like to be able to create matrices for different states on my own and would appreciate any pointers to ensure I'm doing it correctly. Thank you!

0 Answers
Related