This function calculates the best partition to cut a dendrogram based on the higher relative loss of inertia criteria. This criteria was originaly proposed by the HCPC function of the package FactoMineR.

best.cutree(hc, min = 3, max = 20, loss = FALSE, graph = FALSE, ...)

Arguments

hc

a clustering tree (an object of class hclust, dendrogram or agnes)

min

the minimum number of classes

max

the maximum number of classes

loss

if TRUE, will return the relative loss of inertia of each partition instead of the best partition

graph

if TRUE, will plot the relative loss of inertia of each partition, the best partition being indicated in black and the second best in grey

...

additional arguments sent to plot (if graph = TRUE)

See also

Examples

hc <- hclust(dist(USArrests), "ave")
best.cutree(hc)
#> [1] 3
best.cutree(hc, loss = TRUE)
#>         3         4         5         6         7         8         9        10 
#> 0.9162296 0.9204839 0.9390592 0.9468502 0.9445603 0.9455332 0.9447788 0.9428372 
#>        11        12        13        14        15        16        17        18 
#> 0.9478849 0.9517658 0.9509931 0.9486210 0.9462873 0.9454169 0.9430228 0.9450606 
#>        19        20 
#> 0.9452040 0.9456931 
best.cutree(hc, graph = TRUE)

#> [1] 3
best.cutree(hc, graph = TRUE, min = 6, max = 15)

#> [1] 10