Hi,

I have a question on testing spatial autocorrelation on raster data including NA-values. In particular, I like to calculate Moran´s I and Geary´s C indices by using inverse distance weighting matrices. Calculating Moran´s I with moran.test works fine, because the function contains the option "na.action=na.pass". Unfortunately, the function geary.test does not contain this option. The problem is that geary.test needs an nb argument for which I cannot perform for example nb<-ifelse(value, nb, NA), because it would change the nb-format to a list-format. Is there a way to ignore NA-values in geary.test? Or how can I set NA values in a neigbors (nb) list?

Thank you very much,
Kerstin

---

file<-raster(test.tif")
mask<-extent(file, 1, 50, 1, 50)
subset<-crop(file,mask,test.tif", overwrite=TRUE)
value <- as.matrix(subset)

# Creation of a list of integer vectors giving the region id numbers for the neighbors within the grid extent
nb <- cell2nb(50, 50, type="queen", torus=TRUE)

# Calculation of the distances along the links in the neighbous list
dist <- nbdists(nb, coordinates(subset), longlat=TRUE)

# Converting the distances to inverse distance values
inv.dist <- lapply(dist, function (x) 1/(x*100))

# Supplementing the neighbors list with spatial weights for a coding scheme
nb.idw <- nb2listw(nb, glist=inv.dist, style="W")
summary(unlist(nb.idw$weights))

# Moran's test (two-sided)
moran.global <- moran.test(value, listw=nb.idw, zero.policy = TRUE, na.action=na.pass, alternative="two.sided")
moran.global

# Geary's test (two-sided)
geary.global <- geary.test(value, listw=nb.idw, zero.policy = TRUE , alternative="two.sided")
geary.global

----------------------------------------------------------------
This message was sent through https://webmail.uni-jena.de

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to