[R-sig-Geo] Null Distances in Neighbour Matrix

Roger Bivand Roger.Bivand at nhh.no
Thu Mar 18 09:05:59 CET 2010


On Mon, 15 Mar 2010, sylvain willart wrote:

> Hello,
>
> I am new to this list as I just begin to work on spatial data...
>
> I mostly use spdep (and lme for the variogram) but I recently came
> across a problem I don't know how to deal with,
>
> The project I'm working on is a study on the localization of physicians 
> in a metropolitan area. I have the adress of each of them that I coded 
> in Long/Lat. However, some of them are grouped in the same practice, 
> sharing the same adress, and hence the same Long/Lat. This causes a 
> "null distance" error when I try to compute a neighbour matrix and a 
> variogram.

You will need to introduce a trivial non-zero distance to disambiguate the 
points that have zero distance in both cases. Use the sp function 
zerodist() to find the observations that match, and jitter them:

library(sp)
set.seed(1)
xy <- cbind(runif(10), runif(10))
xy <- rbind(xy, xy[1:2,])
xy[c(1,2,11,12),]
library(spdep)
a <- dnearneigh(xy, 0, 0.35)
a[[1]]
zerodist(SpatialPoints(xy))
js <- c(zerodist(SpatialPoints(xy)))
xy[js, 1] <- jitter(xy[js, 1], amount=0.00001)
xy[js, 2] <- jitter(xy[js, 2])
xy[c(1,2,11,12),]
b <- dnearneigh(xy, 0, 0.35)
b[[1]]

and similarly for the variogram case.

Hope this helps,

Roger

>
> any clue ?
>
> thanks in advance,
>
> sylvain
>
> _______________________________________________
> 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