[R-sig-Geo] neighbour list problem - read.gwt2nb

Roger Bivand Roger.Bivand at nhh.no
Sat Nov 20 21:47:02 CET 2010


On Fri, 19 Nov 2010, Carsten Kirkeby wrote:

>
> Hi again!
>
> I am terribly sorry, I got a couple of wrong lines copied into the question
> above. The script example should be this:
>
> test2 <- read.gwt2nb("neighbours.txt")
> summary(test2)
>
> #and the coordinates:
> coox <- c(5,5,5,5,4,3,2,1,1,2,3,4,4,3,2,1,1,2,3,4,4,3)
> cooy <- c(4,3,2,1,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5)
>
> #and a plot for illustration
> plot(test2,matrix(cbind(coox,cooy),ncol=2))
> text(coox,cooy,as.character(1:22),pos=rep(2,22), col="red", cex=0.8)
>
> The .txt file is the same as above.

I think that you are assuming that nb objects assume that if i is a 
neighbour of j, then j is automatically a neighbour of i. This is not the 
case, and both i, j and j, i neighours must be recorded (GWT also assumes 
that the user must provide all the neighbour links). In your case, try 
also:

test2a <- make.sym.nb(test2)
# to make the object symmetric, assuming this was your intention
summary(test2a)
write.sn2gwt(listw2sn(nb2listw(test2a, style="B")), "neighboursA.txt")
file.show("neighboursA.txt")

to indicate what your input file perhaps should have been. I'm not sure 
where you read this in ASDAR ch. 9 - it is correct that an i, j 
relationship should only be given once (no duplicate directed graph 
edges), but this does not mean that the presence of i, j implies that j, i 
is present too (in k-nearest neighbours objects, this is very unlikely, 
for example).

Hope this helps,

Roger

>
> Sincerely
> Carsten Kirkeby
>

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