n = 100
g = 6
set.seed(g)
d <- data.frame(x = unlist(lapply(1:g, function(i) rnorm(n/g, runif(1)*i^2))),
y = unlist(lapply(1:g, function(i) rnorm(n/g, runif(1)*i^2))))
plot(d)
###################
d = read.table('clipboard',header = T)
plot(d)
mydata <- d
wss <- (nrow(mydata)-1)*sum(apply(mydata,2,var))
for (i in 2:15) wss[i] <- sum(kmeans(mydata,
centers=i)$withinss)
plot(1:15, wss, type="b", xlab="Number of Clusters",
ylab="Within groups sum of squares")
library(fpc)
pamk.best <- pamk(d)
##############################
lastcluster = pam(d, 1) # pam(d, pamk.best$nc)
plot(d,type='l')
vl = c(lastcluster$medoids[,1])
vl
abline(v=vl,lty=2,col='red')
#library(cluster)
#plot(pam(d, 3))
###################################
#cat("number of clusters estimated by
# optimum average silhouette ", pamk.best$nc, "
")
#library(cluster)
#plot(pam(d, pamk.best$nc))