# [R] dnearneigh() from spdep: Points with the exact same location are not considered neighbours.

Maël Le Noc mael.lenoc at txstate.edu
Tue Apr 11 00:27:29 CEST 2017

Dear List

As I was working on a project, I realized that when I use dnearneigh
from spdep, two (or more) points that have the exact same coordinates
are not considered neighbours and thus are not linked (even when the
lower bound is put to 0 or even to -1). See below for an example.

Does the function behave the same way for you? Am I missing something?
Is this an expected behavior? And if so, if there a way to change that ?

In the example below, points 1 and 2 are not connected to each other/are
not neighbours (as you can see since the both have only one link, to 3),
even though they have the exact same coordinates (and are thus less than
25km apart), while point 3 is connected to both point 1 and 2.
If I want to assess autocorelation using, for instance joincount.test,
this is then an issue...

> library(data.table)
> library(spdep)
> pointstable <- data.table(XCoord=c(13.667029,13.667029,13.667028),
YCoord=c(42.772396,42.772396,42.772396))
> print(pointstable)
XCoord  YCoord
1: 13.667029 42.772396
2: 13.667029 42.772396
3: 13.667028 42.772396
> coords <-cbind(pointstable\$XCoord, pointstable\$YCoord)
> nbLocal<- dnearneigh(coords, d1=0, d2=25, longlat = TRUE)
> nbLocal<- dnearneigh(coords, d1=-1, d2=25, longlat = TRUE) #both lines
produce the same output
> summary(nbLocal)
Neighbour list object:
Number of regions: 3
Percentage nonzero weights: 44.44444

1 2
2 1
2 least connected regions: