[R-sig-Geo] nndist R vs. ArcGIS

Adrian.Baddeley at csiro.au Adrian.Baddeley at csiro.au
Tue Apr 12 03:41:17 CEST 2011

This topic arose on R-help:

smoluka<smoluka at geo.oregonstate.edu>  writes:
>> Can anyone tell me why I would get different average nearest neighbor values
>> for the same set of coordinates between ArcGIS 10 and R? Sometimes the
>> difference in distance is over 1.3 km.

There are several possible explanations including the treatment of zero distances and duplicated points (i.e. two points at the same location), the handling of edge effects, numerical effects due to the scale of the data, and numerical rounding when the data were transferred between packages.

You don't say which functions/libraries/packages you are using in R. An example would help.

Since you mention 'nndist' I guess you were using the 'spatstat' library. The spatstat function 'nndist' calculates nearest-neighbour distances WITHOUT edge correction. If there are two (x,y) points at the same location, they are deemed to have distance zero, and will be counted as nearest neighbours of each other by nndist. You could check whether this is true for ArcGIS.

[the spatstat function 'Gest' calculates an edge-corrected cumulative distribution function of the nearest neighbour distances]. 

You say that the discrepancies in mean n.n. distance were as large as 1.3 km. What was the overall scale of the data? Hundreds of km? And were the coordinates recorded in metres? If so, then the discrepancy could be due to numerical effects. Firstly the coordinates could have been rounded, either when transferring the data between packages, or at some point in the calculation. Secondly, when distances are calculated in C code, depending on how they are handled, there may or may not be rounding effects (this is "GCC bug #323" although it's not really a bug). They would usually be quite small but could be magnified when you take the mean of a large number of values. 

Since 1.3 is of the same order as sqrt(2), I'll bet $10 that the data were rounded to the nearest 1000 metres. (But if I lose, you have to visit Australia to collect :-)

An example would help.

Adrian Baddeley

More information about the R-sig-Geo mailing list