[R-sig-Geo] Question about dnearneigh

Roger Bivand Roger.Bivand at nhh.no
Fri Mar 2 11:53:01 CET 2007


On Thu, 1 Mar 2007, Takatsugu Kobayashi wrote:

> Hi,
> 
> I have been doing exploratory analysis of the link between global 
> Moran's I coefficients and directional biases of frequencies.
> 
> I created a 10*10 matrix that contains random numbers using 
> randomNumbers(). This went well till I had to define a list of nearest 
> neighbor of each cell. I defined the nearest neighbors as cells that 
> fall within 3 unit distance of each cell. But the images and Moran's I 
> appear to be strange, meaning that the images look like random patterns 
> while the corresponding Moran's I indicate high autocorrelation. I 
> appreciate if someone could point out what I did wrong. Here is the 
> commands I typed:

Hi,

Thanks for a very clear and well documented question. I think that your
reasoning is OK, apart from this line:

> test<-moran.test(D[,p], nb2listw(dnb,style="W"))

which is doing the Moran's I test on the cell coordinate rather than the 
random variate. With:

test<-moran.test(D[,cases+p], nb2listw(dnb,style="W"))

it seems to be as expected.

Hope this helps,

Roger

> 
> rm(list=ls(all=T))
> 
> # Directional bias calculation
> library(random)
> library(spdep)
> 
> # Random process
> # 10*10 case
> 
> # Show n cases of lattice data that contains random numbers using 
> randomNumbers()
> cases<-2
> pts<-seq(1,10,by=1)
> x<-rep(pts,each=length(pts))
> y<-rep(pts,times=length(pts))
> z<-randomNumbers(length(pts)^2*cases,0,100,cases)
> D<-cbind(x,y,z)
> topo<-rep(list(matrix(,length(pts),length(pts))),cases)
> 
> # Reshaping a vector into n matrices
> for (m in 1:cases){topo[[m]]<-matrix(D[,m+2],length(pts),length(pts))}
> 
> dis<-as.matrix(dist(cbind(x,y),diag=T,upper=T,p=2))
> coords<-cbind(x,y)
> 
> # Distance-based nearest neighbors list
> dnb <- dnearneigh(coords, 0, 3)
> 
> par(mfcol=c(1,2))
> for (p in 1:cases){
> test<-moran.test(D[,p], nb2listw(dnb,style="W"))
> image(pts,pts,topo[[p]],col=grey(50:1/50),xlab="Easting",ylab="Northing")
> title(main=paste("Moran's I =",round(test$estimate[1],4)))
> }
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no




More information about the R-sig-Geo mailing list