create listw-objects from shapefiles
On Mon, 4 Dec 2006, Catherine Linard wrote:
Dear R-sig-geo list, I would like to do some spatial analyses such as moran.test, for which I need a listw. I have shapefile data, so I tried to apply the following steps: - create spatial polygons with readShapePoly (maptools package) - create neighbours list by poly2nb (spdep package) - create spatial weights with nb2listw I get an error message for the last step saying that my nb-object is empty but I have results in the neigbours list object in the previous step
No, you have two observations with empty sets of neighbours:
2 regions with no links: 44 78
Either fix that - for example with edit.nb(), or accept that this is reasonable - they really have no neighbours, and set zero.policy=TRUE. Roger
Here are my results:
> lyme <- readShapePoly ("Filename",
proj4string=CRS(as.character (NA)), verbose=FALSE)
> summary(lyme)
Object of class SpatialPolygonsDataFrame
Coordinates:
min max
r1 22120.69 295156.8
r2 21153.22 244018.8
Is projected: NA
proj4string : [NA]
Data attributes: different attributes
> lyme_nb <- poly2nb(as(lyme, "SpatialPolygons")) > summary(lyme_nb)
Neighbour list object: Number of regions: 589 Number of nonzero links: 3314 Percentage nonzero weights: 0.9552607 Average number of links: 5.626486 2 regions with no links: 44 78 Link number distribution: 0 1 2 3 4 5 6 7 8 9 10 11 12 14 15 2 2 10 35 75 170 144 86 38 17 5 1 2 1 1 2 least connected regions: 8 363 with 1 link 1 most connected region: 73 with 15 links
> lyme_w <- nb2listw(lyme_nb,glist=NULL,style="W",zero.policy=FALSE)
Error in nb2listw(lyme_nb, glist = NULL, style = "W", zero.policy = FALSE) :
Empty neighbour sets found
Is there something wrong? Do I miss something?
Thank you very much for any help!
Catherine
Catherine Linard
University of Louvain
Department of Geography
Place Pasteur, 3
B - 1348 Louvain-la-Neuve
BELGIUM
Tel: +32/10/47.28.67
Fax: +32/10/47.28.77
e-mail: linard at geog.ucl.ac.be
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no