Skip to content
Prev 28783 / 29559 Next

question on raster Moran's I statistical significance

Hello,

With regards to my intention of solely estimating 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?

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()
################################################################################################
On Thu, Oct 21, 2021 at 1:13 PM Gabriel Cotlier <gabiklm01 at gmail.com> wrote: