Skip to contents

Quantifies cell-specific changes in the Local Density Factor (LDF) before and after data integration or between reference and simulated datasets.

Usage

calc_ldf_diff(coords_pre, coords_post, k = 15, h = 1, c = 1)

Arguments

coords_pre

Matrix of coordinates before integration / reference (cells x dimensions).

coords_post

Matrix of coordinates after integration / simulated (cells x dimensions).

k

Number of nearest neighbors. Default is 15.

h

Bandwidth parameter for Gaussian kernel. Default is 1.

c

Scaling constant. Default is 1.

Value

A named list:

diff

Numeric vector of absolute LDF differences per cell

mean_ldf_diff

Mean absolute LDF difference (lower indicates better structure preservation)

median_ldf_diff

Median absolute LDF difference

ldf_pre

LDF in pre-integration / reference space

ldf_post

LDF in post-integration / simulated space

Examples

coords <- matrix(stats::rnorm(100), 50, 2)
batch <- factor(rep(c("B1", "B2"), length.out = 50))
calc_ldf_diff(coords, coords)
#> $diff
#>  [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
#> [39] 0 0 0 0 0 0 0 0 0 0 0 0
#> 
#> $mean_ldf_diff
#> [1] 0
#> 
#> $median_ldf_diff
#> [1] 0
#> 
#> $ldf_pre
#>  [1] 0.5017057 0.6336127 0.4768540 0.4786618 0.6644306 0.4940799 0.4874089
#>  [8] 0.5089179 0.6061925 0.5056316 0.6499191 0.7207448 0.5081255 0.4840643
#> [15] 0.7306457 0.5442970 0.4925471 0.5061452 0.4919572 0.7784668 0.4837000
#> [22] 0.4772409 0.6631685 0.4904679 0.4910758 0.5630630 0.5436738 0.4894341
#> [29] 0.5228682 0.5992504 0.5076411 0.4955855 0.5925004 0.4905021 0.6178548
#> [36] 0.4929881 0.4981188 0.5427727 0.8161017 0.7869193 0.5382792 0.5305093
#> [43] 0.5388853 0.4913033 0.6019096 0.5938351 0.5138456 0.5740182 0.4909936
#> [50] 0.5203884
#> 
#> $ldf_post
#>  [1] 0.5017057 0.6336127 0.4768540 0.4786618 0.6644306 0.4940799 0.4874089
#>  [8] 0.5089179 0.6061925 0.5056316 0.6499191 0.7207448 0.5081255 0.4840643
#> [15] 0.7306457 0.5442970 0.4925471 0.5061452 0.4919572 0.7784668 0.4837000
#> [22] 0.4772409 0.6631685 0.4904679 0.4910758 0.5630630 0.5436738 0.4894341
#> [29] 0.5228682 0.5992504 0.5076411 0.4955855 0.5925004 0.4905021 0.6178548
#> [36] 0.4929881 0.4981188 0.5427727 0.8161017 0.7869193 0.5382792 0.5305093
#> [43] 0.5388853 0.4913033 0.6019096 0.5938351 0.5138456 0.5740182 0.4909936
#> [50] 0.5203884
#>