Compares the empirical nearest-neighbour distance distribution \(\hat G(y) = \#(y_i \le y) / n\) against complete spatial randomness, through the supremum distance of a Kolmogorov-Smirnov statistic.
Arguments
- coords
Numeric matrix of event locations (n x d). A vector is read as n points on a line.
- window
Observation region, as
d(min, max) pairs: ad x 2matrix or a flat vector of length2 * d. Defaults to the bounding box ofcoords. Give it explicitly when the true region is larger than the observed extent, since the bounding box of the data is slightly too small and inflates the simulated intensity.- cdf
Optional function giving the null CDF of the nearest-neighbour distance. Supplying it replaces the simulation with a one-sample KS test, which suits only the case where edge effects are negligible or already corrected.
- nsim
Number of CSR patterns simulated in
window. Default 199. Ignored whencdfis given.
Details
The reference distribution comes from simulation rather than a closed form. Under CSR on the whole plane the nearest-neighbour distance follows \(G(y) = 1 - \exp(-\lambda\pi y^2)\), but a real pattern is observed inside a bounded window, and points near the edge have no neighbours beyond it. Their nearest-neighbour distances are biased upward, so the closed form no longer holds. Schabenberger & Gotway accordingly compare against the theoretical \(G(h)\) "or, if \(G(h)\) is not attainable, against the average empirical distribution function from the simulation". Simulating inside the same window makes the edge effect common to data and reference, so it cancels.
The p-value is the rank of the observed statistic among the simulated ones, \(p = (1 + \#\{D_i \ge D_{obs}\}) / (1 + nsim)\). That is the convention behind the same authors' worked example: with 200 simulations and none exceeding the observed value, they report p = 0.00498 = 1/201.
This is a first-order (nearest-neighbour) test. For the second-order
Ripley's K comparison against the same null, see
morie_tps_ripley_k.
Mirrors morie.fn.csrkstst on the Python side.
