0

我尝试通过使用包中的函数和 Moran.I包中的函数运行 Moran's I 测试空间自相关测试,通过对相同数据应用这两种方法,我得到了不同的结果。那么在这一点上,为什么我们会产生如此大的差异,最有效的方法是什么?请参阅以下代码:apemoran.testspdep

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)
4

1 回答 1

0

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

如下所示:mi$observed与 具有相同的值mt2$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    
于 2021-01-15T11:51:24.240 回答