Skip to contents

Implements a two–segment piece-wise linear method to identify the knee (a.k.a. elbow) in a curve such as the reconstruction-error profile obtained when varying the number of archetypes.

Usage

find_knee_pt(y, x = seq_along(y), make_plot = FALSE)

Arguments

y

Numeric vector of \(y\)-values (must have ≥ 3 points).

x

Numeric vector of \(x\)-values (defaults to seq_along(y)). Need not be sorted.

make_plot

Logical; if TRUE, a ggplot2 graphic is produced showing the curve and the detected knee.

Value

A list with components

knee_x

The \(x\)-coordinate of the knee.

idx

Integer index (1-based) of that knee in the supplied vectors.

error_curve

Numeric vector of summed absolute-error values for every tested breakpoint (length = length(y) - 2).

Examples

ks  <- 2:25
err <- exp(-ks) + 0.05 * rnorm(length(ks))
knee_pt(err, ks, make_plot = TRUE)
#> Error in knee_pt(err, ks, make_plot = TRUE): could not find function "knee_pt"