Related Experiment Video
Updated: Sep 15, 2025

A Psychophysics Paradigm for the Collection and Analysis of Similarity Judgments
Published on: March 1, 2022
Exact Expectation of Complete Spatial Randomness for Nearest Neighbor G(r): A Scalable Alternative to Permutations
Abstract:
Spatial analysis is becoming increasingly important for studies, from epidemiology to tissue biology, as technologies advance and experimental costs decrease. However, the widespread use of spatial metrics such as Nearest Neighbor is affected by the fact that biological systems rarely satisfy the assumption of stationarity, which is required to appropriately use theoretical complete spatial randomness (CSR) measures. As a result researchers often use computationally expensive permutations to empirically estimate CSR for subsets of points or cells. Here, we present closed form analytical solutions for both the mean and variance of the sample-specific CSR for Nearest Neighbor to allow for fast and reproducible calculation without permutations. Using a multiplex immunofluorescence sample of clear cell renal cell carcinoma, we show that the theoretical for cytotoxic T cells overestimates CSR at low radii (due to spatial constraints between cells) while drastically underestimating CSR at radii between 20 and 90 pixels. In a simulated sample of 30 points, our analytical solution for the mean is identical to the average of measured on all 142,506 unique combinations of 5 marked (or positive) points. On the real clear cell renal cell carcinoma sample, our exact CSR is similar in speed to estimating CSR with 1000 permutations while our optimized Rcpp implementation is ~30x faster and consuming ~20x less memory than 1000 permutations. This permutation-free approach dramatically enhances computational efficiency and reproducibility, enabling scalable and reproducible analysis for studies in epidemiology, multiplex immunofluorescence, spatial transcriptomics, and related fields where accurate, sample-specific null expectations are important for comparisons.
Related Concept Videos
Random Error
Random Variables
Uppercase letters such as X or Y denote a random variable. Lowercase letters like x or y denote the value of a random variable. If X is a random variable, then X is written in words, and x is given as a number.
For example, let X = the...
Expected Frequencies in Goodness-of-Fit Tests
Wald-Wolfowitz Runs Test II
For binary data, runs are identified using symbols such as + and −, or equivalently, 1s and...
Randomized Experiments
Simple randomization
Simple...
Propagation of Uncertainty from Random Error

