Learn R Programming

DUBStepR (version 1.2.0)

findElbow: Find the Elbow in a Curve

Description

This utility function finds the elbow in a curve which is concave relative to a line drawn between the first and last points. The elbow is defined as the point with the greatest orthogonal distance from that line.

Usage

findElbow(y, ylab = "y values", plot = FALSE, returnIndex = TRUE)

Arguments

y

Numeric vector of y values for the curve.

ylab

Y-axis label.

plot

Logical. Should a plot be made?

returnIndex

Logical. Should the return value be the index of the elbow point?

Value

If returnIndex = TRUE, the index of the elbow point. If returnIndex = FALSE, a data frame containing an index values (x), the y values passed to the function, and the the orthogonal distances of the y values from the line connecting the first and last points. which.max(data_frame_name$dist) will give the index of the elbow point.

Warning

This function makes some simple checks that the data is concave as defined above. Even so, it may give answers in some cases that are not valid. Please check on typical data that you encounter to verify that it works in your cases.

References

The concept of this function is based on the clever idea in the Stackoverflow post at stackoverflow.com/a/2022348/633251 and relies on code posted at paulbourke.net/geometry/pointlineplane/pointline.r (referenced in the SO post). Minor modifications to the code were made to that code in order to vectorize it.