# The optimal number of cluster by Gap Statistics

I'm using the GAP statistics (clusGAP) to find the optimal number of clusters in my gene expression data. But I'm not sure whether the optimal number suggested by clusGAP is right or not. I ran the clusGAP for several times (clustGAP(data, kmeans, K.max = 30, B = 100)), but I received different results as follow:

The suggested number of cluster is 11 for above figure ("firstSEmax");

For another trial,

The suggested number of cluster is 7 for above figure ("firstSEmax");

So I have two questions here:

1. I thought in these results, it is hard to find the maximum of Gap value compared to the examples in the original paper. I'm new in this field, so I don't know whether I can believe the optimal number of clusters suggested by the clustGAP?

2. As I mentioned, the optimal number is different in different trials, then the question is which one to choose? or how can I get a consistent result?

• – Anony-Mousse Sep 15 '15 at 17:12
• Are you able to visualise your data in some way? Do eleven clusters make any sense? Do seven? Is there anything fundamentally different between the different trials? In the thread mentioned by @Anony-Mousse, I link against the original paper of the GAP statistic; it is not overly technical, try to give it a quick read to get a better idea of the theory behind this statistic. – usεr11852 Sep 15 '15 at 18:41
• @Anony-Mousse: While the first question is mostly addressed by the link you give (so I would be inclined to close this as a duplicate) the second question is not covered there and it has utility on its own right. – usεr11852 Sep 15 '15 at 18:43
• That variation is probably an artifact of k-means being randomized (and not returning stable results; common with badly normalized data). It may well go away, when 1) is resolved. – Anony-Mousse Sep 15 '15 at 19:07
• @usεr11852 I also used HCA and visualize it in JavaTreeView. At certain cutoff, I actually could identify 16 different clusters. However, 7-means result also make sense. I think it is because the other clusters are not big. – simonhb1990 Sep 15 '15 at 19:46