Spatial weights are mathematical structures used to represent spatial relationships. Many spatial analytics, such as spatial autocorrelation statistics and regionalization algorithms rely on spatial weights. Generally speaking, a spatial weight \(w_{i,j}\) expresses the notion of a geographical relationship between locations \(i\) and \(j\). These relationships can be based on a number of criteria including contiguity, geospatial distance and general distances.
libpysal offers functionality for the construction, manipulation, analysis, and conversion of a wide array of spatial weights.
We begin with construction of weights from common spatial data formats.
There are functions to construct weights directly from a file path.
A commonly-used type of weight is a queen contigutiy weight, which reflects adjacency relationships as a binary indicator variable denoting whether or not a polygon shares an edge or a vertex with another polygon. These weights are symmetric, in that when polygon \(A\) neighbors polygon \(B\), both \(w_{AB} = 1\) and \(w_{BA} = 1\).
To construct queen weights from a shapefile, we will use geopandas to read the file into a GeoDataFrame, and then use libpysal to construct the weights:
All weights objects have a few traits that you can use to work with the weights object, as well as to get information about the weights object.
To get the neighbors & weights around an observation, use the observation’s index on the weights object, like a dictionary:
A full, dense matrix describing all of the pairwise relationships is constructed using the .full method, or when libpysal.weights.full is called on a weights object:
Note that this matrix is binary, in that its elements are either zero or one, since an observation is either a neighbor or it is not a neighbor.
However, many common use cases of spatial weights require that the matrix is row-standardized. This is done simply in PySAL using the .transform attribute
Now, if we build a new full matrix, its rows should sum to one:
Since weight matrices are typically very sparse, there is also a sparse weights matrix constructor:
<Compressed Sparse Row sparse matrix of dtype 'float64'
with 29374 stored elements and shape (4580, 4580)>
Let’s look at the neighborhoods of the 101th observation
dict_values([9, 9, 4, 7, 7, 5, 5, 6, 5, 8, 9, 8, 4, 3, 5, 5, 6, 6, 4, 5, 5, 6, 7, 9, 6, 4, 7, 8, 7, 5, 7, 2, 6, 6, 8, 3, 7, 7, 5, 8, 6, 5, 5, 4, 6, 6, 7, 7, 4, 6, 7, 4, 5, 6, 13, 6, 7, 6, 8, 6, 6, 6, 2, 6, 6, 8, 6, 7, 7, 6, 3, 5, 6, 6, 3, 7, 6, 5, 5, 5, 8, 8, 6, 8, 9, 7, 7, 6, 7, 5, 5, 7, 7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 5, 8, 6, 6, 6, 7, 7, 8, 5, 7, 6, 5, 8, 7, 9, 6, 5, 6, 8, 5, 7, 7, 7, 6, 7, 6, 8, 5, 7, 9, 8, 5, 7, 5, 8, 8, 9, 12, 7, 4, 7, 10, 8, 7, 7, 6, 6, 7, 6, 7])
Rook weights are another type of contiguity weight, but consider observations as neighboring only when they share an edge. The rook neighbors of an observation may be different than its queen neighbors, depending on how the observation and its nearby polygons are configured.
We can construct this in the same way as the queen weights:
In theory, a “Bishop” weighting scheme is one that arises when only polygons that share vertexes are considered to be neighboring. But, since Queen contiguigy requires either an edge or a vertex and Rook contiguity requires only shared edges, the following relationship is true:
\[ \mathcal{Q} = \mathcal{R} \cup \mathcal{B} \]
where \(\mathcal{Q}\) is the set of neighbor pairs via queen contiguity, \(\mathcal{R}\) is the set of neighbor pairs via Rook contiguity, and \(\mathcal{B}\) via Bishop contiguity.
\[ \mathcal{Q} \setminus \mathcal{R} = \mathcal{B}\]
Bishop weights entail all Queen neighbor pairs that are not also Rook neighbors.
PySAL does not have a dedicated bishop weights constructor, but you can construct very easily using the w_difference function. This function is one of a family of tools to work with weights, all defined in libpysal.weights, that conduct these types of set operations between weight objects.
[(np.int64(0), np.int64(1624)),
(np.int64(1), np.int64(1728)),
(np.int64(2), np.int64(881)),
(np.int64(3), np.int64(292)),
(np.int64(4), np.int64(55))]
Thus, many tracts have no bishop neighbors. But, a few do.
There are many other kinds of weighting functions in PySAL. Another separate type use a continuous measure of distance to define neighborhoods.
<Projected CRS: EPSG:26911>
Name: NAD83 / UTM zone 11N
Axis Info [cartesian]:
- E[east]: Easting (metre)
- N[north]: Northing (metre)
Area of Use:
- name: North America - between 120°W and 114°W - onshore and offshore. Canada - Alberta; British Columbia; Northwest Territories; Nunavut. United States (USA) - California; Idaho; Nevada, Oregon; Washington.
- bounds: (-120.0, 30.88, -114.0, 83.5)
Coordinate Operation:
- name: UTM zone 11N
- method: Transverse Mercator
Datum: North American Datum 1983
- Ellipsoid: GRS 1980
- Prime Meridian: Greenwich
Our coordinate system (UTM 11N) measures distance in meters, so that’s how we’ll define our neighbors
[np.int64(501),
np.int64(2296),
np.int64(2960),
np.int64(974),
np.int64(167),
np.int64(4496),
np.int64(2295),
np.int64(4422)]
[np.int64(501),
np.int64(2960),
np.int64(2296),
np.int64(974),
np.int64(167),
np.int64(4496),
np.int64(2881),
np.int64(2297)]
Kernel Weights are continuous distance-based weights that use kernel densities to define the neighbor relationship. Typically, they estimate a bandwidth, which is a parameter governing how far out observations should be considered neighboring. Then, using this bandwidth, they evaluate a continuous kernel function to provide a weight between 0 and 1.
Many different choices of kernel functions are supported, and bandwidths can either be fixed (constant over all units) or adaptive in function of unit density.
For example, if we want to use adaptive bandwidths for the map and weight according to a gaussian kernel:
bandwidth = the distance to the kth nearest neighbor for each observation
bandwith is changing across observations
| geoid | n_asian_under_15 | n_black_under_15 | n_hispanic_under_15 | n_native_under_15 | n_white_under_15 | n_persons_under_18 | n_asian_over_60 | n_black_over_60 | n_hispanic_over_60 | ... | year | n_total_housing_units_sample | p_nonhisp_white_persons | p_white_over_60 | p_black_over_60 | p_hispanic_over_60 | p_native_over_60 | p_asian_over_60 | p_disabled | geometry | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| quad | |||||||||||||||||||||
| 1 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 0 | 0 | 0 | ... | 15 | 15 | 15 | 0 | 0 | 0 | 0 | 0 | 0 | 15 |
| 2 | 761 | 761 | 761 | 761 | 761 | 761 | 761 | 0 | 0 | 0 | ... | 761 | 761 | 755 | 0 | 0 | 0 | 0 | 0 | 0 | 761 |
| 3 | 3625 | 3625 | 3625 | 3625 | 3625 | 3625 | 3625 | 0 | 0 | 0 | ... | 3625 | 3625 | 3612 | 0 | 0 | 0 | 0 | 0 | 0 | 3625 |
| 4 | 179 | 179 | 179 | 179 | 179 | 179 | 179 | 0 | 0 | 0 | ... | 179 | 179 | 179 | 0 | 0 | 0 | 0 | 0 | 0 | 179 |
4 rows × 194 columns
