Learn R Programming

spdep (version 0.1-10)

is.symmetric.nb: Test a neighbours list for symmetry

Description

Checks a neighbours list for symmetry/transitivity (if i is a neighbour of j, then j is a neighbour of i). This holds for distance and contiguity based neighbours, but not for k-nearest neighbours. The helper function sym.attr.nb() calls is.symmetric.nb() to set the sym attribute if needed, and make.sym.nb makes a non-symmetric list symmetric by adding neighbors.

Usage

is.symmetric.nb(nb, verbose = TRUE, force = FALSE)
sym.attr.nb(nb)
make.sym.nb(nb)

Arguments

nb
an object of class nb with a list of integer vectors containing neighbour region number ids.
verbose
if TRUE prints non-matching pairs
force
do not respect a neighbours list sym attribute and test anyway

Value

  • TRUE if symmetric, FALSE if not

See Also

read.gal

Examples

Run this code
data(columbus)
print(is.symmetric.nb(col.gal.nb, verbose=TRUE, force=TRUE))
k4 <- knn2nb(knearneigh(coords, k=4), row.names=rownames(columbus))
k4 <- sym.attr.nb(k4)
print(is.symmetric.nb(k4))
k4.sym <- make.sym.nb(k4)
print(is.symmetric.nb(k4.sym))

Run the code above in your browser using DataLab