Question

In the scope of a demand forecasting project, I would like to determine the best way to group time series that have similarity with each other so I can apply a Top Down forecasting algorithm. At the moment, my key question is to determine what are the appropriate groups and what is the appropriate hierarchy of those groups. After doing some reading, I believe that Dynamic Time Warping might help. In order to test this, I have created a little test case but I am facing one problem and that is how I can extract the hierarchy in for example a text tree or something similar. I am hoping that maybe one of you will be able to help me further.

I have created the following case to demonstrate what I get to.

sc2 <- read.table("http://dl.dropbox.com/u/9641130/R/hclust.data", header=F, sep="")
SampleLabels <- c("ID1", "ID2", "ID3", "ID4", "ID5", "ID6", "ID7", "ID8", "ID9", "ID10", "ID11", "ID12", "ID13", "ID14", "ID15")
distMatrix2 <- dist(sc2, method="DTW")
hc2 <- hclust(distMatrix2, method="average")
# show the visual tree
plot(hc2, labels=SampleLabels)

Somehow, I would like to get the names and members of the clusters out in text so that I can continue to work with it. Anybody an idea?

Thanks!

Was it helpful?

Solution 2

Following Seth's answer in the comments above, I have come to the following solution:

numgroups <- 5
groups <- cutree(hc2,k=numgroups)
LabelsAndGroups <- t(rbind(SampleLabels,groups)) # t is just to get a better overview when presenting the results here. 
LabelsAndGroups
      SampleLabels groups
 [1,] "ID1"        "1"   
 [2,] "ID2"        "1"   
 [3,] "ID3"        "2"   
 [4,] "ID4"        "1"   
 [5,] "ID5"        "3"   
 [6,] "ID6"        "4"   
 [7,] "ID7"        "1"   
 [8,] "ID8"        "4"   
 [9,] "ID9"        "5"   
[10,] "ID10"       "1"   
[11,] "ID11"       "2"   
[12,] "ID12"       "3"   
[13,] "ID13"       "4"   
[14,] "ID14"       "4"   
[15,] "ID15"       "1"   

OTHER TIPS

You can use dendrapply and attributes to access each node in the tree.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top