## ------------------------------------------------
## load data and retrieve a sample
## ------------------------------------------------
library(healthyFlowData)
data(hd)
sample = exprs(hd.flowSet[[1]])
## ------------------------------------------------
## cluster sample using kmeans algorithm
## ------------------------------------------------
km = kmeans(sample, centers=4, nstart=20)
cluster.labels = km$cluster
## ------------------------------------------------
## Create ClusteredSample object (Option 1 )
## without specifying centers and covs
## we need to pass FC sample for paramter estimation
## ------------------------------------------------
clustSample = ClusteredSample(labels=cluster.labels, sample=sample)
## ------------------------------------------------
## Create ClusteredSample object (Option 2)
## specifying centers and covs
## no need to pass the sample
## ------------------------------------------------
centers = list()
covs = list()
num.clusters = nrow(km$centers)
for(i in 1:num.clusters)
{
centers[[i]] = km$centers[i,]
covs[[i]] = cov(sample[cluster.labels==i,])
}
# Now we do not need to pass sample
ClusteredSample(labels=cluster.labels, centers=centers, covs=covs)
## ------------------------------------------------
## Show summary and plot a clustered sample
## ------------------------------------------------
summary(clustSample)
plot(sample, clustSample)
Run the code above in your browser using DataLab