I wrote a script that produces three raster objects and computes their local and global values for Moran's I. The rasters exhibit regular, clustered and randomly distributed data. I would have expected the values for Moran's I to approximate -1, 1, and 0 for the three scenarios. However this is not the case for the regular data. Moran's I comes out at around 0 instead of -1, both locally and globally and I don't understand why.

To form this into a question: What do I have to change about the regular grid so it results in a Moran's I approaching -1?

Here's the script that I used to compute and plot the rasters and statistics (cell neighbourhood definition is queen's case):

library (raster)
library (rasterVis)

n <- 11

r_regular <- raster (nrows=n, ncols=n, xmn=0, xmx=1, ymn = 0, ymx = 1)
values (r_regular) <- 0
values (r_regular) [seq (1, n^2, by = 2)] <- 1

m_regular <- MoranLocal (r_regular)
mg_reg <- Moran (r_regular)

r_clust <- r_regular
values (r_clust) <- 0
values (r_clust) [seq (1, (n^2) / 2)] <- 1

m_clust <- MoranLocal (r_clust)
mg_clust <- Moran (r_clust)

r_rand <- r_regular
values (r_rand) <- 0
values (r_rand) [sample.int (n^2, n^2 / 2)] <- 1
m_rand <- MoranLocal (r_rand)
mg_rand <- Moran (r_rand)

ms <- stack (r_regular, r_clust, r_rand, m_regular, m_clust, m_rand)
nms <- c ("Regular data", "Clustered data", "Random data",
                 paste0 ("Regular - Global I: ", mg_reg),
                 paste0 ("Clustered - Global I: ", mg_clust),
                 paste0 ("Random: Global I: ", mg_rand)
levelplot (ms, names = nms)

1 Answer 1


By defaults the Moran function uses the 8 neighbours of each cell. For your regular raster, 4 of these are the same and 4 are different to the centre cell. That's no autocorrelation.

If instead you only use the four "rook" adjacent neighbours, you get -1:

> rook = matrix(c(0,1,0,1,0,1,0,1,0),3,3)
> rook
     [,1] [,2] [,3]
[1,]    0    1    0
[2,]    1    0    1
[3,]    0    1    0
> Moran(r_regular,w=rook)
[1] -1

I don't think you can construct a grid with Moran I = -1 using the 8 Queen's neighbours, because that would mean all 8 neighbours were different from the central value, and that all 8 neighbours would be different from each of their neighbours, which is impossible for a raster with two values. You can do this for the Rook's neighbours because the 4 Rook neighbours aren't neighbours of each other.

This grid has a Queen's adjacency Moran I of -0.322:

enter image description here

because about 1/3 of its cells (the green ones) have perfect anti-correlation but the rest have varying mixes of self and non-self values.

Challenge: make an 11x11 raster with an even smaller Moran I with Queen's adjacency!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.