[R-sig-Geo] Moran.I function in "ape" library yielding unexpected values

Steve Pickering pickering at penguin.kobe-u.ac.jp
Fri Dec 5 14:09:13 CET 2014


Dear r-sig-geo community,

I'm running the Moran.I function in the "ape" library and getting some
values which are not what I'm expecting.  Consider the code below, in
which a simple 8 x 8 grid is set up, and then populated with a
chessboard pattern.  My understanding is that a chessboard is an
example of perfect negative spatial autocorrelation, and that it
should therefore yield a Moran's I value of -1.  The result it yields,
while negative, is not close to -1:

$observed
[1] -0.07775248

$expected
[1] -0.01587302

$sd
[1] 0.01499786

$p.value
[1] 3.693094e-05

The code is as follows.  Can anyone tell me what I'm doing wrong?

As always, many thanks!

 - Steve.



library(ape)

# first, build an 8 x 8 grid
# lats and lngs will go from 0 to 7

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)

# simple Euclidean distance measure

testGrid.dists <- as.matrix(dist(cbind(testGrid$lng, testGrid$lat)))

# invert the distances, then replace the infinities with 0

testGrid.dists.inv <- 1 / testGrid.dists

diag(testGrid.dists.inv) <- 0

# now test the chessboard pattern

Moran.I(testGrid$chess, testGrid.dists.inv)



Steve Pickering
Assistant Professor
Graduate School of Law
Kobe University
2-1 Rokkodai-cho
Nada-ku, Kobe
657-8501 Japan
pickering at penguin.kobe-u.ac.jp
http://www.stevepickering.net



More information about the R-sig-Geo mailing list