tof_knn_density: Estimate cells' local densities using K-nearest-neighbor...

tof_knn_densityR Documentation

Estimate cells' local densities using K-nearest-neighbor density estimation

Description

This function uses the distances between a cell and each of its K nearest neighbors to estimate local density of each cell in a 'tof_tbl' or 'tibble' containing high-dimensional cytometry data.

Usage

tof_knn_density(
  tof_tibble,
  distance_cols = where(tof_is_numeric),
  num_neighbors = min(15L, nrow(tof_tibble)),
  distance_function = c("euclidean", "cosine", "l2", "ip"),
  estimation_method = c("mean_distance", "sum_distance"),
  normalize = TRUE,
  ...
)

Arguments

tof_tibble

A 'tof_tbl' or a 'tibble'.

distance_cols

Unquoted names of the columns in 'tof_tibble' to use in calculating cell-to-cell distances during the local density estimation for each cell. Defaults to all numeric columns in 'tof_tibble'.

num_neighbors

An integer indicating the number of nearest neighbors to use in estimating the local density of each cell. Defaults to the minimum of 15 and the number of rows in 'tof_tibble'.

distance_function

A string indicating which distance function to use for calculating cell-to-cell distances during local density estimation. Options include "euclidean" (the default) and "cosine".

estimation_method

A string indicating how the relative density for each cell should be calculated from the distances between it and each of its k nearest neighbors. Options are "mean_distance" (the default; estimates the relative density for a cell's neighborhood by taking the negative average of the distances to its nearest neighbors) and "sum_distance" (estimates the relative density for a cell's neighborhood by taking the negative sum of the distances to its nearest neighbors).

normalize

A boolean value indicating if the vector of local density estimates should be normalized to values between 0 and 1. Defaults to TRUE.

...

Additional optional arguments to pass to tof_find_knn.

Value

A tibble with a single column named ".knn_density" containing the local density estimates for each input cell in 'tof_tibble'.

See Also

Other local density estimation functions: tof_estimate_density(), tof_spade_density()


keyes-timothy/tidytof documentation built on Aug. 28, 2024, 8:37 a.m.