Hi Francisco,

In complement to the previous answer, the following code (with "spdep" package) 
might give you what you are looking for (1st order neighborhood):

------------------------------------------------------------------------------------------------
   require(spdep) 
   shape <- readShapePoly("path_to_my_shapefile", IDvar="Id_of_your_polygons")
   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)
                  )
------------------------------------------------------------------------------------------------

If you want to vary the order of neighborhood: see ?nblag 

The lines 3 to 6 make the format of the adjacency matrix compatible for Winbugs 
but you can play around that to get any desirable format, depending on which 
software or R-model you use.

Hope it helps,

Julien Beguin 

______________________________________
De : r-sig-geo-boun...@stat.math.ethz.ch [r-sig-geo-boun...@stat.math.ethz.ch] 
de la part de Francisco Silva [gilde...@gmail.com]
Date d'envoi : 28 avril 2010 23:43
À : r-sig-geo@stat.math.ethz.ch
Objet : [R-sig-Geo] Wheight matrices

Hi folks,

I am trying to do an spatial econometric model and I need a wheigt matrix.
I have tried so many times to do such thing in R, but I did not find the way.
I would like to know, if is possible to do the matrix in R?
If yes, how does i should do? Please, send the steps because I have
tried with so many packages and always i get wornings messages.
If somebody can help me I can send the .shp file to see how this work.
I know how to read a shape file and even plot maps, but i did not find
the way to construct an adjascency matrix.

Thanks a lot,
Francisco Gildemir Ferreira da Silva

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to