Creating a Region-Level Weights Matrix–updated!
At the recent ERSA Congress here in Vienna, I connected with Roger Bivand, the lead developer of the spdep package for R. He had a look at the solution I wrote up here and spotted an issue with it. There is an updated version of spdep, currently available for download on R-forge that includes a bug fix for the function nb2blocknb() that will create a proper region-level weights matrix. This fix does away with the roundabout method I had worked out.
Download this new version of spdep here:
spdep 06.07 on R-forge
My updated solution is here:
Download the shapefile to test drive it here: Metros
R-Studio and R are available for free download here:
[Original Post . . . .]
Recently, I spent some time (well, a lot of time) trying to work out a solution for a spatial weights matrix that didn’t quite fit with the usual cookbook approaches provided in software packages. The idea was to create a matrix that defined all the census tracts in a metropolitan region as neighbors of one another, while tracts that were geographically adjacent but in different metros would not be neighbors. This matrix could be used to lag variables (or the error term) in a spatial regression to estimate the effect of the value of a variable across a metro to account for within-metro spatial effects as opposed to between metro spatial effects. This is a more elaborated approach than including a simple dummy variable for each metro as it allows for actually estimating the effect of the lagged value, not just the overall effect of a location in a metro.
Most software packages provide ready solutions for spatial weights that are based on either contiguity (touching boundaries) or proximity (distance or the number of nearest neighbors). I’ve written out my solution to creating a metro-level weights matrix using R (an open source analysis software I am using for my analyses) along with a reproducible example.