[R-sig-Geo] Dealing with lakes and NA in Moran/SpatialPolygonsDataFrame

Matthieu Stigler matthieu.stigler at gmail.com
Fri Sep 4 11:37:24 CEST 2009


Hi

I have a second problem with NA in SpatialPolygonsDataFrame, it seems
that residuals.spautolm does not work with NA values, returning NULL.

I add to the questions I asked yesterday about dealing with NAs and
I'm very thankful if anyone could give me any advice!

Thanks a lot!!

Matthieu Stigler



2009/9/3 Matthieu Stigler <matthieu.stigler at gmail.com>:
> 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?
>

SPAUTOLM residuals problem:

NY8 <- readOGR(".", "NY8_utm18")
library(spdep)
Syracuse <- NY8[NY8$AREANAME == "Syracuse city",]
Syracuse2<-Syracuse
Syracuse2$POP8[43]<-NA
spplot(Syracuse2, zcol="POP8")

NY8$Z[43]<-NA
NY8$PEXPOSURE[43]<-NA
NY8$PCTAGE65P[43]<-NA
NY8$PCTOWNHOME[43]<-NA

NY_nb <- read.gal("NY_nb.gal", region.id=row.names(as(NY8, "data.frame")))
NYlistw<-nb2listw(NY_nb, style = "B")
nysar<-spautolm(Z~PEXPOSURE+PCTAGE65P+PCTOWNHOME , data=NY8, listw=NYlistw)
summary(nysar)
residuals(nysar)


> Thanks a lot!
> Matthieu Stigler
>



More information about the R-sig-Geo mailing list