| nndist {spatstat} | R Documentation |
Computes the distance from each point to its nearest neighbour in a point pattern. Alternatively computes the distance to the second nearest neighbour, or third nearest, etc.
nndist(X, ...) ## S3 method for class 'ppp' nndist(X, ..., k=1, method="C") ## Default S3 method: nndist(X, Y=NULL, ..., k=1, method="C")
X,Y |
Arguments specifying the locations of
a set of points.
For |
... |
Ignored by |
k |
Integer, or integer vector. The algorithm will compute the distance to the
|
method |
String specifying which method of calculation to use.
Values are |
This function computes the Euclidean distance from each point
in a point pattern to its nearest neighbour (the nearest other
point of the pattern). If k is specified, it computes the
distance to the kth nearest neighbour.
The function nndist is generic, with
a method for point patterns (objects of class "ppp"),
and a default method for coordinate vectors.
There is also a method for line segment patterns, nndist.psp.
The method for point patterns expects a single
point pattern argument X and returns the vector of its
nearest neighbour distances.
The default method expects that X and Y will determine
the coordinates of a set of points. Typically X and
Y would be numeric vectors of equal length. Alternatively
Y may be omitted and X may be a list with two components
named x and y, or a matrix or data frame with two columns.
The argument k may be a single integer, or an integer vector.
If it is a vector, then the kth nearest neighbour distances are
computed for each value of k specified in the vector.
The argument method is not normally used. It is
retained only for checking the validity of the software.
If method = "interpreted" then the distances are
computed using interpreted R code only. If method="C"
(the default) then C code is used.
The C code is faster by two to three orders of magnitude
and uses much less memory.
If there is only one point (if x has length 1),
then a nearest neighbour distance of Inf is returned.
If there are no points (if x has length zero)
a numeric vector of length zero is returned.
To identify which point is the nearest neighbour of a given point,
use nnwhich.
To use the nearest neighbour distances for statistical inference,
it is often advisable to use the edge-corrected empirical distribution,
computed by Gest.
To find the nearest neighbour distances from one point pattern
to another point pattern, use nncross.
Numeric vector or matrix containing the nearest neighbour distances for each point.
If k = 1 (the default), the return value is a
numeric vector v such that v[i] is the
nearest neighbour distance for the ith data point.
If k is a single integer, then the return value is a
numeric vector v such that v[i] is the
kth nearest neighbour distance for the
ith data point.
If k is a vector, then the return value is a
matrix m such that m[i,j] is the
k[j]th nearest neighbour distance for the
ith data point.
An infinite or NA value is returned if the
distance is not defined (e.g. if there is only one point
in the point pattern).
Pavel Grabarnik pavel.grabar@issp.serpukhov.su and Adrian Baddeley Adrian.Baddeley@csiro.au http://www.maths.uwa.edu.au/~adrian/
nndist.psp,
pairdist,
Gest,
nnwhich,
nncross.
data(cells) # nearest neighbours d <- nndist(cells) # second nearest neighbours d2 <- nndist(cells, k=2) # first, second and third nearest d1to3 <- nndist(cells, k=1:3) x <- runif(100) y <- runif(100) d <- nndist(x, y) # Stienen diagram plot(cells %mark% (nndist(cells)/2), markscale=1)