Skip to contents

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.

Usage

morie_csr_nn_test(coords, window = NULL, cdf = NULL, nsim = 199L)

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: a d x 2 matrix or a flat vector of length 2 * d. Defaults to the bounding box of coords. 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 when cdf is given.

Value

Named list with statistic, p_value, nn_distances, mean_nn, n, nsim, method.

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.

References

Schabenberger O & Gotway CA (2005). Statistical Methods for Spatial Data Analysis. Chapman & Hall/CRC, sections 3.3-3.4.

Diggle PJ (2003). Statistical Analysis of Spatial Point Patterns, 2nd edn. Arnold, London.

Examples

set.seed(1)
morie_csr_nn_test(matrix(runif(200), 100, 2), nsim = 49)$p_value
#> [1] 0.1