Skip to contents

Computes the Local Density Estimate (LDE) and Local Density Factor (LDF) using a Gaussian kernel over reachability distances in the k-NN neighborhood, adapted from Latecki et al. and CellMixS.

Usage

calc_ldf(coords, k = 15, h = 1, c = 1)

Arguments

coords

Matrix of coordinates / embeddings (cells x dimensions).

k

Number of nearest neighbors. Default is 15.

h

Bandwidth parameter for Gaussian kernel. Default is 1.

c

Scaling constant for comparison of LDE to neighboring observations. Default is 1.

Value

A named list:

lde

Local density estimate for each cell

ldf

Local density factor for each cell

Examples

coords <- matrix(stats::rnorm(100), 50, 2)
batch <- factor(rep(c("B1", "B2"), length.out = 50))
calc_ldf(coords)
#> $lde
#>  [1] 0.06729527 0.07281274 0.01859922 0.08066355 0.07193974 0.02132812
#>  [7] 0.02776291 0.05673873 0.06801104 0.06288027 0.06838472 0.07142370
#> [13] 0.06347303 0.09965548 0.09568406 0.07273004 0.10445226 0.05247818
#> [19] 0.08937959 0.06353787 0.09353828 0.05683191 0.09991447 0.05422705
#> [25] 0.06962411 0.08582831 0.07527452 0.06421791 0.10641918 0.06655596
#> [31] 0.10543038 0.09997964 0.06374574 0.09786144 0.08790517 0.09876695
#> [37] 0.04512153 0.05205730 0.06084412 0.08970962 0.04762267 0.10635577
#> [43] 0.09780365 0.09372754 0.04695030 0.05878865 0.06345496 0.08372361
#> [49] 0.10165628 0.09330914
#> 
#> $ldf
#>  [1] 0.5311334 0.5549406 0.7777621 0.5328495 0.5134540 0.7311257 0.6998601
#>  [8] 0.5590328 0.5517190 0.5524725 0.5403090 0.5262261 0.5313970 0.4837206
#> [15] 0.4884443 0.5462771 0.4822015 0.6104103 0.4947437 0.5339757 0.4888876
#> [22] 0.6110768 0.4871243 0.5582501 0.5250692 0.4995939 0.5419516 0.5421524
#> [29] 0.4713221 0.5243788 0.4831776 0.4927956 0.5440863 0.4891815 0.5054740
#> [36] 0.4891661 0.5908283 0.6292508 0.5479760 0.4944047 0.5756359 0.4801596
#> [43] 0.4770288 0.4929933 0.6104528 0.5413921 0.5858664 0.5078567 0.4883516
#> [50] 0.4895431
#>