nb2mat: Spatial weights matrices for neighbours lists

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/nb2mat.R

Description

The function generates a weights matrix for a neighbours list with spatial weights for the chosen coding scheme.

Usage

1
2
nb2mat(neighbours, glist=NULL, style="W", zero.policy=NULL)
listw2mat(listw)

Arguments

neighbours

an object of class nb

glist

list of general weights corresponding to neighbours

style

style can take values W, B, C, and S

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 zero-length weights vectors

listw

a listw object from for example nb2listw

Details

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 variance-stabilizing coding scheme proposed by Tiefelsdorf et al. 1999, p. 167-168.

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 zero-neighbour region will then be zero, which may (or may not) be a sensible choice.

Value

An n by n matrix, where n=length(neighbours)

Author(s)

Roger Bivand Roger.Bivand@nhh.no

References

Tiefelsdorf, M., Griffith, D. A., Boots, B. 1999 A variance-stabilizing coding scheme for spatial link matrices, Environment and Planning A, 31, pp. 165-180.

See Also

nb2listw

Examples

1
2
3
4
5
6
example(columbus)
coords <- coordinates(columbus)
col005 <- dnearneigh(coords, 0, 0.5, attr(col.gal.nb, "region.id"))
summary(col005)
col005.w.mat <- nb2mat(col005, zero.policy=TRUE)
table(round(apply(col005.w.mat, 1, sum)))

Example output

Loading required package: sp
Loading required package: Matrix

colmbs> require(maptools)
Loading required package: maptools
Checking rgeos availability: TRUE

colmbs> columbus <- readShapePoly(system.file("etc/shapes/columbus.shp",
colmbs+  package="spdep")[1])

colmbs> col.gal.nb <- read.gal(system.file("etc/weights/columbus.gal",
colmbs+  package="spdep")[1])
Warning message:
use rgdal::readOGR or sf::st_read 
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:
1 3 6 21
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:
2 5 9 10 31 34 36 39 42 46 47 with 1 link
2 most connected regions:
11 16 with 9 links

 0  1 
 4 45 

spdep documentation built on Aug. 19, 2017, 3:01 a.m.