[R] Subsetting NaN values in localG()
Roger Bivand
Roger.Bivand at nhh.no
Sat Jul 16 20:54:08 CEST 2011
Writing to R-sig-geo would have been a good idea if you required speedier
response. That response would have suggested that your code is not at all
helpful, not using available classes in R for handling spatial data. You
could have read your Arc GRID into a SpatialGridDataFrame, and made
everything simpler. For an arbitrary longlat grid at 0.5 degrees spacing and
a 100km neighbour threshold:
diffc <- rep(as.numeric(NA), 53235)
diffc[sample(53235, 25064, FALSE)] <- rnorm(25064)
summary(diffc)
library(sp)grd <- GridTopology(c(0.25, -79.75), c(0.5,0.5), c(169, 315))
SGDF <- SpatialGridDataFrame(grd, proj4string=CRS("+proj=longlat"),
data=data.frame(diffc))
# SGDF could be read in from Arc with readGDAL() in rgdal
SPixDF <- as(SGDF, "SpatialPixelsDataFrame")
library(spdep)
dnb <- dnearneigh(SPixDF, 0, 100)
dnb
summary(SPixDF)
names(SPixDF)
lw <- nb2listw(dnb, style="B", zero.policy=TRUE)
out <- localG(SPixDF$diffc, lw, zero.policy=TRUE)
summary(out)
As you see, none of your assertions about localG() or dnearneigh() hold in
an unqualified fashion (localG stops on NAs, a quite logical design choice),
you have simply not considered your data representation adequately. Did you
read the Spatial Task View on CRAN carefully?
Further, so-called "hot-spots" are most likely a very poor idea, as the heat
will be only in the eye of the beholder. You should be very careful with
ad-hoc approaches of this kind.
dab98 wrote:
>
> Still have not solved this problem with package 'spdep'. It appears
> localG() cannot handle either SpatialPoints or a matrix of point
> coordinates that are not in a rectangular matrix when plotted. It cannot
> take NaN values and, after I successfully used dnearnigh() to create an
> "nb" object for ONLY Northeast land points and converted to a 'listw'
> object, it still returned the same error. See below ("points" is a
> 2-column matrix of lat-long point coordinates; diffD is my data matrix):
>
> / > neigh2 = dnearneigh(points,0,5,longlat=TRUE)
> > mylist = nb2listw(neigh2,style="B")
> > stats = localG(diffD,mylist)
> Error in matrix(0, nrow = nrow(x), ncol = ncol(x)) :
> invalid 'ncol' value (too large or NA)/
>
> Again, if anyone thinks this analysis is incorrect, please let me know.
> If not, I'll just abandon R for this portion of the project, as it is
> taking far too long to use this this package with Getis-Ord statistics,
> which should run fairly easily.
>
-----
Roger Bivand
Department of Economics
NHH Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway
--
View this message in context: http://r.789695.n4.nabble.com/Subsetting-NaN-values-in-localG-tp3662781p3672287.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list