Tests whether specific phenotype pairs are spatially enriched or depleted relative to a random permutation baseline.
Arguments
- object
An
SpatialCellData-classobject.- radius
Numeric. Neighbourhood radius.
- n_perm
Integer. Number of permutations. Default
100.- seed
Integer or
NULL. Random seed.
Examples
set.seed(1)
counts <- matrix(rnorm(200), nrow = 100,
dimnames = list(NULL, c("CD3", "CD8")))
coords <- data.frame(x = runif(100, 0, 500), y = runif(100, 0, 500))
meta <- data.frame(cell_id = 1:100, sample_id = "s1",
phenotype = sample(c("A", "B"), 100, replace = TRUE))
obj <- CreateSpatialObject(counts, coords, meta)
NeighbourhoodEnrichment(obj, radius = 50, n_perm = 10)
#> from to observed mean_expected z_score p_value
#> 1 A A 58 68.0 -0.9977852 0.3183835
#> 2 B A 79 77.9 0.1268387 0.8990681
#> 3 A B 79 77.9 0.1268387 0.8990681
#> 4 B B 92 84.2 0.5196665 0.6032960