【发布时间】:2021-04-20 02:34:01
【问题描述】:
我尝试通过使用 ape 包中的函数 Moran.I 和 spdep 包中的 moran.test 来运行 Moran's I 测试空间自相关测试我通过同时应用这两种方法得到了不同的结果数据。那么在这一点上,为什么我们会产生如此大的差异,最有效的方法是什么?见以下代码:
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)
【问题讨论】:
-
如果您查看
Moran.I和moran.test的文档,您会发现它们具有不同的默认值。 -
@IanCampbell 谢谢你,即使我将 Moran.I 的替代品更改为更大的 moran.test 我仍然得到不同的结果(请参阅我更新的帖子)。
标签: r spatial spatial-index ape spdep