[R] Adjacency matrix of higher order (from winbugs to to R)

Julien Beguin julien.beguin.1 at ulaval.ca
Tue Mar 2 19:50:20 CET 2010


   Hi everyone,



   I am trying to find a way to calculate an adjacency matrix from a polygon
   shapefile to make a CAR model in winbugs, but I would like to vary the order
   of neihborhood. I used the the spdep package to create an adjacency matrix
   (in list format) of order 2 and it works pretty fine:



   shape <- readShapePoly("path_to_my_shapefile", IDvar="Id")
   shape_nb<-poly2nb(shape)



   data<-list(N = length(shape_nb),
   num=sapply(shape_nb, length),
   adj=unlist(shape_nb),
   lst <- attr(shape_nb, "region.id"),
   adj2 <- lst[unlist(shape_nb)],
   sumNumNeigh=length(unlist(shape_nb))



   is everyone know how to calculate an adjacency matrix in R for polygon
   shapefile but for higher orders of neihborhood (ex: 3,4,5, etc...)? I did
   not see any option for that with poly2nb() in spdep package but I imagine
   that other tools have to exist. Your help would be greatly appreciated.



   Best regards,



   Julien


More information about the R-help mailing list