Rev 5634 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
R version 2.12.0 Patched (2010-10-19 r53372)Copyright (C) 2010 The R Foundation for Statistical ComputingISBN 3-900051-07-0Platform: i686-pc-linux-gnu (32-bit)R is free software and comes with ABSOLUTELY NO WARRANTY.You are welcome to redistribute it under certain conditions.Type 'license()' or 'licence()' for distribution details.R is a collaborative project with many contributors.Type 'contributors()' for more information and'citation()' on how to cite R or R packages in publications.Type 'demo()' for some demos, 'help()' for on-line help, or'help.start()' for an HTML browser interface to help.Type 'q()' to quit R.> library(cluster)>> ### clusplot() & pam() RESULT checking ...>> ## plotting votes.diss(dissimilarity) in a bivariate plot and> ## partitioning into 2 clusters> data(votes.repub)> votes.diss <- daisy(votes.repub)> for(k in 2:4) {+ votes.clus <- pam(votes.diss, k, diss = TRUE)$clustering+ print(clusplot(votes.diss, votes.clus, diss = TRUE, shade = TRUE))+ }$Distances[,1] [,2][1,] 0.0000 154.8601[2,] 154.8601 0.0000$Shading[1] 22.12103 20.87897$Distances[,1] [,2] [,3][1,] 0.0000 NA 140.8008[2,] NA 0 NA[3,] 140.8008 NA 0.0000$Shading[1] 25.602967 5.292663 15.104370$Distances[,1] [,2] [,3] [,4][1,] 0.0000 NA 117.2287 280.7259[2,] NA 0 NA NA[3,] 117.2287 NA 0.0000 NA[4,] 280.7259 NA NA 0.0000$Shading[1] 15.431339 3.980743 10.145454 19.442464>> ## plotting iris (dataframe) in a 2-dimensional plot and partitioning> ## into 3 clusters.> data(iris)> iris.x <- iris[, 1:4]>> for(k in 2:5)+ print(clusplot(iris.x, pam(iris.x, k)$clustering, diss = FALSE))$Distances[,1] [,2][1,] 0.0000000 0.5452161[2,] 0.5452161 0.0000000$Shading[1] 18.93861 24.06139$Distances[,1] [,2] [,3][1,] 0.000000 1.433071 2.851715[2,] 1.433071 0.000000 NA[3,] 2.851715 NA 0.000000$Shading[1] 18.987588 17.166940 9.845472$Distances[,1] [,2] [,3] [,4][1,] 0.000000 2.24157 1.6340329 3.0945887[2,] 2.241570 0.00000 NA NA[3,] 1.634033 NA 0.0000000 0.9461858[4,] 3.094589 NA 0.9461858 0.0000000$Shading[1] 12.881766 14.912379 13.652381 7.553474$Distances[,1] [,2] [,3] [,4] [,5][1,] 0.000000 1.9899160 1.552387 3.11516148 3.96536391[2,] 1.989916 0.0000000 NA NA 0.94713417[3,] 1.552387 NA 0.000000 1.17348334 2.22769309[4,] 3.115161 NA 1.173483 0.00000000 0.04539385[5,] 3.965364 0.9471342 2.227693 0.04539385 0.00000000$Shading[1] 10.369738 11.560147 10.088431 14.857590 5.124093>>> .Random.seed <- c(0L,rep(7654L,3))> ## generate 25 objects, divided into 2 clusters.> x <- rbind(cbind(rnorm(10,0,0.5), rnorm(10,0,0.5)),+ cbind(rnorm(15,5,0.5), rnorm(15,5,0.5)))> print.default(clusplot(px2 <- pam(x, 2)))$Distances[,1] [,2][1,] 0.000000 5.516876[2,] 5.516876 0.000000$Shading[1] 20.18314 22.81686>> clusplot(px2, labels = 2, col.p = 1 + px2$clustering)>