> species <- readXL("D:/Nina/statistica/datasets/Копия IvindoData_DryadVersion.xlsx", + rownames=TRUE, header=TRUE, na="", sheet="Лист2", stringsAsFactors=TRUE) > summary(species) LandUse TransectID Distance Veg_Rich Veg_Stems Veg_liana Veg_DBH Veg_Canopy Veg_Understory RA_Apes Logging:13 Min. : 1.00 Min. : 2.701 Min. :10.88 Min. :23.44 Min. : 4.750 Min. :28.45 Min. :2.500 Min. :2.375 Min. : 0.0000 Neither: 4 1st Qu.: 5.75 1st Qu.: 5.672 1st Qu.:13.09 1st Qu.:28.69 1st Qu.: 9.031 1st Qu.:40.65 1st Qu.:3.250 1st Qu.:2.871 1st Qu.: 0.0000 Park : 7 Median :14.50 Median : 9.720 Median :14.94 Median :32.44 Median :11.938 Median :43.90 Median :3.429 Median :3.000 Median : 0.4818 Mean :13.50 Mean :11.880 Mean :14.83 Mean :32.80 Mean :11.038 Mean :46.09 Mean :3.468 Mean :3.018 Mean : 2.0448 3rd Qu.:20.25 3rd Qu.:17.680 3rd Qu.:16.54 3rd Qu.:37.08 3rd Qu.:13.250 3rd Qu.:50.58 3rd Qu.:3.750 3rd Qu.:3.170 3rd Qu.: 3.8120 Max. :27.00 Max. :26.761 Max. :18.75 Max. :47.56 Max. :16.375 Max. :76.48 Max. :4.000 Max. :3.875 Max. :12.9335 RA_Birds RA_Elephant RA_Monkeys RA_Rodent RA_Ungulate Min. :31.56 Min. :0.0000 Min. : 5.84 Min. :1.062 Min. : 0.000 1st Qu.:52.51 1st Qu.:0.0000 1st Qu.:22.70 1st Qu.:2.050 1st Qu.: 1.232 Median :57.90 Median :0.3639 Median :31.74 Median :3.229 Median : 2.546 Mean :58.64 Mean :0.5455 Mean :31.29 Mean :3.278 Mean : 4.166 3rd Qu.:68.18 3rd Qu.:0.8906 3rd Qu.:39.89 3rd Qu.:4.094 3rd Qu.: 5.156 Max. :85.03 Max. :2.2991 Max. :54.12 Max. :6.307 Max. :13.864 > attach(species) > library(cluster, pos=16) > matrix1 <- daisy(species[,10:15]) > matrix1 Dissimilarities : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 2 14.280969 3 19.646097 20.991981 4 22.787524 19.354245 33.785270 5 3.870564 16.560824 19.528523 26.007829 6 18.645137 20.671507 3.162199 34.488263 18.242279 7 12.847567 22.674962 12.938656 32.535533 11.761573 11.953269 8 23.191101 29.168426 10.103771 40.057319 22.315126 10.044739 11.393056 9 27.830343 25.665418 44.248403 19.274496 29.692332 43.852320 40.456622 50.289168 10 46.122610 41.173508 61.147091 32.164296 48.216401 60.900415 58.766515 68.047711 18.888319 11 29.560175 27.042639 45.542243 18.986670 31.512686 45.236971 42.134254 51.726237 3.316061 17.165445 12 18.436846 18.362734 35.568511 16.175743 20.394513 34.979552 31.177696 41.135222 9.494288 27.905300 11.384860 13 43.848548 39.681212 59.229283 30.810207 45.748408 58.932190 56.511015 65.924843 16.410332 4.178964 14.493947 25.516362 14 25.744926 24.860102 42.705607 19.437143 27.436398 42.151168 38.442336 48.403424 3.769812 21.378901 5.122054 7.528273 18.567720 15 5.878726 15.967854 24.954690 22.303239 6.605860 23.837847 17.945851 28.544356 23.514552 42.057638 25.348565 14.200545 39.530458 21.085856 16 6.798646 13.631953 24.266683 19.958370 7.973856 23.521094 18.833556 28.925852 21.988258 40.537411 23.779641 12.897427 38.061064 19.939040 4.010719 17 18.382145 19.061064 35.772328 17.311038 20.091878 35.106055 31.112977 41.166033 9.857770 28.333010 11.693664 1.634136 25.759524 7.395810 13.783383 12.674872 18 6.547026 17.242833 24.599316 23.728507 6.025735 23.418940 17.415364 27.872171 24.876920 43.409460 26.580627 15.733119 40.716009 22.271929 2.578872 5.122931 19 23.413782 21.853529 39.612553 13.199224 25.866952 39.410779 35.779155 45.412440 6.858869 23.511928 7.721612 6.790024 21.493356 6.976549 19.910173 18.331763 20 3.688090 14.392367 21.948188 22.973324 4.303067 20.771252 15.585332 25.837076 25.680326 44.066718 27.445938 16.307678 41.619520 23.375887 3.119694 4.571255 21 27.088321 33.840478 14.861292 45.086200 25.779398 14.325554 14.695939 5.339507 54.617805 72.595744 56.149590 45.347502 70.397116 52.598401 32.177599 32.935090 22 18.449333 11.764656 31.163995 13.639433 20.861386 30.869902 30.232405 38.480929 14.637903 30.056457 15.527973 9.235194 28.257599 13.967445 16.445673 13.951657 23 5.530074 12.263996 21.291121 18.195672 8.121508 20.787019 16.868892 26.222773 24.262239 42.241654 25.603330 15.139189 39.912391 22.247131 6.505882 5.022118 24 20.384234 19.564984 37.213490 16.674838 22.278476 36.620519 33.139982 42.973678 7.834512 26.003606 9.521203 2.219885 23.535566 5.650817 16.068233 14.775829 17 18 19 20 21 22 23 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 15.127583 19 7.873545 21.524390 20 16.015492 3.546554 21.921884 21 45.286943 31.360263 49.896576 29.564287 22 10.147515 17.874732 11.472314 16.955828 43.133787 23 15.165881 7.214946 19.610136 5.481732 30.578479 14.241509 24 2.566315 17.459638 6.222314 18.136978 47.206413 9.474550 16.905062 Metric : euclidean Number of objects : 24 > matrix2 <- daisy(species[,10:15], metric="manhattan") > ###MULTIDIMENSIONAL SCALING > species.mds1 <- cmdscale(matrix1) > plot(species.mds1[,1:2]) > plot(species.mds1[,1:2], type="n", xlab="Dim. 1", ylab="Dim. 2") > text(species.mds1[,1:2], labels=abbreviate(species[,1],1, method="both.sides")) > print (species.mds1) [,1] [,2] [1,] -8.877293 3.1380392 [2,] -4.074775 -8.6326085 [3,] -24.347778 -8.0903310 [4,] 7.168845 -10.1302903 [5,] -10.600695 5.6081811 [6,] -24.196368 -6.0436167 [7,] -21.534661 3.2398455 [8,] -31.305774 -2.1747536 [9,] 18.761028 1.4334478 [10,] 36.604050 -4.0975809 [11,] 20.345275 0.1358858 [12,] 9.497397 2.3427217 [13,] 34.512562 -1.6384862 [14,] 16.714564 3.4358211 [15,] -4.140856 6.2320536 [16,] -3.105466 3.4342746 [17,] 9.373463 3.5954248 [18,] -5.215096 7.2225093 [19,] 13.994726 -0.7727998 [20,] -6.590665 4.5886513 [21,] -35.777777 0.5831663 [22,] 6.655963 -5.8142383 [23,] -5.223014 0.3520821 [24,] 11.362345 2.0526014 > ####################CLUSTER ANALYSIS > species.clus1 <- agnes(species, metric = "manhattan", method = "single", stand = TRUE) > species.clus1 Call: agnes(x = species, metric = "manhattan", stand = TRUE, method = "single") Agglomerative coefficient: 0.2592759 Order of objects: [1] 1 2 5 9 11 12 17 14 20 23 15 19 18 24 10 13 16 7 8 21 22 3 6 4 Height (summary): Min. 1st Qu. Median Mean 3rd Qu. Max. 8.588 10.939 12.506 12.359 13.765 16.024 Available components: [1] "order" "height" "ac" "merge" "diss" "call" "method" "data" > plot(species.clus1) > species.clus2 <- agnes(species, method = "ward", stand = TRUE) > species.clus2 Call: agnes(x = species, stand = TRUE, method = "ward") Agglomerative coefficient: 0.7062797 Order of objects: [1] 1 5 2 3 6 4 7 8 21 9 11 13 10 22 12 17 14 15 19 18 16 20 23 24 Height (summary): Min. 1st Qu. Median Mean 3rd Qu. Max. 2.840 4.456 5.211 6.206 7.370 15.771 Available components: [1] "order" "height" "ac" "merge" "diss" "call" "method" "data" > plot(species.clus2) > plot(species.clus2, labels=abbreviate(species[,1])) > ############K-MEANS CLUSTERING > species.k1 <- clara(species, 3, samples=100) > species.k1 Call: clara(x = species, k = 3, samples = 100) Medoids: LandUse TransectID Distance Veg_Rich Veg_Stems Veg_liana Veg_DBH Veg_Canopy Veg_Understory RA_Apes RA_Birds RA_Elephant RA_Monkeys RA_Rodent RA_Ungulate [1,] 3 5 17.466897 16.500 29.22222 12.875 44.06772 2.500000 3.000000 2.481140 38.64208 0.000000 43.29142 1.832914 13.752445 [2,] 1 19 13.957156 14.875 35.00000 12.000 44.52021 3.428571 2.428571 0.000000 67.24923 0.364100 27.70799 3.640998 1.037684 [3,] 1 13 6.614524 12.375 23.44444 7.000 43.73006 3.500000 3.000000 1.830777 74.40211 0.989609 18.68712 2.968827 1.121557 Objective function: 17.23712 Clustering vector: int [1:24] 1 1 1 2 1 1 1 1 3 3 3 2 3 2 2 2 2 2 ... Cluster sizes: 8 12 4 Best sample: [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Available components: [1] "sample" "medoids" "i.med" "clustering" "objective" "clusinfo" "diss" "call" "silinfo" "data" > plot(species.k1) > summary(species.k1) Object of class 'clara' from call: clara(x = species, k = 3, samples = 100) Medoids: LandUse TransectID Distance Veg_Rich Veg_Stems Veg_liana Veg_DBH Veg_Canopy Veg_Understory RA_Apes RA_Birds RA_Elephant RA_Monkeys RA_Rodent RA_Ungulate [1,] 3 5 17.466897 16.500 29.22222 12.875 44.06772 2.500000 3.000000 2.481140 38.64208 0.000000 43.29142 1.832914 13.752445 [2,] 1 19 13.957156 14.875 35.00000 12.000 44.52021 3.428571 2.428571 0.000000 67.24923 0.364100 27.70799 3.640998 1.037684 [3,] 1 13 6.614524 12.375 23.44444 7.000 43.73006 3.500000 3.000000 1.830777 74.40211 0.989609 18.68712 2.968827 1.121557 Objective function: 17.23712 Numerical information per cluster: size max_diss av_diss isolation [1,] 8 26.99337 16.73074 0.7009645 [2,] 12 35.06563 18.54295 1.7701952 [3,] 4 31.63581 14.33237 1.5970496 Average silhouette width per cluster: [1] 0.3522441 0.1548720 0.3957560 Average silhouette width of best sample: 0.26081 Best sample: [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Clustering vector: [1] 1 1 1 2 1 1 1 1 3 3 3 2 3 2 2 2 2 2 2 2 1 2 2 2 Silhouette plot information for best sample: cluster neighbor sil_width 8 1 2 0.51780056 3 1 2 0.51483116 6 1 2 0.50438546 7 1 2 0.44756932 21 1 2 0.33302918 5 1 2 0.24053988 1 1 2 0.15097060 2 1 2 0.10882694 17 2 3 0.29207069 24 2 3 0.26703227 23 2 1 0.23885099 20 2 1 0.23210472 15 2 1 0.21621349 18 2 1 0.20138088 16 2 1 0.15246035 14 2 3 0.08986829 19 2 3 0.08329315 12 2 3 0.08259902 4 2 1 0.03333659 22 2 3 -0.03074682 13 3 2 0.50804956 10 3 2 0.42187889 9 3 2 0.32959110 11 3 2 0.32350463 276 dissimilarities, summarized : Min. 1st Qu. Median Mean 3rd Qu. Max. 6.619 24.965 32.852 34.652 43.543 81.867 Metric : euclidean Number of objects : 24 Available components: [1] "sample" "medoids" "i.med" "clustering" "objective" "clusinfo" "diss" "call" "silinfo" "data" ##################################SCRIPT############################## species <- readXL("D:/Nina/statistica/datasets/Копия IvindoData_DryadVersion.xlsx", rownames=TRUE, header=TRUE, na="", sheet="Лист2", stringsAsFactors=TRUE) summary(species) attach(species) ######DISTANCE MATRIX library(cluster, pos=16) matrix1 <- daisy(species[,10:15]) matrix1 matrix2 <- daisy(species[,10:15], metric="manhattan") ###MULTIDIMENSIONAL SCALING species.mds1 <- cmdscale(matrix1) plot(species.mds1[,1:2]) plot(species.mds1[,1:2], type="n", xlab="Dim. 1", ylab="Dim. 2") text(species.mds1[,1:2], labels=abbreviate(species[,1],1, method="both.sides")) print (species.mds1) ####################CLUSTER ANALYSIS species.clus1 <- agnes(species, metric = "manhattan", method = "single", stand = TRUE) species.clus1 plot(species.clus1) species.clus2 <- agnes(species, method = "ward", stand = TRUE) species.clus2 plot(species.clus2, labels=abbreviate(species[,1])) ############K-MEANS CLUSTERING species.k1 <- clara(species, 3, samples=100) species.k1 plot(species.k1) summary(species.k1)