Given a point pattern, this function constructs pixel images giving the distance from each pixel to its k-th nearest neighbour in the point pattern, and the index of the k-th nearest neighbour.
1 2 3
Point pattern (object of class
Integer, or integer vector. The algorithm will find the
Character string specifying what information should be returned.
Either the nearest neighbour distance (
Arguments passed to
Window (object of class
Logical value attesting whether the point pattern
Determines which coordinate to use to sort the point pattern. See Details.
Given a point pattern
X, this function constructs two pixel images:
a distance map giving, for each pixel,
the distance to the nearest point of
a nearest neighbour map giving, for each pixel,
the identifier of the nearest point of
If the argument
k is specified, then the
neighbours will be found.
what="dist" then only the distance map is returned.
what="which" then only the nearest neighbour map
k may be an integer or an integer vector.
If it is a single integer, then the
k-th nearest neighbours
are computed. If it is a vector, then the
neighbours are computed for each entry
k[i]. For example, setting
k=1:3 will compute the nearest, second-nearest and
A pixel image, or a list of pixel images.
By default (if
what=c("dist", "which")), the result is
a list with two components
containing the distance map and the nearest neighbour map.
what="dist" then the result is a real-valued pixel image
containing the distance map.
what="which" then the result is an integer-valued pixel image
containing the nearest neighbour map.
k is a vector of several integers, then the result is
similar except that each pixel image is replaced by a list of
pixel images, one for each entry of
Read this section if you care about the speed of computation.
For efficiency, the algorithm sorts the point pattern
into increasing order of the x coordinate
or increasing order of the the y coordinate.
Sorting is only an intermediate step;
it does not affect the output, which is always given in the same
order as the original data.
By default (if
the sorting will occur on the coordinate that has the larger range of
values (according to the frame of the enclosing window of
sortby = "var"), sorting will occur on the coordinate that
has the greater variance (in the pattern
sortby = "y" will specify that
sorting should occur on the x or y coordinate, respectively.
If the point pattern
X is already
sorted, then the argument
should be set to
sortby should be set
"y" to indicate which coordinate
Ties are possible: there may be two data points
which lie exactly the same distance away from a particular pixel.
This affects the results from
The handling of ties is not well-defined: it is not consistent
between different computers and different installations of R.
If there are ties, then different calls to
may give inconsistent results. For example, you may get a different answer
, \rolf , and Jens Oehlschlaegel