I tried to run Moran's I test for the spatial autocorrelation test by using the function Moran.I
from the package ape
and moran.test
from the package spdep
I got different results by applying the two methods on the same data. So at this point why we're getting such a difference and what is the most efficient method? See the following code:
library(ape) #For Moran.I
library(spdep) #For moran.test
Var <- rnorm(200,1, 1)
xy<- as.data.frame(cbind(rnorm(200,0, 1), (rnorm(200,0, 1))))
colnames(xy) <-c('X','Y')
dists <- as.matrix(dist(cbind(xy$X, xy$Y)))
dists.inv <- 1/dists
diag(dists.inv) <- 0
# TEST WITH "Moran.I"
Moran.I(Var, dists.inv, alternative = "greater")
# TEST WITH "moran.test"
lw <- mat2listw(dists.inv)
moran.test(Var, lw)