adjacency: Revert to density estimate

This reverts commit 23bb499d3a.
This commit is contained in:
Elias Projahn 2022-01-13 18:35:02 +01:00
parent 0087f83247
commit 8cda3e8e83
4 changed files with 50 additions and 4 deletions

View file

@ -1,7 +1,31 @@
#' Find the densest value in the data.
#'
#' This function assumes that data represents a continuous variable and finds
#' a single value with the highest estimated density. This can be used to
#' estimate the mode of the data. If there is only one value that value is
#' returned. If multiple density maxima with the same density exist, their mean
#' is returned.
#'
#' @param data The input data.
#'
#' @return The densest value of data.
#'
#' @export
densest <- function(data) {
as.numeric(if (length(data) <= 0) {
NULL
} else if (length(data) == 1) {
data
} else {
density <- stats::density(data)
mean(density$x[density$y == max(density$y)])
})
}
#' Score genes based on their proximity to the reference genes.
#'
#' @param estimate A function that will be used to summarize the distance
#' values for each gene. By default, [median()] is used.
#' values for each gene. See [densest()] for the default implementation.
#' @param combination A function that will be used to combine the different
#' distances to the reference genes. By default [min()] is used. That means
#' the distance to the nearest reference gene will be scored.
@ -9,7 +33,7 @@
#' @return An object of class `geposan_method`.
#'
#' @export
adjacency <- function(estimate = stats::median, combination = min) {
adjacency <- function(estimate = densest, combination = min) {
method(
id = "adjacency",
name = "Adjacency",