Question: How To Use Clusgap() When The Cluster Method Is Hierarchical Clustering?
0
gravatar for liux.bio
6.1 years ago by
liux.bio340
China
liux.bio340 wrote:

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 • 7.4k views
ADD COMMENTlink modified 6.1 years ago by Michael Dondrup47k • written 6.1 years ago by liux.bio340
1
gravatar for Michael Dondrup
6.1 years ago by
Bergen, Norway
Michael Dondrup47k wrote:

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 COMMENTlink modified 6.1 years ago • written 6.1 years ago by Michael Dondrup47k

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 REPLYlink modified 6.1 years ago • written 6.1 years ago by liux.bio340

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 REPLYlink written 6.1 years ago by Michael Dondrup47k

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

ADD REPLYlink written 6.1 years ago by Michael Dondrup47k

Yeah,you are right.Thank you.

ADD REPLYlink written 6.1 years ago by liux.bio340
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 774 users visited in the last hour