【问题标题】:Getting different test results between Moran.I and moran.test在 Moran.I 和 moran.test 之间获得不同的测试结果
【发布时间】:2021-04-20 02:34:01
【问题描述】:

我尝试通过使用 ape 包中的函数 Moran.Ispdep 包中的 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.Imoran.test 的文档,您会发现它们具有不同的默认值。
  • @IanCampbell 谢谢你,即使我将 Moran.I 的替代品更改为更大的 moran.test 我仍然得到不同的结果(请参阅我更新的帖子)。

标签: r spatial spatial-index ape spdep


【解决方案1】:

如果您将参数style = "W" 提供给mat2listw,则这两种方法返回相同的结果。

如下所示:mi$observedmt2$estimate[1] 具有相同的值。

library(broom) # to tidy output of moran.test

mi <- Moran.I(Var, dists.inv, alternative = "greater")
mt1 <- moran.test(Var, mat2listw(dists.inv))
mt2 <- moran.test(Var, mat2listw(dists.inv, style = "W"))

str(mi)
List of 4
 $ observed: num -0.0184
 $ expected: num -0.00503
 $ sd      : num 0.0106
 $ p.value : num 0.896


tidy(mt1)

# A tibble: 1 x 7
  estimate1 estimate2 estimate3 statistic p.value method                           alternative
      <dbl>     <dbl>     <dbl>     <dbl>   <dbl> <chr>                            <chr>      
1   -0.0167  -0.00503  0.000199    -0.829   0.796 Moran I test under randomisation greater    

tidy(mt2)

# A tibble: 1 x 7
  estimate1 estimate2 estimate3 statistic p.value method                           alternative
      <dbl>     <dbl>     <dbl>     <dbl>   <dbl> <chr>                            <chr>      
1   -0.0184  -0.00503  0.000112     -1.26   0.896 Moran I test under randomisation greater    

【讨论】:

  • 非常感谢您提供这些信息。抱歉我的愚蠢问题,但样式“M”和“W”有什么区别?
  • 不是我的领域,但它与如何计算权重有关。见the documentation for nb2listw。如果它解决了您的问题,请投票和/或接受答案。
猜你喜欢
  • 1970-01-01
  • 2014-01-04
  • 2012-08-24
  • 1970-01-01
  • 2023-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-08
相关资源
最近更新 更多