[R-sig-Geo] Different values from raster::Moran() and spdep::moran.test()

Agustin Lobo alobolistas at gmail.com
Fri Nov 20 14:37:23 CET 2015


Using the testGrid example provided by
https://stat.ethz.ch/pipermail/r-sig-geo/2014-December/022106.html

lng <- rep(seq(0, 7, by=1), 8)
counter = 1
subCounter = 0
startNum = 0
lat = NULL
while (counter < 65) {
  if (subCounter == 8) {
    startNum = startNum + 1
    subCounter = 0
  }
  lat = c(lat, startNum)
  subCounter = subCounter + 1
  counter = counter + 1
}
# now add the black/ white chessboard pattern
chess <- rep(c(0,1,0,1,0,1,0,1,1,0,1,0,1,0,1,0), 4)
gridNum <- seq(1:64)
testGrid <- data.frame(gridNum, lat, lng, chess)

I define
require(raster)
rtestGrid <- rasterFromXYZ(testGrid[,2:4])
plot(rtestGrid)

and run

Moran(rtestGrid)
which results on:

[1] 0.07438017

while

require(spdep)
nb8q <- cell2nb(8, 8, type="queen", torus=FALSE)
moran.test(testGrid$chess, nb2listw(nb8q, style="B"),alternative="two.sided")

which results on:
Moran's I test under randomisation

data:  testGrid$chess
weights: nb2listw(nb8q, style = "B")

Moran I statistic standard deviate = -0.7714, p-value = 0.4404
alternative hypothesis: two.sided
sample estimates:
Moran I statistic       Expectation          Variance
     -0.066666667      -0.015873016       0.004335237

Considering the grid is regular, a negative I value makes sense.

Why is Moran() so different?

Thanks



More information about the R-sig-Geo mailing list