Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

nbOrder

Determine Neighbourhood Order Matrix from Binary Adjacency Matrix


Description

Given a square binary adjacency matrix, the function nbOrder determines the integer matrix of neighbourhood orders (shortest-path distance) using the function nblag from 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 vertex adjacencies, i.e., 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 number of regions (there cannot be higher orders) and then converted to integer, thus, maxlag = Inf also works.

Value

An integer matrix of neighbourhood orders, i.e., the shortest-path distance matrix of the vertices. The dimnames of the input neighbourhood matrix are preserved.

Note

By the end, the function issues a message informing about the range of maximum neighbourhood order by region.

Author(s)

Sebastian Meyer

See Also

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

Examples

## generate adjacency matrix
set.seed(1)
n <- 6
adjmat <- matrix(0, n, n)
adjmat[lower.tri(adjmat)] <- sample(0:1, n*(n-1)/2, replace=TRUE)
adjmat <- adjmat + t(adjmat)
adjmat

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

surveillance

Temporal and Spatio-Temporal Modeling and Monitoring of Epidemic Phenomena

v1.19.1
GPL-2
Authors
Michael H<f6>hle [aut, ths] (<https://orcid.org/0000-0002-0423-6702>), Sebastian Meyer [aut, cre] (<https://orcid.org/0000-0002-1791-9449>), Michaela Paul [aut], Leonhard Held [ctb, ths], Howard Burkom [ctb], Thais Correa [ctb], Mathias Hofmann [ctb], Christian Lang [ctb], Juliane Manitz [ctb], Andrea Riebler [ctb], Daniel Saban<e9>s Bov<e9> [ctb], Ma<eb>lle Salmon [ctb], Dirk Schumacher [ctb], Stefan Steiner [ctb], Mikko Virtanen [ctb], Wei Wei [ctb], Valentin Wimmer [ctb], R Core Team [ctb] (A few code segments are modified versions of code from base R)
Initial release
2021-03-30

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.