compon: Depth First Search on Neighbor Lists

Description Usage Arguments Value Author(s) See Also Examples

Description

n.comp.nb() finds the number of disjoint connected subgraphs in the graph depicted by nb.obj - a spatial neighbours list object.

Usage

1
n.comp.nb(nb.obj)

Arguments

nb.obj

a neighbours list object of class nb

Value

A list of:

nc

number of disjoint connected subgraphs

comp.id

vector with the indices of the disjoint connected subgraphs that the nodes in nb.obj belong to

Author(s)

Nicholas Lewin-Koh nikko@hailmail.net

See Also

plot.nb

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
example(columbus)
coords <- coordinates(columbus)
plot(col.gal.nb, coords, col="grey")
col2 <- droplinks(col.gal.nb, 21)
plot(col2, coords, add=TRUE)
res <- n.comp.nb(col2)
table(res$comp.id)
points(coords, col=res$comp.id, pch=16)
if (require(igraph)) {
B <- as(nb2listw(col2, style="B", zero.policy=TRUE), "CsparseMatrix")
g1 <- graph.adjacency(B, mode="undirected")
c1 <- clusters(g1)
print(c1$no == res$nc)
print(all.equal(c1$membership, res$comp.id))
print(all.equal(c1$csize, c(table(res$comp.id)), check.attributes=FALSE))
W <- as(nb2listw(col2, style="W", zero.policy=TRUE), "CsparseMatrix")
g1W <- graph.adjacency(W, mode="directed", weighted="W")
c1W <- clusters(g1W)
print(all.equal(c1W$membership, res$comp.id))
B1 <- get.adjacency(g1)
print(all.equal(B, B1))
}

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