Skip to content

CAssociation · Guide test 256

Clark–Evans nearest neighbor test

Tests a point pattern’s clustering or regularity against complete spatial randomness, with suitable edge handling.

Runs in CodeSplashPython (calls R) example not runR example validated

Do it in CodeSplash

In the app, set it up in Analyze with this method:

In Point patterns (Clark–Evans, Ripley's K and L envelopes), choose Test = Clark–Evans.

Do it in CodeSplash Run this test on your own data, in Python or R.

Bench

Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.

Bench · Clark–Evans test

60
0.30

0 is complete spatial randomness; the rest are thrown around cluster centers.

4
0.050
0.050

Alternative

Your data

Simulated with a known share of clustered points
mean 0.066

Each point is linked to its nearest neighbor. Clustered patterns have short links (R < 1); regular patterns long ones (R > 1).

If H₀ were true

z = −0.39
  1. The reference: how z varies across samples when H₀ is true (normal approximation with Donnelly's edge correction).
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .697).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

R=rˉE(rˉ),E(rˉ)=12An+(0.0514+0.0412n)Pn,z=rˉ−E(rˉ)SER=\frac{\bar r}{E(\bar r)},\quad E(\bar r)=\tfrac12\sqrt{\tfrac An}+\Big(0.0514+\tfrac{0.0412}{\sqrt n}\Big)\tfrac Pn,\qquad z=\frac{\bar r-E(\bar r)}{\mathrm{SE}}

With your numbers

rˉ=0.07, E(rˉ)=0.07, SE=0.0050,R=0.97, z=(−0.39)\bar r = 0.07,\ E(\bar r) = 0.07,\ \mathrm{SE} = 0.0050,\quad R = 0.97,\ z = (-0.39)
rˉ\bar r
mean nearest-neighbor distance
A, PA,\ P
the window's area and perimeter (Donnelly's edge correction)
RR
below 1 clustered, above 1 regular

The verdict

z = −0.39, p = .697, R = 0.97

p > α = .050: compatible with H₀

Effect size: Clark–Evans ratio (< 1 clustered) R = 0.972

One number for the whole window at the smallest scale; it misses clustering at larger distances. The window must match the area that was searched.

Statistic
−0.389
p-value
0.6974
Clark–Evans test on 60 points in the unit square: z = −0.39, p = .697, R = 0.97. The p-value is above α = .050, so the data are compatible with H0.

Clark–Evans test on 60 points in the unit square: z = −0.39, p = .697, R = 0.97. The p-value is above α = .050, so the data are compatible with H₀.

Question and hypotheses

H0: complete spatial randomness from a homogeneous Poisson point process.

Assumptions

Planar point locations in a known observation window; appropriate boundary correction and intensity estimate.

Formula

R=rˉNN1/(2λ)R=\frac{\bar r_{NN}}{1/(2\sqrt\lambda)}

Parameters and notation

r̄NN is mean nearest-neighbor distance; λ is point intensity. R<1 suggests clustering,R>1 regular spacing.

Structure of the method

Compute every point’s nearest-neighbor distance, average them, compare with the homogeneous-Poisson mean based on intensity, and apply the chosen edge and reference correction. The observation window is a fundamental input: unknown boundaries or unrecorded inaccessible areas change expected distances.

Estimated and nuisance parameters

Estimate intensity from observed count and window area when not fixed externally, plus mean nearest-neighbor distance. There is no fitted interaction coefficient. Conditional Monte Carlo fixes the observed count and places points uniformly in the same window; unconditional Poisson simulation instead permits count variation and answers a different null formulation.

Settings and design choices

Choose correction, analytic versus Monte Carlo method, conditioned/unconditioned count, alternative, and simulation count. Donnelly correction is suited to its supported window geometry; a rectangular demonstration does not validate its use for arbitrary polygons. Do not choose an edge correction according to the most favorable p value.

Fitting and adaptation

Adapt by defining the true observation window, handling duplicate coordinates transparently, and selecting a valid intensity model. The documented MonteCarlo route conditions on count. For an inhomogeneous intensity process, use a suitable alternative diagnostic/model rather than interpreting clustering relative to homogeneous CSR as evidence of interaction.

Sensitivity and robustness

Inspect boundary bias, coordinate accuracy, duplicate points, missing regions, small counts, and spatial intensity gradients. Rejection below one can reflect population-density variation rather than attraction between events. The ratio summarizes nearest-neighbor scale only and may miss structure at longer distances captured by other point-process summaries.

How to use and calibrate

Use a corrected analytic normal approximation or simulate Poisson/uniform point patterns in the same window, conditioning on count if intended.

Example application

Assess whether point events are clustered or regularly spaced.

Interpretation and pitfalls

Watch out

Uncorrected boundaries inflate distances. Spatially varying intensity can mimic interaction and requires an inhomogeneous null.

What changed in edition 2

  • New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.

Python and R

Point pattern in a unit-square observation window; edge correction and CSR null must match the sampling window.

Python · invokes R

Not run — Executed end to end through Rscript · needs Python standard library + Rscript; R packages: spatstat.explore, spatstat.geom, spatstat.random

# Python launcher for the complete R implementation below.
# Requires Rscript on PATH and the listed R packages.
import shutil
import subprocess
rscript = shutil.which("Rscript")
if rscript is None:
    raise RuntimeError("Install R and make Rscript available on PATH.")
r_code = r"""
set.seed(2026)
p<-spatstat.random::runifpoint(80,win=spatstat.geom::owin(c(0,1),c(0,1)));print(spatstat.explore::clarkevans.test(p,correction="Donnelly",alternative="two.sided"))
"""
# No shell interpolation. A failed R execution raises an error in Python.
result = subprocess.run([rscript, "--vanilla", "-"], input=r_code,
                        text=True, capture_output=True)
print(result.stdout)
if result.stderr:
    print(result.stderr)
result.check_returncode()
R

Validated — Executed successfully in the validation environment · needs spatstat.explore, spatstat.geom, spatstat.random

set.seed(2026)
p<-spatstat.random::runifpoint(80,win=spatstat.geom::owin(c(0,1),c(0,1)));print(spatstat.explore::clarkevans.test(p,correction="Donnelly",alternative="two.sided"))
Output
	Clark-Evans test
	Donnelly correction
	Z-test

data:  p
R = 0.98664, p-value = 0.8103
alternative hypothesis: two-sided

Sources

Statistics guide v4 (historical):
Python: Executed end to end through Rscript · R: Executed successfully in the validation environment
Reference's record:
Edition 2 review: Python: skip · R: not executed (Rscript unavailable); why not run: Python: Python-to-R bridge; Rscript is unavailable. R code was not executed. Python: Not run in the reference's review: Python-to-R bridge; Rscript is unavailable. R code was not executed. R: Reviewed but not run: R wasn't available to the reference's authors.

From the CodeSplash statistics guide (v4), entry 256, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT256.