Computes the nearest neighbour distance from each cell of one phenotype
to cells of another phenotype. With from equal to to, the distance is to
the nearest other cell of that phenotype.
Arguments
- object
An
SpatialCellData-classobject.- from
Character. Source phenotype.
- to
Character. Target phenotype.
- 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
counts <- matrix(rnorm(60), nrow = 30,
dimnames = list(NULL, c("CD3", "CD8")))
coords <- data.frame(x = runif(30, 0, 100), y = runif(30, 0, 100))
meta <- data.frame(cell_id = 1:30, sample_id = "s1",
phenotype = rep(c("A", "B", "C"), each = 10))
obj <- CreateSpatialObject(counts, coords, meta)
CrossNNDistance(obj, from = "A", to = "B")
#> <phenoscapR> Cross nearest-neighbour distances
#> A -> B : 10 cells
#> median 18, mean 20.3, range [1.42, 39.6]