Learn R Programming

SCDA (version 0.0.1)

Elbow_finder: Automatically selects the optimal number of clusters based on elbow criterion.

Description

Automatically selects the optimal number of clusters (X-axis) based on elbow criterion computed on a metric (Y-axis). Potential metrics are the AIC and the BIC. The function can be applied to any other context in which the objective is to find the optimal X producing an elbow in Y.

Usage

Elbow_finder(x, y, Plot = TRUE)

Value

Returns the following outputs:

  • x_max_dist: optimal value of x (i.e., the x satisfying the elbow rule)

  • y_max_dist: optimal value of y (i.e., the y satisfying the elbow rule)

  • Scatterplot (non-compulsory) of x and y with connecting lines and vertical line in correspondence of the optimal value of x.

Arguments

x

Numeric (m x 1) vector of integer values (usually, the number of clusters from 1 to G)

y

Numeric (m x 1) vector of values (usually, the criterion values) associated with the number of groups.

Plot

Logical value (TRUE or FALSE). If Plot = TRUE a plot of the relationship between x and y is produced. The plot is a scatterplot with connecting lines. A vertical line is depicted in correspondence of the optimal value of x.

Examples

Run this code
## Compute the Elbow criterion on two generic vectors x and y
x <- 1:10
y <- c(10,9,6,5,4,3,2,1,1,1)
Elbow_finder(x,y,Plot = TRUE)


Run the code above in your browser using DataLab