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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
R : Copyright 2002, The R Development Core Team
Version 1.6.0 Under development (unstable) (2002-07-29)
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.
Type `demo()' for some demos, `help()' for on-line help, or
`help.start()' for a HTML browser interface to help.
Type `q()' to quit R.
> ### SETUP
> library(cluster)
Loading required package: mva
>
> ### 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 191.3607
[2,] 191.3607 0.0000
$Shading
[1] 20.92924 22.07076
$Distances
[,1] [,2] [,3]
[1,] 0.0000 NA 166.9258
[2,] NA 0 NA
[3,] 166.9258 NA 0.0000
$Shading
[1] 24.375330 5.142036 16.482634
$Distances
[,1] [,2] [,3] [,4]
[1,] 0.0000 NA 146.3222 291.3211
[2,] NA 0 NA NA
[3,] 146.3222 NA 0.0000 NA
[4,] 291.3211 NA NA 0.0000
$Shading
[1] 14.151910 3.869265 10.873704 20.105120
>
> ## 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(0,rep(7654,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)
>
|