[R-sig-Geo] identify neighborhoods (with neighbors list). Possible?

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Mon Jun 4 19:23:53 CEST 2012


On Mon, Jun 4, 2012 at 5:41 PM, Leonardo Monasterio
<leonardo.monasterio at gmail.com> wrote:
> Dear all,
> A spdep  listw object has each unit and its neighboors. I am searching for
> a way to go from this listw object to the list of the *neighboorhoods*  and
> its member units.
> Example:
> Units: neighboors
>
> A :B C
> B: A
> D: E
> C: A
> E: D
>
> I want
> Neighborhood I : A, B, C
> Neighborhood II : D, E
>
> Any ideas?

 Graph Theory!

 and the igraph package.

 rewriting your list as an edgelist matrix:

> el
     [,1] [,2]
[1,] "A"  "B"
[2,] "A"  "C"
[3,] "B"  "A"
[4,] "D"  "E"
[5,] "C"  "A"
[6,] "E"  "D"

then

> g = graph.edgelist(el)

and

> clusters(g)
$membership
[1] 0 0 0 1 1

$csize
[1] 3 2

$no
[1] 2

 now the $membership part of the value here is telling you which of
the vertices are in which cluster (numbered from zero, that's graph
theorists for you).


Converting the listw to a graph (might be an easier way than
converting to an edgelist matrix) is left as an exercise! [Truth: I
don't have any listw objects handy at the moment]

Barry



More information about the R-sig-Geo mailing list