Calculates the mixing metric originally proposed in Seurat (Stuart et al., Cell 2019) and adapted by CellMixS. For each cell, finds the rank of the k_pos-th neighbor from each batch in the sorted neighborhood, and computes the median rank across batches.
Value
A named list:
- mixing_metrics
Numeric vector of median ranks per cell
- mean_mixing_metric
Mean mixing rank (lower indicates better mixing)
- median_mixing_metric
Median mixing rank
Examples
coords <- matrix(stats::rnorm(100), 50, 2)
batch <- factor(rep(c("B1", "B2"), length.out = 50))
calc_seurat_mixing_metric(coords, batch)
#> $mixing_metrics
#> [1] 10.5 8.5 9.5 9.0 9.5 11.5 11.0 10.5 9.5 9.0 10.0 9.5 10.0 10.0 9.0
#> [16] 10.0 9.5 9.0 10.0 11.5 10.5 10.5 10.0 10.0 9.5 9.5 9.0 9.5 9.5 9.0
#> [31] 9.0 10.0 9.5 10.0 11.0 9.0 10.0 9.5 9.5 8.0 10.5 10.5 9.5 10.0 9.0
#> [46] 10.0 9.5 10.0 9.0 9.5
#>
#> $mean_mixing_metric
#> [1] 9.74
#>
#> $median_mixing_metric
#> [1] 9.5
#>
