Skip to content
Prev 10794 / 29559 Next

creating an adjacency matrix in spdep

On Tue, 1 Feb 2011, Stratford, Jeffrey wrote:

            
No, it is not a matrix. An nb object is a list of vectors of neighbour IDs 
(taken as integer IDs in j=1,N, j!=i); a listw object pairs an nb object 
with the matching spatial weights in the same configuration, and is very 
much like a sparse matrix representation. listw2mat() converts a listw 
object into a dense matrix with mostly zero entries; sparse matrix 
representations are also used in spdep.

By definition, an adjacency matrix is a sparse matrix representing the 
graph of edges representing adjacency relationships between nodes, and 
only in very odd circumstances would it be dense (all adjacent to all). 
You are setting the distance threshold too large. The example in 
?dnearneigh shows how you can use the nearest neighbour to set the 
threshold so that all observations are linked, which is most likely needed 
in WB.
Distance-based neighbours are necessarily symmetric by definition, so the 
next step is superfluous.

Hope this helps,

Roger