```
kmeans_performance <- list()
for (i in 2:10) {
kmeans_performance[[i - 1]] <-
fpc::cluster.stats(
d = dist(pca_scores),
clustering = kmeans_results[[i - 1]]$cluster,
G2 = TRUE,
G3 = TRUE,
aggregateonly = TRUE
) %>% unlist
}
df_kmeans_performance <-
data.frame(Reduce(rbind, kmeans_performance))
kmeans_metrics_names <- c(
"n" = "number of cases",
"cluster.number" = "number of points",
"min.cluster.size" = "size of smallest cluster",
"noisen" = "number of noise points", # Not relevant for kmeans
"average.between" = "average distance between clusters",
"average.within" = "average distance within clusters", # (reweighted so that every observation, rather than every distance, has the same weight)
"max.diameter" = "maximum cluster diameter",
"min.separation" = "minimum cluster separation",
"ave.within.cluster.ss" = "within clusters sum of squares", # generalisation
"avg.silwidth" = "average silhouette width",
"g2" = "Goodman Kruskal's Gamma coefficient", # See Milligan and Cooper (1985), Gordon (1999, p. 62).
"g3" = "G3 coefficient", # See Gordon (1999, p. 62)
"pearsongamma" = "Normalized gamma", # correlation between distances and a 0-1-vector where 0 means same cluster, 1 means different clusters. see Halkidi et al. (2001)
"dunn" = "Dunn index", # minimum separation / maximum diameter, Dunn index, see Halkidi et al. (2002).
"dunn2" = "Dunn index 2", # minimum average dissimilarity between two cluster / maximum average within cluster dissimilarity, another version of the family of Dunn indexes
"entropy" = "entropy of distribution of cluster memberships", # see Meila(2007)
"wb.ratio" = "average within / average between",
"ch" = "Calinski and Harabasz index", # (Calinski and Harabasz 1974, optimal in Milligan and Cooper 1985; generalised for dissimilarites in Hennig and Liao 2013)
"widestgap" = "widest within-cluster gap",
"sindex" = "separation index"
)
df_kmeans_performance %>%
kbl(.,
escape = FALSE,
booktabs = TRUE,
align = "c",
digits = 2,
row.names = FALSE,
col.names = kmeans_metrics_names) %>%
kable_classic(
full_width = F,
lightable_options = "hover",
html_font = "Cambria"
) %>%
scroll_box(width = "100%")
```

number of cases | number of points | size of smallest cluster | number of noise points | average distance between clusters | average distance within clusters | maximum cluster diameter | minimum cluster separation | within clusters sum of squares | average silhouette width | Goodman Kruskal's Gamma coefficient | G3 coefficient | Normalized gamma | Dunn index | Dunn index 2 | entropy of distribution of cluster memberships | average within / average between | Calinski and Harabasz index | widest within-cluster gap | separation index |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|

156 | 2 | 76 | 0 | 10.98 | 9.98 | 19.77 | 4.70 | 51.80 | 0.09 | 0.26 | 0.36 | 0.21 | 0.24 | 1.10 | 0.69 | 0.91 | 16.38 | 12.48 | 5.54 |

156 | 3 | 41 | 0 | 10.91 | 9.70 | 18.93 | 4.89 | 48.47 | 0.08 | 0.32 | 0.31 | 0.26 | 0.26 | 1.04 | 1.08 | 0.89 | 13.96 | 12.48 | 5.40 |

156 | 4 | 21 | 0 | 10.92 | 9.54 | 18.54 | 5.15 | 46.58 | 0.08 | 0.40 | 0.26 | 0.30 | 0.28 | 0.93 | 1.32 | 0.87 | 11.68 | 12.48 | 5.51 |

156 | 5 | 5 | 0 | 10.95 | 9.44 | 18.00 | 4.89 | 45.05 | 0.08 | 0.45 | 0.24 | 0.33 | 0.27 | 0.80 | 1.41 | 0.86 | 10.28 | 13.34 | 5.39 |

156 | 6 | 5 | 0 | 10.80 | 9.32 | 18.00 | 4.69 | 43.67 | 0.06 | 0.44 | 0.24 | 0.28 | 0.26 | 0.77 | 1.68 | 0.86 | 9.37 | 13.34 | 5.26 |

156 | 7 | 5 | 0 | 10.77 | 9.23 | 18.00 | 5.03 | 42.48 | 0.06 | 0.45 | 0.23 | 0.28 | 0.28 | 0.74 | 1.84 | 0.86 | 8.67 | 13.34 | 5.31 |

156 | 8 | 5 | 0 | 10.74 | 9.12 | 18.00 | 4.69 | 41.31 | 0.05 | 0.48 | 0.22 | 0.27 | 0.26 | 0.73 | 1.99 | 0.85 | 8.19 | 13.34 | 5.15 |

156 | 9 | 5 | 0 | 10.71 | 9.04 | 18.00 | 4.69 | 40.31 | 0.05 | 0.49 | 0.22 | 0.26 | 0.26 | 0.74 | 2.12 | 0.84 | 7.75 | 13.34 | 5.09 |

156 | 10 | 2 | 0 | 10.74 | 9.04 | 18.00 | 4.69 | 39.35 | 0.05 | 0.51 | 0.21 | 0.29 | 0.26 | 0.63 | 2.07 | 0.84 | 7.40 | 13.92 | 5.09 |