Nearest Neighbour Map as a Function
Compute the nearest neighbour map of an object, and return it as a function.
nnfun(X, ...) ## S3 method for class 'ppp': nnfun(X, ...) ## S3 method for class 'psp': nnfun(X, ...)
- Any suitable dataset representing a two-dimensional
collection of objects,
such as a point pattern (object of class
"ppp") or a line segment pattern (object of class
- Extra arguments are ignored.
For a collection $X$ of two dimensional objects
(such as a point pattern or a line segment pattern),
is the index $i$ identifying the closest member of $X$.
That is, if $i = f(x,y)$ then $X[i]$ is the closest member of
the collection $X$ to the location $(x,y)$.
f <- nnfun(X) returns a function
in the Rlanguage, with arguments
x,y, that represents the
nearest neighbour function of
X. Evaluating the function
in the form
v <- f(x,y), where
are any numeric vectors of equal length containing coordinates of
spatial locations, yields the values of the distance function at these
The result of
f <- nnfun(X) also belongs to the class
"funxy" and to the special class
It can be printed and plotted immediately as shown in the Examples.
nnfun object can be converted to a pixel image
x,y. The function also belongs to the class
"nnfun"which has a method for
"funxy"which has methods for
f <- nnfun(cells) f plot(f) f(0.2, 0.3)