R Under development (unstable) (2023-12-12 r85669 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 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. > ############### > # preliminaries > library(klaR) Loading required package: MASS > library(MASS) > data(B3) > data(countries) > postscript("EDAM.ps", encoding="ISOLatin1") > > ###### > # EDAM > TopoS(dist(B3[, 2:14]), dist(cmdscale(dist(B3[, 2:14])))) [,1] [1,] 0.7979349 > > # iris > suppressWarnings(RNGversion("2.10.0")) > set.seed(1234) > iris.sample <- sample(150, 42) > irisEDAM <- EDAM(iris[iris.sample, 1:4], classes = iris[iris.sample, 5], + standardize = TRUE, iter.max = 3) 1 / 18 2 / 18 0.5410866 3 / 18 0.5206556 4 / 18 0.5691 5 / 18 0.5780345 6 / 18 0.609391 7 / 18 0.6170824 8 / 18 0.6399899 9 / 18 0.646767 10 / 18 0.6470014 11 / 16 0.6470014 > plot(irisEDAM, vertices = FALSE) > legend(3, 5, col = rainbow(3), legend = levels(iris[,5]), pch = 16) > print(irisEDAM) $preimages Sepal.Length Sepal.Width Petal.Length Petal.Width 114 5.7 2.5 5.0 2.0 73 6.3 2.5 4.9 1.5 88 6.3 2.3 4.4 1.3 90 5.5 2.5 4.0 1.3 61 5.0 2.0 3.5 1.0 34 5.5 4.2 1.4 0.2 112 6.4 2.7 5.3 1.9 127 6.2 2.8 4.8 1.8 102 5.8 2.7 5.1 1.9 91 5.5 2.6 4.4 1.2 60 5.2 2.7 3.9 1.4 42 4.5 2.3 1.3 0.3 133 6.4 2.8 5.6 2.2 55 6.5 2.8 4.6 1.5 98 6.2 2.9 4.3 1.3 93 5.8 2.6 4.0 1.2 2 4.9 3.0 1.4 0.2 39 4.4 3.0 1.3 0.2 113 6.8 3.0 5.5 2.1 76 6.6 3.0 4.4 1.4 92 6.1 3.0 4.6 1.4 95 5.6 2.7 4.2 1.3 31 4.8 3.1 1.6 0.2 30 4.7 3.2 1.6 0.2 125 6.7 3.3 5.7 2.1 138 6.4 3.1 5.5 1.8 71 5.9 3.2 4.8 1.8 32 5.4 3.4 1.5 0.4 40 5.1 3.4 1.5 0.2 36 5.0 3.2 1.2 0.2 126 7.2 3.2 6.0 1.8 149 6.2 3.4 5.4 2.3 66 6.7 3.1 4.4 1.4 21 5.4 3.4 1.7 0.2 18 5.1 3.5 1.4 0.3 25 4.8 3.4 1.9 0.2 136 7.7 3.0 6.1 2.3 137 6.3 3.4 5.6 2.4 6 5.4 3.9 1.7 0.4 22 5.1 3.7 1.5 0.4 28 5.2 3.5 1.5 0.2 23 4.6 3.6 1.0 0.2 $Z [,1] [,2] [,3] [,4] [,5] [,6] [1,] 1 2 3 4 5 6 [2,] 7 8 9 10 11 12 [3,] 13 14 15 16 17 18 [4,] 19 20 21 22 23 24 [5,] 25 26 27 28 29 30 [6,] 31 32 33 34 35 36 [7,] 37 38 39 40 41 42 $Z.old.terms [,1] [,2] [,3] [,4] [,5] [,6] [1,] 16 10 36 40 41 8 [2,] 39 14 26 3 34 21 [3,] 33 31 11 2 7 17 [4,] 28 12 4 9 20 38 [5,] 29 15 42 32 13 18 [6,] 5 6 27 23 1 19 [7,] 22 30 24 35 25 37 $cl.ord [1] virginica versicolor versicolor versicolor versicolor setosa [7] virginica virginica virginica versicolor versicolor setosa [13] virginica versicolor versicolor versicolor setosa setosa [19] virginica versicolor versicolor versicolor setosa setosa [25] virginica virginica versicolor setosa setosa setosa [31] virginica virginica versicolor setosa setosa setosa [37] virginica virginica setosa setosa setosa setosa Levels: setosa versicolor virginica $S [,1] [1,] 0.6470031 attr(,"class") [1] "EDAM" > > # B3 > phasemat <- lapply(1:4, function(x) B3[B3[,1] == x, 2:14]) > subclasses <- lapply(phasemat, + function(x) cutree(hclust(dist(x)), k = round(nrow(x) / 4.47))) > centroids <- lapply(1:4, + function(y) apply(phasemat[[y]], 2, + function(x) by(x, subclasses[[y]], mean))) > centmat <- matrix(unlist(sapply(centroids, t)), ncol = 13, + byrow = TRUE, dimnames = list(NULL, colnames(centroids[[1]]))) > centclasses <- unlist(lapply(1:4, + function(x) rep(x, unlist(lapply(centroids, nrow))[x]))) > B3EDAM <- EDAM(centmat, classes = centclasses, standardize = TRUE, + iter.max = 6, rand = FALSE) 1 / 36 2 / 36 0.5503169 3 / 36 0.5782196 4 / 36 0.5766633 5 / 36 0.5894002 6 / 36 0.5661183 7 / 36 0.5744937 8 / 36 0.6509185 9 / 36 0.6455015 10 / 36 0.6693491 11 / 36 0.6878151 12 / 36 0.6966163 13 / 36 0.6975969 14 / 36 0.6994951 15 / 36 0.6996743 16 / 33 0.6996743 17 / 28 0.6996743 > plot(B3EDAM, standardize = TRUE) > opar <- par(xpd = NA) > legend(4, 5.1, col = rainbow(4), pch = 16, xjust = 0.5, yjust = 0, + ncol = 2, legend = c("upswing", "upper turning point", + "downswing", "lower turning point")) > print(B3EDAM) $preimages BSP91JW CP91JW DEFRATE EWAJW EXIMRATE GM1JW [1,] 10.0400000 6.1700000 1.9600000 1.1200000 2.400000 8.1000000 [2,] 6.1625000 6.7200000 0.0175000 1.0750000 3.795000 12.6525000 [3,] 8.3900000 5.6200000 0.0400000 3.2000000 2.900000 6.6200000 [4,] 7.3900000 8.7200000 1.0200000 2.9900000 2.360000 6.9900000 [5,] 9.0250000 8.7050000 0.6500000 4.2000000 2.900000 10.2550000 [6,] 5.1100000 5.1500000 -2.8000000 2.7900000 6.990000 2.8300000 [7,] 4.9650000 4.0100000 -2.6800000 1.3200000 6.600000 9.7600000 [8,] 8.5325000 5.3275000 0.1900000 2.5850000 3.382500 12.4375000 [9,] 7.4450000 7.9183333 1.2283333 2.6250000 2.948333 7.8200000 [10,] 7.4250000 8.8150000 -1.5950000 3.8700000 1.260000 6.2400000 [11,] 2.4192857 2.8328571 -1.4964286 0.9785714 5.100714 7.6600000 [12,] 3.9462500 3.3037500 0.0425000 1.2100000 4.281250 6.4462500 [13,] 5.1966667 4.3177778 -1.7744444 1.0677778 2.688889 9.9822222 [14,] 4.1200000 5.8822222 0.8833333 1.3222222 1.157778 10.1344444 [15,] 7.8950000 6.7500000 0.4700000 3.6350000 2.595000 9.4400000 [16,] 2.1900000 0.5966667 -2.0566667 -1.0666667 5.706667 10.7933333 [17,] 2.5200000 5.2433333 -2.3266667 0.1700000 6.156667 10.2500000 [18,] 3.6150000 3.3700000 -1.3680000 0.9510000 2.430000 8.3680000 [19,] 4.7740000 4.7000000 -0.8950000 1.9170000 2.208000 9.0190000 [20,] 5.8400000 7.3800000 1.5000000 2.3500000 1.660000 6.9800000 [21,] 1.4800000 1.7800000 -0.5100000 0.2200000 2.360000 3.1200000 [22,] 1.2328571 1.4757143 -2.7028571 -1.8357143 3.722857 10.5057143 [23,] 3.7750000 4.4125000 -3.4125000 0.6775000 3.380000 12.3600000 [24,] 3.5000000 4.2430000 -0.2990000 1.7180000 4.225000 7.5170000 [25,] 5.3466667 7.7633333 -0.1766667 2.3866667 2.200000 6.2433333 [26,] 0.0200000 -0.0700000 -4.0200000 0.7000000 3.330000 3.7300000 [27,] -0.8883333 -0.1566667 -0.9966667 -2.2083333 2.928333 2.8350000 [28,] 1.0650000 0.5200000 -1.9833333 1.4300000 0.975000 2.4200000 [29,] 2.5700000 4.4250000 1.3950000 0.8700000 2.325000 12.9400000 [30,] 2.7425000 5.5025000 -0.3025000 1.2475000 1.842500 13.0475000 [31,] 6.5450000 6.1775000 -4.2200000 3.3200000 6.602500 23.5700000 [32,] -2.3025000 0.1850000 -2.8775000 -1.7225000 7.220000 7.4100000 [33,] 0.3550000 -0.2900000 -3.1166667 -0.3900000 2.461667 0.5283333 [34,] -1.6000000 1.9500000 -4.1160000 -2.1840000 3.458000 11.6040000 [35,] -1.4000000 2.7100000 1.9400000 0.8900000 0.900000 8.0400000 IAU91JW IB91JW LSTKJW PBSPJW PCPJW ZINSK ZINSLR [1,] 5.9300000 40.2500000 0.9600000 2.360000 2.1100000 3.400000 3.7000000 [2,] 8.2225000 11.6250000 0.7250000 1.105000 0.5425000 3.172500 4.8600000 [3,] -3.7600000 14.5800000 1.0300000 1.950000 1.6500000 4.960000 4.9500000 [4,] 27.2500000 1.1300000 2.3800000 3.340000 1.5700000 4.000000 3.2500000 [5,] 23.0000000 11.3800000 3.6600000 3.460000 2.0000000 6.285000 3.1900000 [6,] 16.8300000 7.3800000 1.4900000 3.090000 2.4400000 8.200000 5.4800000 [7,] 5.8600000 14.8900000 0.4850000 1.700000 1.7950000 4.725000 4.5700000 [8,] 17.8850000 9.5750000 0.7350000 2.542500 1.7075000 4.122500 3.6525000 [9,] 15.5716667 4.4733333 5.8316667 3.846667 1.8933333 5.218333 2.5900000 [10,] 9.5100000 22.3900000 3.2400000 3.720000 3.8500000 6.815000 3.6950000 [11,] 4.8378571 -0.1050000 1.7557143 2.195000 0.8692857 4.587143 4.0871429 [12,] 12.2587500 1.3700000 1.8400000 2.782500 2.5437500 6.202500 4.5262500 [13,] 7.6688889 4.5355556 2.6711111 3.258889 2.6300000 3.952222 3.4066667 [14,] 6.8233333 3.9111111 6.4377778 4.095556 3.4333333 4.301111 2.4444444 [15,] 11.8150000 18.6200000 6.7750000 5.505000 4.0900000 6.780000 1.5800000 [16,] -0.6500000 3.2266667 -0.8133333 1.506667 2.2633333 4.563333 5.5800000 [17,] -9.1700000 2.5300000 2.6966667 3.290000 2.4566667 6.686667 3.4666667 [18,] 0.9430000 5.2770000 4.1060000 3.577000 3.2060000 4.621000 3.4980000 [19,] 6.3370000 5.8630000 4.7270000 4.338000 4.0720000 7.099000 3.4370000 [20,] 20.0600000 -2.9100000 12.3400000 6.170000 3.1900000 9.400000 1.1000000 [21,] -10.4200000 0.9000000 0.5900000 2.270000 2.9300000 5.940000 5.7300000 [22,] 1.9085714 0.5042857 0.5500000 3.055714 3.3142857 5.298571 4.6714286 [23,] 8.4225000 -3.4675000 2.9875000 3.920000 3.4550000 3.837500 2.7700000 [24,] -0.6340000 2.5890000 5.3150000 4.071000 3.6840000 7.768000 3.6960000 [25,] 14.0266667 7.9733333 13.1100000 7.566667 3.5800000 9.233333 0.3233333 [26,] 7.8800000 -16.2000000 1.3100000 1.640000 2.3400000 6.050000 5.8000000 [27,] -11.8233333 -7.1150000 3.6950000 3.458333 3.8683333 6.716667 4.9033333 [28,] -0.2566667 -4.1616667 8.7966667 5.455000 6.1250000 11.236667 3.8033333 [29,] 6.0150000 -6.6750000 6.9050000 5.090000 3.7450000 3.415000 1.4200000 [30,] 0.6950000 5.7900000 8.9175000 7.197500 5.2875000 6.427500 0.9475000 [31,] 12.7075000 2.7300000 1.1600000 3.362500 3.1825000 8.892500 5.5075000 [32,] -17.6050000 -0.8950000 3.3225000 3.195000 3.2450000 7.295000 3.1750000 [33,] -8.3000000 -3.4950000 5.0616667 4.393333 5.8050000 10.930000 5.6516667 [34,] -5.5220000 -9.8380000 8.7380000 6.814000 6.6660000 6.792000 2.7200000 [35,] -2.8400000 -21.5900000 6.4600000 4.150000 3.2700000 3.400000 2.0100000 $Z [,1] [,2] [,3] [,4] [,5] [1,] 1 2 3 4 5 [2,] 6 7 8 9 10 [3,] 11 12 13 14 15 [4,] 16 17 18 19 20 [5,] 21 22 23 24 25 [6,] 26 27 28 29 30 [7,] 31 32 33 34 35 $Z.old.terms [,1] [,2] [,3] [,4] [,5] [1,] 3 30 21 7 14 [2,] 13 12 1 16 15 [3,] 10 6 4 24 19 [4,] 5 22 2 17 26 [5,] 9 33 8 20 27 [6,] 11 32 28 23 34 [7,] 18 29 25 35 31 $cl.ord [1] 1 4 3 1 2 1 1 1 2 2 1 1 1 3 3 1 3 1 2 3 1 4 1 3 3 1 4 3 3 4 2 3 3 4 4 $S [,1] [1,] 0.6996743 attr(,"class") [1] "EDAM" > par(opar) > > # countries > logcount <- log(countries[,2:7]) > sdlogcount <- apply(logcount, 2, sd) > logstand <- t((t(logcount) / sdlogcount) * c(1,2,6,5,5,3)) > cclasses <- cutree(hclust(dist(logstand)), k = 6) > countryEDAM <- EDAM(logstand, classes = cclasses, sa = FALSE, + iter.max = 10, random = FALSE) 1 / 60 2 / 60 0.5819664 3 / 60 0.6019728 4 / 60 0.6032748 5 / 54 0.6032748 6 / 45 0.6032748 7 / 36 0.6032748 8 / 27 0.6032748 > plot(countryEDAM, vertices = FALSE, label = TRUE, stck = FALSE) > print(countryEDAM) $preimages Popul PopDens GDPpp LifeEx InfMor Illit VN 20.25732 9.548113 39.24569 116.3470 5.4178970 3.3785349 VRC 23.32402 8.485364 42.93622 117.1823 4.4590193 4.9761966 PL 19.42525 8.342967 46.65082 117.8157 -0.5338077 -3.0347501 GB 19.91683 9.532564 51.56967 119.3465 -3.0732560 0.0000000 D 20.26781 9.425814 51.72475 119.4375 -4.1402025 0.0000000 J 20.75075 10.079973 52.18528 120.3001 -5.3349348 0.0000000 RI 21.43267 8.326859 40.77249 115.9096 6.4354691 4.6052804 RP 20.29740 9.773323 42.75107 116.0483 4.4053813 2.6605518 TR 20.05604 7.740917 45.14800 117.0226 7.1513716 4.9076219 THA 19.99144 8.364019 44.96586 116.8082 3.7567641 2.6139915 I 19.87735 9.111887 51.50130 119.7775 -2.3080976 0.6344508 F 19.91842 8.142383 51.66126 119.7361 -3.9835174 0.0000000 WAN 20.80755 8.619864 34.23431 107.6621 9.4557280 6.5349786 ET 20.15903 7.469738 42.01007 116.4873 6.0639667 7.0611565 PE 19.08377 5.362560 43.18365 116.6695 6.2918536 4.1639140 YV 18.92612 5.711113 43.63746 117.7786 4.1705045 3.5582515 ROK 19.67362 10.731166 50.21975 118.3476 -1.5078150 1.2102773 E 19.47024 7.583450 50.63404 119.7188 -3.7998705 1.3989943 EAK 19.20347 6.919382 35.31607 104.3632 8.8842274 5.0936766 PK 20.93909 9.065449 38.53911 113.0926 9.7929825 7.5320599 DZ 19.24417 4.543840 43.59350 116.5378 6.3910479 6.4132851 CO 19.50948 6.235090 44.26121 116.7698 3.8958126 3.7992936 RA 19.42865 4.831215 47.03593 118.3912 2.3095602 2.0076146 USA 21.66832 5.900347 53.33636 118.9868 -1.8913387 2.0715392 RDC 19.85070 5.515311 32.52564 106.5222 10.9116952 6.6768197 BD 20.84484 11.897512 37.87758 112.7070 9.0864939 7.6202514 MA 19.20524 7.382954 41.96403 116.3431 7.2237670 7.3112704 BR 21.14918 5.305233 45.40257 116.7659 5.5578768 4.9215378 MAL 18.85336 7.360029 46.05336 116.9730 3.0886300 4.5385267 CDN 19.22326 2.028643 52.23873 119.9254 -3.4523532 2.0715392 AFG 19.09573 6.568735 33.01896 105.4028 12.7837592 7.8419744 MYA 19.53190 7.167192 37.91571 110.1147 9.3878081 5.3311720 IND 23.09742 9.988050 39.85378 113.7107 8.5890326 6.9791612 IR 20.05880 6.450779 44.79846 116.0720 7.1481043 5.7044775 MEX 20.53637 6.883343 46.18200 117.2126 4.1482030 3.8732480 RUS 20.89262 3.699693 46.69606 115.3965 3.2160923 -1.7277544 ETH 20.03041 7.064598 33.51298 101.8406 11.2326493 7.6334605 EAT 19.34466 6.301470 32.24726 103.9606 11.2540465 5.8112379 SUD 19.41051 4.715004 36.78556 111.0506 9.0506784 6.9031571 UZB 18.98441 7.035666 39.86317 113.8738 9.4665068 -0.6725449 UA 19.66823 7.581899 42.80663 114.9230 3.5403547 -2.2702066 SA 19.53863 6.161484 46.82540 105.1628 8.6889292 4.9215378 $Z [,1] [,2] [,3] [,4] [,5] [,6] [1,] 1 2 3 4 5 6 [2,] 7 8 9 10 11 12 [3,] 13 14 15 16 17 18 [4,] 19 20 21 22 23 24 [5,] 25 26 27 28 29 30 [6,] 31 32 33 34 35 36 [7,] 37 38 39 40 41 42 $Z.old.terms [,1] [,2] [,3] [,4] [,5] [,6] [1,] 42 7 29 37 13 18 [2,] 15 28 35 34 17 12 [3,] 25 10 27 41 20 32 [4,] 19 26 2 8 3 39 [5,] 9 4 23 5 21 6 [6,] 1 24 14 16 22 30 [7,] 11 38 33 40 36 31 $cl.ord VN VRC PL GB D J RI RP TR THA I F WAN ET PE YV ROK E EAK PK 2 2 3 5 5 5 2 2 2 3 5 5 1 2 2 3 5 5 1 4 DZ CO RA USA RDC BD MA BR MAL CDN AFG MYA IND IR MEX RUS ETH EAT SUD UZB 2 3 3 5 1 4 2 2 3 5 1 4 4 2 3 3 1 1 4 2 UA SA 3 6 $S [,1] [1,] 0.6032748 attr(,"class") [1] "EDAM" > dev.off() null device 1 > > psSave <- readLines("EDAM.ps.save") > ps <- readLines("EDAM.ps") > setdiff(ps, psSave) character(0) > > proc.time() user system elapsed 1.48 0.31 1.78