[R-sig-Geo] question on raster Moran's I statistical significance

Gabriel Cotlier g@b|k|m01 @end|ng |rom gm@||@com
Sat Oct 23 09:49:53 CEST 2021


Hello,

I would like to estimate the pseudo p-value of Moran's I from raster data
layer, by converting it to polygon data in order to be able to directly use
the function  spdep::mc.moran() and getting in one step not only value of
Moran'sI but its statistical significance without using other simulations
but only that in the funcion spdep::mc.moran() as an alternative I have
used the code below. However, since with the initial version of the code I
got  several errors such as :

Error in moran. mc(My_raster, lw.l, 999) : r is not a numeric vector

So I converted "r" to a vector using as.vector() in :

M <- moran.mc(as.vector(r), lw.l, 999)

However then appeared another the error:

Error in na.fail.default(x) : missing values in object

Finally these errors disappeared with the following version of the code--
see below -- the version of the code below runs OK--unless for the input
raster I have used-- with no more errors or problems.

Therefore my question is : if instead of using arguments of the function
spdep::mc.moran() such as na.action = na.omit or other --which I have tried
and could not make work-- is it a valid way to solve the above errors  in
the way as presented in the code below?

I would appreciate it a lot if there is a possibility of knowing what could
be wrong in the code below?

I suspect it could be possible the problem is related to the way in which
the raster  data layer is converted to polygon data  im the code to be
input to the function spdep::mc.moran() , but will appreciate any guidance
and assistance in the issue to get working in the correct manner.

Thanks a lot.
Kind regards,

################### Estimate of Moran's I and its p-value from a raster
layer ##################################
library(raster)
library(spdep)
library(easycsv)

rm(list = ls())

r<- raster(file.choose())
l <- rasterToPolygons(r)

nb.l <- poly2nb(l, queen=FALSE)
lw.l <- nb2listw(nb.l, style="W",zero.policy=TRUE)

v<-r[!is.na(r)]
M <- moran.mc((v), lw.l, 999, zero.policy=TRUE)
M

plot(M, main=sprintf("Original, Moran's I (p = %0.3f)", M$p.value),
xlab="Monte-Carlo Simulation of Moran I", sub =NA, cex.lab=1.5,
cex.axis=1.5, cex.main=1.5, cex.sub=1.5)
abline(v=M$statistic, col="red", lw=2)
dev.off()
################################################################################################

-- 
Gabriel Cotlier, PhD
Haifa Research Center for Theoretical Physics and Astrophysics (HCTPA)
University of Haifa
Israel

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list