Creates a list of connected nodes following the graph representation of a spatial connectivity matrix.

edges(C, unique_pairs_only = TRUE)

Arguments

C

A connectivity matrix where connection between two nodes is indicated by non-zero entries.

unique_pairs_only

By default, only unique pairs of nodes (i, j) will be included in the output.

Value

Returns a data.frame with three columns. The first two columns (node1 and node2) contain the indices of connected pairs of nodes; only unique pairs of nodes are included (unless unique_pairs_only = FALSE). The third column (weight) contains the corresponding matrix element, C[node1, node2].

Details

This is used internally for stan_icar and it is also helpful for creating the scaling factor for BYM2 models fit with stan_icar.

Examples

data(sentencing)
C <- shape2mat(sentencing)
nbs <- edges(C)
head(nbs)

## similar to:
head(Matrix::summary(C))
head(Matrix::summary(shape2mat(georgia, "W")))