Description Usage Arguments Details Value Author(s) References See Also Examples
The function generates a weights matrix for a neighbours list with spatial weights for the chosen coding scheme.
1 2 
neighbours 
an object of class 
glist 
list of general weights corresponding to neighbours 
style 

zero.policy 
default NULL, use global option value; if FALSE stop with error for any empty neighbour sets, if TRUE permit the weights list to be formed with zerolength weights vectors 
listw 
a 
Starting from a binary neighbours list, in which regions are either listed as neighbours or are absent (thus not in the set of neighbours for some definition), the function creates an n by n weights matrix with values given by the coding scheme style chosen. B is the basic binary coding, W is row standardised, C is globally standardised, while S is the variancestabilizing coding scheme proposed by Tiefelsdorf et al. 1999, p. 167168.
The function leaves matrix rows as zero for any regions with zero neighbours fore zero.policy TRUE. These will in turn generate lag values of zero, equivalent to the sum of products of the zero row t(rep(0, length=length(neighbours))) %*% x
, for arbitraty numerical vector x
of length length(neighbours)
. The spatially lagged value of x for the zeroneighbour region will then be zero, which may (or may not) be a sensible choice.
An n by n matrix, where n=length(neighbours)
Roger Bivand Roger.Bivand@nhh.no
Tiefelsdorf, M., Griffith, D. A., Boots, B. 1999 A variancestabilizing coding scheme for spatial link matrices, Environment and Planning A, 31, pp. 165180.
1 2 3 4 5 6  columbus < st_read(system.file("shapes/columbus.shp", package="spData")[1], quiet=TRUE)
col005 < dnearneigh(st_coordinates(st_centroid(st_geometry(columbus),
of_largest_polygon=TRUE)), 0, 0.5, as.character(columbus$NEIGNO))
summary(col005)
col005.w.mat < nb2mat(col005, style="B", zero.policy=TRUE)
table(round(rowSums(col005.w.mat)))

Loading required package: sp
Loading required package: spData
To access larger datasets in this package, install the spDataLarge
package with: `install.packages('spDataLarge',
repos='https://nowosad.github.io/drat/', type='source')`
Loading required package: sf
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
Neighbour list object:
Number of regions: 49
Number of nonzero links: 170
Percentage nonzero weights: 7.080383
Average number of links: 3.469388
4 regions with no links:
1005 1006 1008 1043
Link number distribution:
0 1 2 3 4 5 6 7 8 9
4 11 5 8 3 9 2 2 3 2
11 least connected regions:
1001 1007 1018 1010 1045 1044 1046 1047 1049 1048 1015 with 1 link
2 most connected regions:
1038 1036 with 9 links
0 1 2 3 4 5 6 7 8 9
4 11 5 8 3 9 2 2 3 2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.