[R-sig-Geo] Dealing with lakes and NA in Moran/SpatialPolygonsDataFrame
Matthieu Stigler
matthieu.stigler at gmail.com
Thu Sep 3 13:00:45 CEST 2009
Hi
I'm puzzled hot to deal with NAs and lakes on SpatialPolygonsDataFrame
objects...
My problems (maybe should I post in separated files?):
-spplot does not seem to handle specially NA values...
-neighbors graph seem to make links even to lakes/holes
-moran.test seem to work with NA values... but what about the
neighbors/weights used as input? Are the results biased?
-localmoran does not seem to work with NA
I illustrate each of them below.
Example is based on Syracuse data from ASDAR (data from web-site
http://www.asdar-book.org/bundles/lat1_bundle.zip):
#NA PROBLEM
setwd("H:/Documents/Stats/Book Bivand/Chap 9")
library(sp)
library(rgdal)
NY8 <- readOGR(".", "NY8_utm18")
library(spdep)
Syracuse <- NY8[NY8$AREANAME == "Syracuse city",]
Syracuse2<-Syracuse
Syracuse2$POP8[43]<-NA
spplot(Syracuse2, zcol="POP8")
#it appears as white, similar to other colors which are nevertheless
true values and not NA!
LAKE problem:
#check if lakes:
sapply(sapply(slot(Syracuse, "polygons"),function(x) slot(x,
"Polygons")), function(x) slot(x, "hole"))
#btw, it is pretty complicated, are there some more user-friendly
wrapers for that? kind of isHole, getHole?
slot(slot(slot(Syracuse2, "polygons")[[43]],"Polygons")[[1]], "hole")<-TRUE
plot(poly2nb(Syracuse), coordinates(Syracuse2))
Here it seems that it did not take into account the hole and still
computes neighbors... right?
And if yes... does it affect the results using moran tests?
Thanks a lot!
Matthieu Stigler
More information about the R-sig-Geo
mailing list