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.- by_sample
Logical. If
TRUEand the object holds several samples, the statistic is computed per sample and returned as a named list. DefaultFALSE; otherwise a single sample is required.
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)
#> <phenoscapR> Neighbourhood enrichment (permutation test)
#> top co-localised pairs (by z-score):
#> from to z_score p_value
#> B B 0.5196665 0.6032960
#> B A 0.1268387 0.8990681
#> A B 0.1268387 0.8990681
#> A A -0.9977852 0.3183835