[R] Help needed on calculation of Moran's I

Thibaut Jombart jombart at biomserv.univ-lyon1.fr
Fri Oct 26 16:48:41 CEST 2007


Geertje Van der Heijden wrote:

>Hi,
>
>I am trying to calculate Moran's I test for the residuals for a
>regression equation, but I have trouble converting my  coordinates into
>nb format.
>
>I have used the dnearneigh() funtion now with an arbitrarily high upper
>distance to make it include all plots. However, when I do the
>lm.morantest() I get a Moran's I value which is the same as the expected
>value and a P-value of 1.
>
>I have used the following code:
>  
>
>>attach(lowland)
>>coords <- as.matrix(cbind(long, $lat))
>>coord.nb <- dnearneigh(coords, 0, 10000 longlat=TRUE)
>>coord.list <- nb2listw(coord.nb, style="W")
>>lianasp.lm <- lm(lianasprich ~ log(averdist) + dsl + lianadens +
>>    
>>
>wooddens)
>  
>
>>lm.morantest(lianasp.lm, coord.list, alternative="two.sided")
>>    
>>
>
>And get the following result
>
>        Global Moran's I for regression residuals
>
>data:  
>model: lm(formula = lianasprich ~ log(averdist) + dsl + lianadens +
>wooddens)
>weights: coord.list
> 
>Moran I statistic standard deviate = 0, p-value = 1
>alternative hypothesis: two.sided 
>sample estimates:
>Observed Moran's I        Expectation           Variance 
>     -1.754386e-02      -1.754386e-02       2.125706e-16 
>
>Can anyone tell me where I went wrong or if there is another way to
>generate a nb list? 
>
>Many thanks,
>Geertje
>  
>
Hi,

did you have a look at the graph you produced (using plot.nb)? Maybe the 
maximum distance between any two neighbours is too high. What does 
max(dist(coords)) say ?
Anyway, there are many different connection networks available in 
several R packages, some being more appropriate than others to model 
paticular spatial distributions.

The package adegenet proposes a small tool to choose among several 
graphs interactively:

library(adegenet)
xy = matrix(runif(100),ncol=2)
yourcn = chooseCN(xy)

Regards,

Thibaut.

-- 
######################################
Thibaut JOMBART
CNRS UMR 5558 - Laboratoire de Biométrie et Biologie Evolutive
Universite Lyon 1
43 bd du 11 novembre 1918
69622 Villeurbanne Cedex
Tél. : 04.72.43.29.35
Fax : 04.72.43.13.88
jombart at biomserv.univ-lyon1.fr
http://lbbe.univ-lyon1.fr/-Jombart-Thibaut-.html?lang=en
http://pbil.univ-lyon1.fr/software/adegenet/



More information about the R-help mailing list