[R] How to do "moran's I test"?

Lyndsey Stanfill lyndsey.stanfill at fcesc.org
Tue Feb 6 14:48:45 CET 2007


First, I use lattice data rather than point pattern data, so this may not be
applicable. 
The following is an example of the Moran's I test using the "south" dataset,
analyzing the variable HR60 for dependence.
I  use GeoDa to create my spatial weight (https://www.geoda.uiuc.edu/), and
I call the weight "south.gal"
In R, load package:spdep
Load and attach data:
> south <- read.table("south.txt", header=TRUE)
> attach(south)
Create my .nb weight:
> south.gal.nb <- ("south.gal")
Read the .gal file into a neighbors object:
> south.gal.nb <- read.gal ("south.GAL", override.id=TRUE)
Create my weight¹s matrix:
> south.listw <- nb2listw(south.gal.nb, style="W")
Name my variable as a spatially named vector:
> HR60 <- spNamedVec("HR60", south)
Perform test:
> str(moran(HR60, south.listw, length(south.gal.nb), Szero(south.listw)))
List of 2
 $ I: num 0.216
 $ K: num 31
For a monte carlo simulation of Moran's I (with randomization):
> nsim<-999
> set.seed(1234)
> simHR60<-moran.mc(HR60, listw=south.listw, nsim=nsim)
> simHR60
 
     Monte-Carlo simulation of Moran's I
 
data:  HR60 
weights: south.listw
number of simulations + 1: 1000
 
statistic = 0.2159, observed rank = 1000, p-value = 0.001
alternative hypothesis: greater

I hope this helps!
Lyndsey Stanfill
Research Design and Data Specialist
Central Ohio Regional School Improvement Team (CORSIT)
lyndsey.stanfill at fcesc.org
http://www.cositpd.org/index.html

On 2/6/07 7:36 AM, "Jian Zhang" <jzhang04 at 163.com> wrote:

> I want to do "moran's I test" in R language. I try to use "gearymoran" in
> Package "ade4","moran" in Package "spdep", and Moran.I in Package "ape". But
> I do not know how to do it because data format is different.
> 
> My data:
> 
>     x        y       dbh
> 
>   111.03    10.7       7
> 
>   118.11    0.28     1.2
> 
>   165.36    0.36     8.4
> 
>    282.9     0.3     7.5
> 
>   303.29   13.32    12.2
> 
>   319.28    3.88     6.2
> 
>      447       9       6
> 
>    445.5    18.3    13.8
> 
>    445.5    12.1     7.1
> 
>   467.64     1.2     4.7
> 
>    485.4    14.1     4.4
> 
>     2.98   23.95    11.7
> 
>       15   35.78    23.5
> 
>   130.21    23.6    14.1
> 
>    213.5   23.22    21.5
> 
>   233.57   28.76    35.4
> 
>    482.3    20.5       6
> 
>    69.73   45.21     7.5
> 
>     69.8   50.49    10.2
> 
>    76.65    45.5    21.5
> 
>  
> 
> "x","y" are spatial coordinate;
> 
> "dbh" is variable
> 
> I want to test the spatial autocorrelation of "dbh" in different distances
> by "x" and "y".
> 
>  
> 
> Thanks,
> 
>                                 Jian Zhang
> 
> 
> [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list