Learn R Programming

surveillance (version 1.5-4)

nbOrder: Determine Neighbourhood Order Matrix from Binary Adjacency Matrix

Description

Given a square binary matrix indicating adjacencies, the function nbOrder determines the integer matrix of orders of neighbourhood using the function nblag from the spdep package. Hence this function is essentially a wrapper around functionality of the spdep package.

Usage

nbOrder(neighbourhood, maxlag = 1)

Arguments

neighbourhood
a square, numeric or logical, and usually symmetric matrix with finite entries (and usually zeros on the diagonal) which indicates first-order neighbourhood (interpreted as neighbourhood == 1, not >0).
maxlag
positive scalar integer specifying an upper bound for the neighbourhood order. The default (1) just returns the input neighbourhood matrix (converted to binary integer mode). maxlag is automatically trimmed to one less than the nu

Value

  • An integer matrix of neighbourhood order. The dimnames of the input neighbourhood matrix are preserved.

See Also

nblag from the spdep package, on which this wrapper depends.

Examples

Run this code
## generate random adjancency matrix
n <- 6
adjmat <- matrix(0, n, n)
adjmat[lower.tri(adjmat)] <- sample(0:1, n*(n-1)/2, replace=TRUE)
adjmat <- adjmat + t(adjmat)

## determine neighbourhood order matrix
if (require("spdep")) {
    nbmat <- nbOrder(adjmat, maxlag=Inf)
    nbmat
}

Run the code above in your browser using DataLab