CAssociation · Guide test 257
Ripley K or L envelope test
Uses simulated spatial patterns to test departures from a point process null across distance scales; global envelopes address simultaneous inference.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Point patterns (Clark–Evans, Ripley's K and L envelopes) — Are the points clustered, regularly spaced, or compatible with complete spatial randomness?
In Point patterns (Clark–Evans, Ripley's K and L envelopes), choose Test = Ripley's K and L with an envelope.
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 · Ripley L envelope test
0 is complete spatial randomness; the rest are thrown around cluster centers.
Your data
Simulated with a known share of clustered pointsAbove the band: more neighbors within r than randomness gives (clustering); below: regularity. The band is the global 95% envelope, so leaving it anywhere is one test.
If H₀ were true
- The reference: how T varies across samples when H₀ is true, simulated: 199 CSR patterns of 60 points (Monte Carlo: 199 CSR patterns on the shared stream).
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .685).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- Ripley's isotropic edge correction
- 0 under randomness; positive means clustering at scale r
- the largest departure over all r, compared with simulated random patterns
The verdict
T = 0.014, p = .685
p > α = .050: compatible with H₀
A global envelope: one test over all distances, so reading pointwise bands at every r inflates errors. The scale where L̂ peaks is descriptive, not a second test.
- Statistic
- 0.014
- p-value
- 0.6850
Ripley L envelope test on 60 points in the unit square: T = 0.014, p = .685. The p-value is above α = .050, so the data are compatible with H₀.
Question and hypotheses
H0: a specified spatial point process, often homogeneous Poisson complete spatial randomness.
Assumptions
Known observation window, chosen edge correction and appropriate intensity model; distances evaluated over a prespecified range.
Formula
Parameters and notation
Here eij is the fraction/edge-inclusion factor for the chosen correction. Under planar homogeneous Poisson, K0(r)=πr² and L0(r)=r.
Structure of the method
Estimate K or its L transformation over a declared distance grid using edge corrections, simulate point patterns under a specified null, compute the same curve for each, and compare a prespecified global functional/envelope. Estimating or plotting K/L alone is descriptive; a test requires the simulation/reference step.
Estimated and nuisance parameters
Estimate intensity or other null-model parameters when needed, and the edge-corrected summary curve. A fitted inhomogeneous or interaction model introduces additional nuisance estimation. A plug-in simulation envelope from fitted parameters need not have exact nominal size; composite-null adjustment or refitting may be required.
Settings and design choices
Choose null process, fixed versus random point count, distance range/grid, edge correction, summary transform, global-envelope functional, simulations, and rank. Pointwise and global envelopes answer different questions. More simulations improve attainable p-value resolution and Monte Carlo precision; they do not cure an inappropriate observation window or null process.
Fitting and adaptation
Refit the null and reproduce the complete curve-estimation workflow in a valid composite-null procedure when parameters are estimated. For a simple fully specified simulation null, retain exchangeability of observed and simulated statistics. The supplied global=TRUE call selects global inference, but its actual interval and simulation/rank level should be reported.
Sensitivity and robustness
Inspect intensity gradients, edge-dominated large radii, small counts, duplicate locations, and scale-dependent clustering/regularity. A curve exiting pointwise bands somewhere is not automatically a global rejection. L(r)-r is often easier to read, but a transformation does not alter the need for matched global calibration.
How to use and calibrate
Generate null simulations and compare a prespecified global deviation statistic or global envelope. K/L estimation alone is not a hypothesis test.
Example application
Detect clustering at several spatial scales.
Interpretation and pitfalls
Watch out
Pointwise envelopes do not control error over an entire distance range. Edge and intensity corrections are essential.
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
Global simulation envelope over the specified r range, not pointwise significance at every radius. Simulation envelopes can open a plot device; choose simulation count and rank for the desired attainable significance level.
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)));e<-spatstat.explore::envelope(p,fun=spatstat.explore::Lest,nsim=99,global=TRUE,nrank=1,verbose=FALSE);print(e);plot(e)
"""
# 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()
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)));e<-spatstat.explore::envelope(p,fun=spatstat.explore::Lest,nsim=99,global=TRUE,nrank=1,verbose=FALSE);print(e);plot(e)
Output
Simultaneous critical envelopes for L(r)
and observed value for ‘p’
Edge correction: “iso”
Obtained from 99 simulations of CSR
Envelope based on maximum deviation of L(r) from null value for CSR (known
exactly)
Alternative: two.sided
Significance level of simultaneous Monte Carlo test: 1/100 = 0.01
...........................................................
Math.label Description
r r distance argument r
obs hat(L)[obs](r) observed value of L(r) for data pattern
theo L[theo](r) theoretical value of L(r) for CSR
lo hat(L)[lo](r) lower critical boundary for L(r)
hi hat(L)[hi](r) upper critical boundary for L(r)
...........................................................
Default plot formula: .~r
where “.” stands for ‘obs’, ‘theo’, ‘hi’, ‘lo’
Columns ‘lo’ and ‘hi’ will be plotted as shading (by default)
Recommended range of argument r: [0, 0.25]
Available range of argument r: [0, 0.25]Sources
- spatstat.explore — spatstat.explore · KestAuthor documentation/source reviewed: spatstat.explore 3.8-3.search.r-project.org
- spatstat.explore — spatstat.explore · envelopeAuthor documentation/source reviewed: spatstat.explore 3.8-3.search.r-project.org
- Kestsearch.r-project.org
- envelopesearch.r-project.org
- Lestsearch.r-project.org
- owinsearch.r-project.org
- runifpointsearch.r-project.org
- 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 257, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT257.