Estimate the local densities for all cells in a high-dimensional cytometry dataset.
Source:R/utils.R
tof_estimate_density.Rd
This function is a wrapper around tidytof's tof_*_density() function family. It performs local density estimation on high-dimensional cytometry data using a user-specified method (of 3 choices) and each method's corresponding input parameters.
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`.
- 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".
- 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 arguments to pass to the `tof_*_density()` function family member corresponding to the chosen `method`.
- augment
A boolean value indicating if the output should column-bind the local density estimates of each cell as a new column in `tof_tibble` (TRUE; the default) or if a single-column tibble including only the local density estimates should be returned (FALSE).
- method
A string indicating which local density estimation method should be used. Valid values include "mean_distance", "sum_distance", and "spade".
Value
A `tof_tbl` or `tibble` If augment = FALSE, it will have a single column encoding the local density estimates for each cell in `tof_tibble`. If augment = TRUE, it will have ncol(tof_tibble) + 1 columns: each of the (unaltered) columns in `tof_tibble` plus an additional column encoding the local density estimates.
See also
Other local density estimation functions:
tof_knn_density()
,
tof_spade_density()
Examples
sim_data <-
dplyr::tibble(
cd45 = rnorm(n = 1000),
cd38 = rnorm(n = 1000),
cd34 = rnorm(n = 1000),
cd19 = rnorm(n = 1000)
)
# perform the density estimation
tof_estimate_density(tof_tibble = sim_data, method = "spade")
#> # A tibble: 1,000 × 5
#> cd45 cd38 cd34 cd19 .spade_density
#> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 0.760 0.167 -0.222 -0.928 1
#> 2 0.0804 -0.569 -0.324 1.58 1
#> 3 0.767 0.837 0.473 0.417 1
#> 4 1.05 -1.14 0.0856 -0.0271 1
#> 5 -1.53 -0.352 0.710 0.000200 1
#> 6 0.371 0.875 -0.0882 0.514 1
#> 7 0.655 -2.26 0.0972 -0.120 1
#> 8 0.501 1.31 0.876 -0.0215 1
#> 9 -0.286 -0.307 1.53 -0.0930 1
#> 10 -0.0880 -1.71 -0.516 0.705 1
#> # ℹ 990 more rows
# perform the density estimation with a smaller search radius around
# each cell
tof_estimate_density(
tof_tibble = sim_data,
alpha_multiplier = 2,
method = "spade"
)
#> # A tibble: 1,000 × 5
#> cd45 cd38 cd34 cd19 .spade_density
#> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 0.760 0.167 -0.222 -0.928 1
#> 2 0.0804 -0.569 -0.324 1.58 1
#> 3 0.767 0.837 0.473 0.417 1
#> 4 1.05 -1.14 0.0856 -0.0271 1
#> 5 -1.53 -0.352 0.710 0.000200 0.8
#> 6 0.371 0.875 -0.0882 0.514 1
#> 7 0.655 -2.26 0.0972 -0.120 0.4
#> 8 0.501 1.31 0.876 -0.0215 0.9
#> 9 -0.286 -0.307 1.53 -0.0930 0.8
#> 10 -0.0880 -1.71 -0.516 0.705 1
#> # ℹ 990 more rows