Exact Expectation of Complete Spatial Randomness for Nearest Neighbor G(r): A Scalable Alternative to Permutations
Alex C. SoupiriD, Brandon J. ManleyiD, Lauren Cole PeresiD, Brooke L. FridleyiD, Julia WrobeliD
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 G(r) 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 G(r) 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 G(r) 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 G(r) 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.
02 /Specification & Classification
Click any tag to browse matching papers- Citations
- 1
- Assay
- Research Focus
- Approach
Reproducibility ledger
Nobody has reported trying to reproduce this paper yet. Did you replicate an experiment or run the code? Your report saves the next lab a week.
Sign in to file a reproducibility report.
Related papers
- A Spatial Omnibus Test (SPOT) for Spatial Proteomic Data
Sarah Samorodnitsky, Katie Marie Campbell, … Michael C. Wu·BioinformaticsPeer-reviewed·Jun 28, 2024
- scSpatialSIM: a simulator of spatial single-cell molecular data
Alex C. Soupir, Julia Wrobel, … Brooke L. Fridley·SoftwareXPeer-reviewed·Jun 6, 2025
- Using random forests to uncover the predictive power of distance-varying cell interactions in tumor microenvironments
Jeremy VanderDoes, Claire Marceaux, … Jack D. Hywood·PLoS Computational BiologyPeer-reviewed·Jun 14, 2024
- LRSPAT: A low-rank framework for spatial omics statistics
Hildreth Robert Frost·bioRxiv·Aug 31, 2026
- stCNASim: Allele-aware spatial RNA-seq simulator enables systematic benchmarking of copy number inference
Xianjie Huang, Rongting Huang, … Yuanhua Huang·bioRxiv·Aug 11, 2026
- Estimating conditional cell population associations across tumor density trajectory in three dimensional tissue images
Sagnik Bhadury, Arvind Rao·Scientific ReportsPeer-reviewed·Sep 28, 2026