spatstat (version 1.8-6)

nndist: Nearest neighbour distances

Description

Computes the distance from each point to its nearest neighbour in a point pattern.

Usage

nndist(X, ..., method="C")
  nndist.ppp(X, ..., method="C")
  nndist.default(X, Y=NULL, ..., method="C")

Arguments

X,Y
Arguments specifying the locations of a set of points. For nndist.ppp, the argument X should be a point pattern (object of class "ppp"). For nndist.default, typically X and <
...
Ignored by nndist.ppp and nndist.default.
method
String specifying which method of calculation to use. Values are "C" and "interpreted".

Value

  • Numeric vector of the nearest neighbour distances for each point.

Warnings

An infinite value is returned if there is only one point in the point pattern.

Details

This function computes the Euclidean distance from each point in a point pattern to its nearest neighbour (the nearest other point of the pattern).

The function nndist is generic, with a method for point patterns (objects of class "ppp") and a default method.

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 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.

See Also

pairdist, Gest

Examples

Run this code
data(cells)
   d <- nndist(cells)

   x <- runif(100)
   y <- runif(100)
   d <- nndist(x, y)

   # Stienen diagram
   plot(cells %mark% (nndist(cells)/2), markscale=1)

Run the code above in your browser using DataCamp Workspace