[R-sig-Geo] moran.plot: sum or mean?
Robert J. Hijmans
r.hijmans at gmail.com
Mon Apr 22 21:12:44 CEST 2013
I am using package spdep. I have a listw object (lw) and a vector of
values (y) and I want to make a Moran scatterplot (with unadjusted
values):
library(spdep)
m <- matrix(c(0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0,
0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0), ncol=6)
lw <- mat2listw(m, style='B')
y <- c(32, 26, 19, 14, 18, 17)
moran.plot(y, lw)
# The values on the vertical axes are the sums of the lagged values
# (as returned by lag(lw, y) ), where I expected the mean (which is
# what the example ?moran.plot example appears to do
# I expected this
x <- cbind(rep(y, each=6), as.vector(m * y))
x <- x[x[,2] > 0, ]
x <- aggregate(x[,2], list(x[,1]), FUN=mean)
colnames(x) <- c('y', 'lagged y')
# and a plot like this
x11()
plot(x)
abline(lm(x[,2] ~ x[,1]), lwd=2)
abline(v=mean(y), lt=2)
abline(h=mean(x[,2]), lt=2)
# What am I missing?
Thanks, Robert
More information about the R-sig-Geo
mailing list