# Nearest neighbour distribution

In probability and statistics, a nearest neighbor function, nearest neighbor distance distribution, nearest-neighbor distribution function or nearest neighbor distribution is a mathematical function that is defined in relation to mathematical objects known as point processes, which are often used as mathematical models of physical phenomena representable as randomly positioned points in time, space or both. More specifically, nearest neighbor functions are defined with respect to some point in the point process as being the probability distribution of the distance from this point to its nearest neighboring point in the same point process, hence they are used to describe the probability of another point existing within some distance of a point. A nearest neighbor function can be contrasted with a spherical contact distribution function, which is not defined in reference to some initial point but rather as the probability distribution of the radius of a sphere when it first encounters or makes contact with a point of a point process.
Nearest neighbor function are used in the study of point processes as well as the related fields of stochastic geometry and spatial statistics, which are applied in various scientific and engineering disciplines such as biology, geology, physics, and telecommunications.

## Point process notation

Point processes are mathematical objects that are defined on some underlying mathematical space. Since these processes are often used to represent collections of points randomly scattered in space, time or both, the underlying space is usually d-dimensional Euclidean space denoted here by $\textstyle {\textbf {R}}^{d}$, but they can be defined on more abstract mathematical spaces.
Point processes have a number of interpretations, which is reflected by the various types of point process notation. For example, if a point $\textstyle x$ belongs to or is a member of a point process, denoted by $\textstyle {N}$, then this can be written as:
    $\textstyle x\in {N},$
and represents the point process being interpreted as a random set. Alternatively, the number of points of $\textstyle {N}$ located in some Borel set $\textstyle B$ is often written as:
    $\textstyle {N}(B),$
which reflects a random measure interpretation for point processes. These two notations are often used in parallel or interchangeably.

## Definitions
### Nearest neighbor function

The nearest neighbor function, as opposed to the spherical contact distribution function, is defined in relation to some point of a point process already existing in some region of space. More precisely, for some point in the point process $\textstyle {N}$, the nearest neighbor function is the probability distribution of the distance from that point to the nearest or closest neighboring point.
To define this function for a point located in $\textstyle {\textbf {R}}^{d}$ at, for example, the origin $\textstyle o$, the $\textstyle d$-dimensional ball $\textstyle b(o,r)$ of radius $\textstyle r$ centered at the origin o is considered. Given a point of $\textstyle {N}$ existing at $\textstyle o$, then the nearest neighbor function is defined as:
    $D_{o}(r)=1-P({N}(b(o,r))=1\mid o).$
where $\textstyle P({N}(b(o,r))=1\mid o)$ denotes the conditional probability that there is one point of $\textstyle {N}$ located in $\textstyle b(o,r)$ given there is a point of $\textstyle {N}$ located at $\textstyle o$.
The reference point need not be at the origin, and can be located at an arbitrary point $\textstyle x\in {\textbf {R}}^{d}$. Given a point of $\textstyle {N}$ existing at $\textstyle x$, then the nearest neighbor function, is defined as:
    $D_{x}(r)=1-P({N}(b(x,r))=1\mid x).$

## Examples

Mathematical expressions of the nearest neighbor distribution only exist for a few point processes.

### Poisson point process

For a Poisson point process $\textstyle {N}$ on $\textstyle {\textbf {R}}^{d}$ with intensity measure $\textstyle \Lambda$ the nearest neighbor function is:
    $D_{x}(r)=1-e^{-\Lambda (b(x,r))},$
which for the homogeneous case becomes
    $D_{x}(r)=1-e^{-\lambda |b(x,r)|},$
where $\textstyle |b(x,r)|$ denotes the volume (or more specifically, the Lebesgue measure) of the (hyper) ball of radius $\textstyle r$. In the plane $\textstyle {\textbf {R}}^{2}$ with the reference point located at the origin, this becomes
    $D_{x}(r)=1-e^{-\lambda \pi r^{2}}.$

## Relationship to other functions
### Spherical contact distribution function

In general, the spherical contact distribution function and the corresponding nearest neighbor function are not equal. However, these two functions are identical for Poisson point processes. In fact, this characteristic is due to a unique property of Poisson processes and their Palm distributions, which forms part of the result known as the Slivnyak–Mecke or Slivnyak's theorem.

### J-function

The fact that the spherical distribution function H$_s$(r) and nearest neighbor function D$_o$(r) are identical for the Poisson point process can be used to statistically test if point process data appears to be that of a Poisson point process. For example, in spatial statistics the J-function is defined for all r ≥ 0 as:
    $J(r)={\frac {1-D_{o}(r)}{1-H_{s}(r)}}$
For a Poisson point process, the J function is simply J(r) = 1, hence why it is used as a non-parametric test for whether data behaves as though it were from a Poisson process. It is, however, thought possible to construct non-Poisson point processes for which J(r) = 1, but such counterexamples are viewed as somewhat 'artificial' by some and exist for other statistical tests.
More generally, J-function serves as one way (others include using factorial moment measures) to measure the interaction between points in a point process.