Description Usage Arguments Examples
View source: R/gauss.kmedoids.R
k-Medoids is a generally applicable clustering algorithm
as long as we have concept of dissimilarity. We adopt pam
algorithm
by cluster package. See pam
for more details.
1 | gauss.kmedoids(glist, k = 2, type = c("wass2"))
|
glist |
list of objects, a S3 object of |
k |
the number of clusters. |
type |
type of distance metric to be used. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ## generate three-cluster data with univariate Gaussians
mylist = list()
for (i in 1:10){
mylist[[i]] = wrapgauss1d(mean=-2-runif(1), sd=runif(1))
}
for (i in 11:20){
mylist[[i]] = wrapgauss1d(mean=0, sd=runif(1))
}
for (i in 21:30){
mylist[[i]] = wrapgauss1d(mean=2+runif(1), sd=runif(1))
}
## apply clustering with different k values
cl2 <- gauss.kmedoids(mylist, k=2)$cluster
cl3 <- gauss.kmedoids(mylist, k=3)$cluster
cl4 <- gauss.kmedoids(mylist, k=4)$cluster
## compute 2-dimensional embedding for visualization
mds2d <- gauss.mds(mylist, ndim=2)$embed
mdsx <- as.vector(mds2d[,1])
mdsy <- as.vector(mds2d[,2])
## visualize
opar = par(mfrow=c(1,3), pty="s")
plot(mdsx, mdsy, pch=19, col=cl2, main="k=2 medoids")
plot(mdsx, mdsy, pch=19, col=cl3, main="k=3 medoids")
plot(mdsx, mdsy, pch=19, col=cl4, main="k=4 medoids")
par(opar)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.