The R Project SVN R-packages

Rev

Rev 7508 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed


R version 3.5.0 alpha (2018-03-28 r74481)
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-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)
> options(digits = 6)
> data(votes.repub)
> di.votes <- daisy(votes.repub)
> 
> .p00 <- proc.time()
> summary(diana(votes.repub, metric = "manhattan", stand = TRUE))
Merge:
      [,1] [,2]
 [1,]   -7  -32
 [2,]  -13  -35
 [3,]  -12  -50
 [4,]    1  -30
 [5,]  -26  -28
 [6,]   -5  -37
 [7,]  -22  -38
 [8,]  -21  -39
 [9,]  -16  -27
[10,]    4    2
[11,]  -25  -48
[12,]  -42  -46
[13,]   -6  -14
[14,]  -34  -41
[15,]   -8  -20
[16,]    5  -31
[17,]   10    7
[18,]  -17  -47
[19,]   -3  -44
[20,]  -33   12
[21,]   15   18
[22,]   17  -29
[23,]   22  -49
[24,]   21   11
[25,]   23  -15
[26,]  -11  -19
[27,]    3    9
[28,]    8  -23
[29,]   19   16
[30,]   27   14
[31,]    6   25
[32,]   -1  -10
[33,]   31   13
[34,]   29  -36
[35,]   -2  -45
[36,]   -9  -43
[37,]   24   20
[38,]   32   -4
[39,]  -24  -40
[40,]   38  -18
[41,]   33   30
[42,]   34   37
[43,]   35   26
[44,]   41   28
[45,]   40   36
[46,]   42   44
[47,]   45   39
[48,]   43   46
[49,]   47   48
Order of objects:
 [1] Alabama        Georgia        Arkansas       Louisiana      Florida       
 [6] Texas          Mississippi    South Carolina Alaska         Vermont       
[11] Hawaii         Maine          Arizona        Utah           Montana       
[16] Nevada         New Mexico     Oklahoma       Delaware       Maryland      
[21] Kentucky       Washington     Missouri       West Virginia  North Carolina
[26] Tennessee      Virginia       California     Oregon         Connecticut   
[31] New York       New Jersey     Illinois       Ohio           Michigan      
[36] Pennsylvania   New Hampshire  Wisconsin      Iowa           Colorado      
[41] Indiana        Idaho          Wyoming        Kansas         Nebraska      
[46] North Dakota   South Dakota   Massachusetts  Rhode Island   Minnesota     
Height:
 [1]  27.36345  33.96925  39.65826  48.53428  31.89965  72.59850  35.69152
 [8] 167.58020  31.58222  43.84601  24.48796  85.55248  18.39339  25.67631
[15]  11.49397  17.45552  28.62550  42.54480  16.48510  20.04450  17.87516
[22]  21.98373  14.21808  33.61071  18.39733  14.75762  56.55675  11.70132
[29]  27.05887   8.38200  11.36820  13.25237   9.23004  17.83484  12.70819
[36]  20.66714  21.03997  23.66586  28.60541  15.31703  40.33905  10.46294
[43]  24.83525  12.80419  26.36292  16.25192  47.25773  12.79160  24.87206
Divisive coefficient:
[1] 0.886918

1225 dissimilarities, summarized :
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   8.38   25.54   34.51   45.06   56.02  167.60 
Metric :  manhattan 
Number of objects : 50

Available components:
[1] "order"     "height"    "dc"        "merge"     "diss"      "call"     
[7] "order.lab" "data"     
> summary(diana(di.votes, keep.diss = FALSE))
Merge:
      [,1] [,2]
 [1,]  -12  -50
 [2,]  -13  -32
 [3,]  -14  -35
 [4,]   -7  -29
 [5,]  -21  -39
 [6,]   -3  -28
 [7,]  -25  -48
 [8,]  -16  -27
 [9,]  -15  -41
[10,]    2  -30
[11,]    6  -26
[12,]  -33  -42
[13,]   12  -46
[14,]    1  -44
[15,]   10    3
[16,]  -22  -38
[17,]  -11  -19
[18,]   -5  -47
[19,]  -17  -20
[20,]   -2  -45
[21,]   14  -31
[22,]  -37  -49
[23,]    9    8
[24,]    4   15
[25,]   -8   19
[26,]   -6   21
[27,]    5  -23
[28,]   24   16
[29,]   26  -36
[30,]   11   29
[31,]   -1  -10
[32,]   28   22
[33,]   23  -34
[34,]    7   13
[35,]   -4   -9
[36,]   20   17
[37,]  -24  -40
[38,]   31  -43
[39,]   32   33
[40,]   25   34
[41,]   30   18
[42,]   35  -18
[43,]   38   42
[44,]   39   27
[45,]   41   40
[46,]   36   44
[47,]   43   37
[48,]   46   45
[49,]   47   48
Order of objects:
 [1] Alabama        Georgia        Texas          Arkansas       Florida       
 [6] Louisiana      Mississippi    South Carolina Alaska         Vermont       
[11] Hawaii         Maine          Connecticut    New Hampshire  Illinois      
[16] New York       New Jersey     Indiana        Ohio           Michigan      
[21] Pennsylvania   Oregon         Wisconsin      Iowa           South Dakota  
[26] Kansas         Nebraska       North Dakota   Massachusetts  Rhode Island  
[31] Minnesota      Arizona        Nevada         Montana        Colorado      
[36] Idaho          Wyoming        Utah           New Mexico     Oklahoma      
[41] California     Washington     Delaware       Kentucky       Maryland      
[46] Missouri       West Virginia  North Carolina Tennessee      Virginia      
Height:
 [1]  48.2397  63.1862  72.9221  56.1363  72.9221 116.7048  63.0951 281.9508
 [9]  33.8330  58.0384  32.7611 106.7448  20.5216  39.1728  19.8436  27.0243
[17]  31.4966  20.2258  47.1690  31.6595  49.2428  36.7667  64.4821  26.1547
[25]  37.4564  25.9221  50.7201  77.1184  22.6334  44.4594 178.4119  23.4206
[33]  27.8273  48.0483  43.7055  17.1992  31.1988  34.0510  48.0483  70.4868
[41]  33.2328  81.0764  43.3829  33.4744  66.7591  25.3953  54.7306  29.5099
[49]  30.1541
Divisive coefficient:
[1] 0.878225

Available components:
[1] "order"     "height"    "dc"        "merge"     "diss"      "call"     
[7] "order.lab"
> cat('Time elapsed: ', proc.time() - .p00,'\n')
Time elapsed:  0.006 0.003 0.008 0 0 
> 
> data(agriculture)
> data(ruspini)
> 
> .p0 <- proc.time()
> dia.agr <- diana(agriculture)
> drusp0  <- diana(ruspini, keep.diss=FALSE, keep.data=FALSE)
> drusp1  <- diana(ruspini, metric = "manhattan")
> cat('Time elapsed: ', proc.time() - .p0,'\n')
Time elapsed:  0.002 0 0.003 0 0 
> 
> summary(dia.agr)
Merge:
      [,1] [,2]
 [1,]   -1  -10
 [2,]   -2   -9
 [3,]    1   -3
 [4,]   -6   -8
 [5,]   -5   -7
 [6,]    3  -12
 [7,]   -4  -11
 [8,]    6    4
 [9,]    8    2
[10,]    7    5
[11,]    9   10
Order of objects:
 [1] B   NL  D   UK  F   I   DK  L   GR  P   E   IRL
Height:
 [1]  1.64924  2.43516  4.85077  6.72309  2.77308  8.05295  2.22036 24.03539
 [9]  5.16236 12.56742  3.14006
Divisive coefficient:
[1] 0.871106

66 dissimilarities, summarized :
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   1.65    4.36    7.99    9.59   13.25   24.04 
Metric :  euclidean 
Number of objects : 12

Available components:
[1] "order"     "height"    "dc"        "merge"     "diss"      "call"     
[7] "order.lab" "data"     
> summary(drusp0)
Merge:
      [,1] [,2]
 [1,]  -18  -19
 [2,]  -55  -56
 [3,]  -27  -28
 [4,]  -49  -51
 [5,]  -33  -34
 [6,]  -23  -24
 [7,]  -59  -60
 [8,]  -29  -30
 [9,]  -67  -69
[10,]  -36  -39
[11,]  -32  -35
[12,]  -50  -54
[13,]  -37  -38
[14,]  -70  -71
[15,]  -64  -68
[16,]  -62  -66
[17,]  -12  -13
[18,]  -16    1
[19,]   -9  -10
[20,]  -42  -43
[21,]  -15  -17
[22,]  -47  -48
[23,]   12  -52
[24,]  -21  -22
[25,]    9   14
[26,]    2  -57
[27,]  -73  -74
[28,]    6  -25
[29,]  -26   11
[30,]    4  -53
[31,]    3    8
[32,]  -11   17
[33,]   -6   -8
[34,]   -2   -3
[35,]   10  -40
[36,]  -14   21
[37,]  -65   25
[38,]   -4   33
[39,]   36   18
[40,]   29    5
[41,]   26    7
[42,]   -1   34
[43,]   24   28
[44,]   16  -63
[45,]  -46   22
[46,]  -31   35
[47,]   27  -75
[48,]   37  -72
[49,]   43   31
[50,]   30   23
[51,]   13   20
[52,]   15   48
[53,]   32  -20
[54,]   41  -58
[55,]   42   -5
[56,]   40   46
[57,]  -44  -45
[58,]   19   39
[59,]   38   -7
[60,]   51  -41
[61,]  -61   44
[62,]   50   54
[63,]   52   47
[64,]   61   63
[65,]   49   56
[66,]   59   53
[67,]   55   58
[68,]   57   62
[69,]   65   60
[70,]   67   66
[71,]   68   45
[72,]   69   71
[73,]   70   64
[74,]   73   72
Order of objects:
 [1] 1  2  3  5  9  10 14 15 17 16 18 19 4  6  8  7  11 12 13 20 61 62 66 63 64
[26] 68 65 67 69 70 71 72 73 74 75 21 22 23 24 25 27 28 29 30 26 32 35 33 34 31
[51] 36 39 40 37 38 42 43 41 44 45 49 51 53 50 54 52 55 56 57 59 60 58 46 47 48
Height:
 [1]  10.04988   6.40312  16.12452  29.12044   4.12311  17.02939   8.48528
 [8]   4.24264   9.21954   4.12311   1.41421  40.24922   8.94427   6.32456
[15]  19.02630  28.84441   6.32456   4.12311  14.14214 102.07840  21.40093
[22]   4.12311  10.81665  27.07397   3.60555  13.60147   8.54400   2.82843
[29]   5.09902   3.60555  12.80625  22.80351   5.65685  12.36932 154.49595
[36]   4.47214  10.77033   2.23607   5.83095  13.03840   2.00000   6.32456
[43]   2.82843  28.16026   6.08276   3.00000   9.43398   2.23607  16.27882
[50]  11.04536   3.00000   6.70820  36.61967   3.60555  13.34166   4.24264
[57]  20.02498  94.57801  17.02939  35.35534   2.23607   6.32456  13.15295
[64]   3.16228   4.47214  22.20360   2.00000   5.38516   9.84886   2.82843
[71]  15.29706  47.63402  11.00000   4.47214
Divisive coefficient:
[1] 0.960566

Available components:
[1] "order"     "height"    "dc"        "merge"     "diss"      "call"     
[7] "order.lab"
> summary(drusp1)
Merge:
      [,1] [,2]
 [1,]  -55  -56
 [2,]  -27  -28
 [3,]  -18  -19
 [4,]  -49  -51
 [5,]  -33  -34
 [6,]  -32  -35
 [7,]  -23  -24
 [8,]  -59  -60
 [9,]  -50  -54
[10,]  -29  -30
[11,]  -67  -69
[12,]  -37  -38
[13,]   11  -71
[14,]  -64  -68
[15,]  -62  -66
[16,]  -12  -13
[17,]  -16    3
[18,]   -9  -10
[19,]  -47  -48
[20,]    9  -52
[21,]  -42  -43
[22,]  -39  -40
[23,]  -21  -22
[24,]   13  -70
[25,]  -15  -17
[26,]    1  -57
[27,]  -26    6
[28,]    4  -53
[29,]    7  -25
[30,]    2   10
[31,]  -11   16
[32,]   -6   -8
[33,]  -31  -36
[34,]  -74  -75
[35,]   -2   -3
[36,]  -46   19
[37,]  -65   24
[38,]  -14   17
[39,]   -4   32
[40,]   38   25
[41,]   -1   35
[42,]   26    8
[43,]   27    5
[44,]   23   30
[45,]   28   20
[46,]   15  -63
[47,]   43   33
[48,]   44   29
[49,]   46  -73
[50,]   31  -20
[51,]   42  -58
[52,]  -44  -45
[53,]   12   22
[54,]   37  -72
[55,]   14   54
[56,]   39   -7
[57,]   41   -5
[58,]   53   21
[59,]   18   40
[60,]   48   47
[61,]  -61   49
[62,]   45   51
[63,]   58  -41
[64,]   55   34
[65,]   61   64
[66,]   57   59
[67,]   56   50
[68,]   52   62
[69,]   60   63
[70,]   66   67
[71,]   68   36
[72,]   69   71
[73,]   70   65
[74,]   73   72
Order of objects:
 [1] 1  2  3  5  9  10 14 16 18 19 15 17 4  6  8  7  11 12 13 20 61 62 66 63 73
[26] 64 68 65 67 69 71 70 72 74 75 21 22 27 28 29 30 23 24 25 26 32 35 33 34 31
[51] 36 37 38 39 40 42 43 41 44 45 49 51 53 50 54 52 55 56 57 59 60 58 46 47 48
Height:
 [1]  12   9  22  36   5  24  11   5   2  12   6  54  12   8  20  40   8   5  16
[20] 142  30   5  15  16  33   5  19  11   4   5   6  18  32   9 187   6  14   2
[39]   8   4  16   3   8  26   7   3  13   3  16   9  51   5  18   6  24   6  32
[58] 123  18  48   3   8  15   4   6  31   2   7  13   4  18  67  11   6
Divisive coefficient:
[1] 0.958075

2775 dissimilarities, summarized :
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
    2.0    52.5    97.0    91.0   128.0   187.0 
Metric :  manhattan 
Number of objects : 75

Available components:
[1] "order"     "height"    "dc"        "merge"     "diss"      "call"     
[7] "order.lab" "data"     
> str    (drusp1)
List of 8
 $ order    : int [1:75] 1 2 3 5 9 10 14 16 18 19 ...
 $ height   : num [1:74] 12 9 22 36 5 24 11 5 2 12 ...
 $ dc       : num 0.958
 $ merge    : int [1:74, 1:2] -55 -27 -18 -49 -33 -32 -23 -59 -50 -29 ...
 $ diss     : 'dissimilarity' num [1:2775] 11 12 29 13 25 43 33 22 27 39 ...
  ..- attr(*, "Size")= int 75
  ..- attr(*, "Metric")= chr "manhattan"
  ..- attr(*, "Labels")= chr [1:75] "1" "2" "3" "4" ...
 $ call     : language diana(x = ruspini, metric = "manhattan")
 $ order.lab: chr [1:75] "1" "2" "3" "5" ...
 $ data     : int [1:75, 1:2] 4 5 10 9 13 13 12 15 18 19 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:75] "1" "2" "3" "4" ...
  .. ..$ : chr [1:2] "x" "y"
 - attr(*, "class")= chr [1:2] "diana" "twins"
> 
> ## From system.file("scripts/ch11.R", package = "MASS")
> data(swiss)
> swiss.x <- as.matrix(swiss[,-1])
> .p1 <- proc.time()
> dCH <- diana(swiss.x)
> cat('Time elapsed: ', proc.time() - .p1,'\n')
Time elapsed:  0.001 0 0.001 0 0 
> str(as.dendrogram(as.hclust(dCH)))# keep back-compatible
--[dendrogram w/ 2 branches and 47 members at h = 127]
  |--[dendrogram w/ 2 branches and 31 members at h = 99.2]
  |  |--[dendrogram w/ 2 branches and 11 members at h = 60.9]
  |  |  |--[dendrogram w/ 2 branches and 8 members at h = 29.1]
  |  |  |  |--[dendrogram w/ 2 branches and 5 members at h = 22.7]
  |  |  |  |  |--[dendrogram w/ 2 branches and 4 members at h = 17.4]
  |  |  |  |  |  |--[dendrogram w/ 2 branches and 3 members at h = 11.7]
  |  |  |  |  |  |  |--leaf "Courtelary" 
  |  |  |  |  |  |  `--[dendrogram w/ 2 branches and 2 members at h = 7.48]
  |  |  |  |  |  |     |--leaf "Le Locle" 
  |  |  |  |  |  |     `--leaf "ValdeTravers" 
  |  |  |  |  |  `--leaf "La Chauxdfnd" 
  |  |  |  |  `--leaf "La Vallee" 
  |  |  |  `--[dendrogram w/ 2 branches and 3 members at h = 19]
  |  |  |     |--[dendrogram w/ 2 branches and 2 members at h = 11.5]
  |  |  |     |  |--leaf "Lausanne" 
  |  |  |     |  `--leaf "Neuchatel" 
  |  |  |     `--leaf "Vevey" 
  |  |  `--[dendrogram w/ 2 branches and 3 members at h = 56.1]
  |  |     |--leaf "V. De Geneve" 
  |  |     `--[dendrogram w/ 2 branches and 2 members at h = 21.4]
  |  |        |--leaf "Rive Droite" 
  |  |        `--leaf "Rive Gauche" 
  |  `--[dendrogram w/ 2 branches and 20 members at h = 48.4]
  |     |--leaf "Moutier" 
  |     `--[dendrogram w/ 2 branches and 19 members at h = 44.3]
  |        |--[dendrogram w/ 2 branches and 18 members at h = 39.1]
  |        |  |--[dendrogram w/ 2 branches and 6 members at h = 21.9]
  |        |  |  |--[dendrogram w/ 2 branches and 4 members at h = 12.1]
  |        |  |  |  |--[dendrogram w/ 2 branches and 2 members at h = 10.8]
  |        |  |  |  |  |--leaf "Neuveville" 
  |        |  |  |  |  `--leaf "Boudry" 
  |        |  |  |  `--[dendrogram w/ 2 branches and 2 members at h = 4.56]
  |        |  |  |     |--leaf "Grandson" 
  |        |  |  |     `--leaf "Val de Ruz" 
  |        |  |  `--[dendrogram w/ 2 branches and 2 members at h = 13.5]
  |        |  |     |--leaf "Nyone" 
  |        |  |     `--leaf "Yverdon" 
  |        |  `--[dendrogram w/ 2 branches and 12 members at h = 20.4]
  |        |     |--[dendrogram w/ 2 branches and 7 members at h = 15.1]
  |        |     |  |--[dendrogram w/ 2 branches and 5 members at h = 11.6]
  |        |     |  |  |--[dendrogram w/ 2 branches and 4 members at h = 8.05]
  |        |     |  |  |  |--[dendrogram w/ 2 branches and 3 members at h = 6.79]
  |        |     |  |  |  |  |--[dendrogram w/ 2 branches and 2 members at h = 4.79]
  |        |     |  |  |  |  |  |--leaf "Aigle" 
  |        |     |  |  |  |  |  `--leaf "Morges" 
  |        |     |  |  |  |  `--leaf "Rolle" 
  |        |     |  |  |  `--leaf "Avenches" 
  |        |     |  |  `--leaf "Orbe" 
  |        |     |  `--[dendrogram w/ 2 branches and 2 members at h = 6.04]
  |        |     |     |--leaf "Moudon" 
  |        |     |     `--leaf "Payerne" 
  |        |     `--[dendrogram w/ 2 branches and 5 members at h = 17.3]
  |        |        |--[dendrogram w/ 2 branches and 4 members at h = 11.2]
  |        |        |  |--[dendrogram w/ 2 branches and 2 members at h = 7.57]
  |        |        |  |  |--leaf "Aubonne" 
  |        |        |  |  `--leaf "Oron" 
  |        |        |  `--[dendrogram w/ 2 branches and 2 members at h = 6.35]
  |        |        |     |--leaf "Cossonay" 
  |        |        |     `--leaf "Lavaux" 
  |        |        `--leaf "Paysd'enhaut" 
  |        `--leaf "Echallens" 
  `--[dendrogram w/ 2 branches and 16 members at h = 56.2]
     |--[dendrogram w/ 2 branches and 5 members at h = 20.4]
     |  |--[dendrogram w/ 2 branches and 3 members at h = 12.7]
     |  |  |--leaf "Delemont" 
     |  |  `--[dendrogram w/ 2 branches and 2 members at h = 9.4]
     |  |     |--leaf "Franches-Mnt" 
     |  |     `--leaf "Porrentruy" 
     |  `--[dendrogram w/ 2 branches and 2 members at h = 13]
     |     |--leaf "Gruyere" 
     |     `--leaf "Sarine" 
     `--[dendrogram w/ 2 branches and 11 members at h = 30]
        |--[dendrogram w/ 2 branches and 5 members at h = 12.9]
        |  |--[dendrogram w/ 2 branches and 4 members at h = 11.9]
        |  |  |--[dendrogram w/ 2 branches and 3 members at h = 8.45]
        |  |  |  |--leaf "Broye" 
        |  |  |  `--[dendrogram w/ 2 branches and 2 members at h = 4.14]
        |  |  |     |--leaf "Glane" 
        |  |  |     `--leaf "Veveyse" 
        |  |  `--leaf "Sion" 
        |  `--leaf "Monthey" 
        `--[dendrogram w/ 2 branches and 6 members at h = 16]
           |--[dendrogram w/ 2 branches and 4 members at h = 7.42]
           |  |--[dendrogram w/ 2 branches and 3 members at h = 5.94]
           |  |  |--[dendrogram w/ 2 branches and 2 members at h = 2.05]
           |  |  |  |--leaf "Conthey" 
           |  |  |  `--leaf "Sierre" 
           |  |  `--leaf "Herens" 
           |  `--leaf "Entremont" 
           `--[dendrogram w/ 2 branches and 2 members at h = 5.09]
              |--leaf "Martigwy" 
              `--leaf "St Maurice" 
> 
> proc.time()
   user  system elapsed 
  0.192   0.044   0.292