You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This line in the global Moran's I calculation (autocor.R line 156) will return NA for any cell with an adjacent NA cell, and thus does not correctly count neighbours for any cell with an adjacent NA.
W<- focal( zz, w=w, fun="sum")
In extreme cases this leads to a failure to calculate Global Moran's I (autocorr returns NA).
In less extreme cases this leads to slightly inflated values of I being returned.
Here's some code to replicate this issue in an extreme case:
exampleRast_base<- ifel((0==rast(diag(1,5,5))),NA,1) # Generate a diagonal raster -> an extreme caseexampleRast<- mask(focal(exampleRast_base,3,'sum',na.rm=TRUE),exampleRast_base) # Adjust the raster to add some variancex<-exampleRastw<-matrix(c(1,1,1,1,0,1,1,1,1),3)
autocor(x, w, method="moran", global=TRUE) # -> Returns NA
And here's some code that I think will properly count neighbours if we replace line 156 with it. Notably, we need to apply a mask using the original raster after adding na.rm = TRUE, otherwise the autocorr function will produce slightly deflated values for I.
This line in the global Moran's I calculation (
autocor.R
line 156) will returnNA
for any cell with an adjacent NA cell, and thus does not correctly count neighbours for any cell with an adjacent NA.In extreme cases this leads to a failure to calculate Global Moran's I (
autocorr
returns NA).In less extreme cases this leads to slightly inflated values of I being returned.
Here's some code to replicate this issue in an extreme case:
And here's some code that I think will properly count neighbours if we replace line 156 with it. Notably, we need to apply a mask using the original raster after adding
na.rm = TRUE
, otherwise theautocorr
function will produce slightly deflated values for I.I'm unsure whether a similar issue exists for the local or Geary calculations - I'm not particularly familiar with how they are calculated.
OS is Windows 10
The text was updated successfully, but these errors were encountered: