[R-sig-Geo] RE : Wheight matrices
Julien Beguin
julien.beguin.1 at ulaval.ca
Thu Apr 29 17:25:39 CEST 2010
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-bounces at stat.math.ethz.ch [r-sig-geo-bounces at stat.math.ethz.ch] de la part de Francisco Silva [gildemir at gmail.com]
Date d'envoi : 28 avril 2010 23:43
À : r-sig-geo at 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 at stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
More information about the R-sig-Geo
mailing list