I need some help to finalize code for a spatial weight matrix that uses a nearest neighbor definition within regions, but does not allow neighbors from across a political border. For example, physically adjacent counties are neighbors, but physically adjacent counties separated by a state boundary are not neighbors.
I am working with an ESRI shapefile, with about 40,000 polygons.
The nearest neighbor bit is straightforward using functions from spdep. And I have collected a code example that creates a boundary effect:
# xxx is the name of the shape fileunique(xxx$country)length(unique(xxx$countrycode))# B_domestic = Indicator function taking value 1 if two regions belong to same country and 0 if notB_domestic
I am working with an ESRI shapefile, with about 40,000 polygons.
The nearest neighbor bit is straightforward using functions from spdep. And I have collected a code example that creates a boundary effect:
# xxx is the name of the shape fileunique(xxx$country)length(unique(xxx$countrycode))# B_domestic = Indicator function taking value 1 if two regions belong to same country and 0 if notB_domestic