Skip to content
Prev 318195 / 398503 Next

Is it possible to obtain an agglomeration schedule with R cluster analyis

You didn't show what the tabular summary should look like.
However, look at the height and merge components of
an hclust object:
height merge.1 merge.2
1   9.297849      -1      -8
2  13.609188      -2      -5
3  23.779193      -4      -6
4  33.865321      -3       2
5  48.229659       1       3
6 104.636227       4       5
7 185.135221      -7       6
The two merge.* columns identify what groups merged at
the corresponding height value.  Negative values, i, refer to the
-i'th leaf value in the 'labels' component and positive values, i, refer
to cluster created in the i'th row of the data.frame.  The following
function transforms those references into name:

f <- function(hc){
     data.frame(row.names=paste0("Cluster",seq_along(hc$height)),
                height=hc$height,
                components=ifelse(hc$merge<0, hc$labels[abs(hc$merge)], paste0("Cluster",hc$merge)),
                stringsAsFactors=FALSE)
}

as in
height components.1 components.2
Cluster1   9.297849      Alabama     Delaware
Cluster2  13.609188       Alaska   California
Cluster3  23.779193     Arkansas     Colorado
Cluster4  33.865321      Arizona     Cluster2
Cluster5  48.229659     Cluster1     Cluster3
Cluster6 104.636227     Cluster4     Cluster5
Cluster7 185.135221  Connecticut     Cluster6

Compare that to the output of str(as.dendrogram(hc3)):
--[dendrogram w/ 2 branches and 8 members at h = 185]
  |--leaf "Connecticut" 
  `--[dendrogram w/ 2 branches and 7 members at h = 105]
     |--[dendrogram w/ 2 branches and 3 members at h = 33.9]
     |  |--leaf "Arizona" 
     |  `--[dendrogram w/ 2 branches and 2 members at h = 13.6]
     |     |--leaf "Alaska" 
     |     `--leaf "California" 
     `--[dendrogram w/ 2 branches and 4 members at h = 48.2]
        |--[dendrogram w/ 2 branches and 2 members at h = 9.3]
        |  |--leaf "Alabama" 
        |  `--leaf "Delaware" 
        `--[dendrogram w/ 2 branches and 2 members at h = 23.8]
           |--leaf "Arkansas" 
           `--leaf "Colorado"

Does f() produce the information you need for your display?

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com