How To Use Clusgap() When The Cluster Method Is Hierarchical Clustering?
1
0
Entering edit mode
11.1 years ago
liux.bio ▴ 360

Hello, Biostars.I am new in R and statistics.I am using package 'cluster' in R to analyse microarray data. "FUNcluster" in the "clusGap" needs a argument k while hierarchical clustering method like hclust() has no argument k. What should I do? Best wishes.

r clustering • 11k views
ADD COMMENT
1
Entering edit mode
11.1 years ago
Michael 55k

You can use the function cutree(tree, k = NULL, h = NULL) with k parameter as follows to define the cluster function for clusGap:

mycluster <- function(x, k) list(cluster=cutree(hclust(dist(x), method = "average"),k=k))

Edit: According to ?clusGap, FUNcluster needs to be a list with one element named 'cluster' containing integer numbers for the clusters.

ADD COMMENT
0
Entering edit mode

Thanks! I did following your advice .But there is an error.

llibrary(cluster)
mydist <- function(x) as.dist((1-cor(t(x)))/2)
mycluster <- function(x, k) cutree(hclust(mydist(x), method = "average"),k=k)
myclusGap <- clusGap(data.selection03,
                                   FUN = mycluster, 
                                   K.max = 10, 
                                   B = 100)

Error: $ operator is invalid for atomic vectors

I checked the code of clusGap. Maybe something is wrong with cutree.

ADD REPLY
0
Entering edit mode

Sorry, didn't have time to test the code. I guess mycluster has to return a list, this is documented in the help page of clusGap(). I'm sure you can figure it out.

ADD REPLY
0
Entering edit mode

Try mycluster <- function(x, k) list(cluster=cutree(hclust(mydist(x), method = "average"),k=k))

ADD REPLY
0
Entering edit mode

Yeah,you are right.Thank you.

ADD REPLY

Login before adding your answer.

Traffic: 4454 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6