rank_threshold: Calculate threshold value on ranked input

View source: R/rank-threshold.R

rank_thresholdR Documentation

Calculate threshold value on ranked input

Description

Calculate a threshold value of a vector based on the unimodal threshold method described by Rosin 2001 for image thresholding. Conceptually, the method attempts to draw a line from the peak of the distribution to the tail and calculates the maximum distance from a point to that line. The point where the distance is maximized is the threshold.

Usage

rank_threshold(x, show = FALSE)

Arguments

x

numeric vector of values.

show_plot

logical. default (FALSE). Show the scatter plot for the given distribution.

Details

The function takes a numeric vector and ranks the values using data.table::frank. with ties.method = "first". The returned values for the threshold "x" and "y", indicate the rank of the data point and the value at that rank, respectively.

Value

named vector containing "x" and "y" position of calculated threshold

Examples

# simulate exponential counts
x <- (1:100)^exp(3)
rank_threshold(x, show = TRUE)

jcalendo/coriell documentation built on March 5, 2025, 5:42 a.m.