## create artificial data set with 3 distinct clusters
set.seed(1)
V1 = c(abs(rnorm(100, 2)), abs(rnorm(100, 50)), abs(rnorm(100, 140)))
V2 = c(abs(rnorm(100, 2, 8)), abs(rnorm(100, 55, 4)), abs(rnorm(100, 105, 1)))
data <- t(data.frame(V1, V2))
colnames(data) <- paste("Sample", 1:ncol(data), sep="")
rownames(data) <- paste("Gene", 1:nrow(data), sep="")
## run COMMUNAL
result <- COMMUNAL(data=data, ks=seq(2,5)) # result is a COMMUNAL object
k <- 3 # suppose optimal cluster number is 3
clusters <- result$getClustering(k) # method to extract clusters
mat.key <- clusterKeys(clusters, k=k) # get core clusters
examineCounts(mat.key) # help decide agreement.thresh
core <- returnCore(mat.key, agreement.thresh=50) # find 'core' clusters (all algs agree)
table(core) # the 'core' cluster sizes
## Note: could try a different value for k to
## see clusters with sub-optimal k
## Can specify clustering methods and validation measures
result <- COMMUNAL(data = data, ks=c(2,3),
clus.methods = c("diana", "som", "pam", "kmeans", "ccp-hc", "nmf"),
validation=c('pearsongamma', 'avg.silwidth'))
clusters <- result$getClustering(k=3)
mat.key <- clusterKeys(clusters, k=3)
examineCounts(mat.key)
core <- returnCore(mat.key, agreement.thresh=50) # find 'core' clusters
table(core) # the 'core' clusters
## Additional arguments are passed down to clValid, NMF, ConsensusClusterPlus
result <- COMMUNAL(data=data, ks=2:5,
clus.methods=c("diana", "ccp-hc", "nmf"), reps=20, nruns=2)Run the code above in your browser using DataLab