Btibert3
10/16/2019 - 2:05 PM

A simple function to explore hclust in R to look at distance/cluster tradeoff

A simple function to explore hclust in R to look at distance/cluster tradeoff

## function to take an dendrogram, and heights for each iteration
## pull out the # of clusters and height
hclust_eval = function(c) {
  # extract the height, and the dendrogram
  h = c$height
  d = as.dendrogram(c)
  # the container for the stats
  s = list()
  # for each entry in h, get the # of clusters
  # TODO: improve this code
  for (i in 1:length(h)) {
    tmp_h = h[i]
    tmp = length(unique(cutree(d, h=tmp_h)))
    s[[i]] = list(iteration = i,
                n_clust = tmp,
                h_dist = tmp_h)
    rm(tmp_h, tmp)
  }
  # return s
  return(s)
}