Tugas Prak 8 TPM

Ghonniyu Hiban Saputra
G1401221012

About The Data

Dataset EUROJOBS Dataset Eurojobs.csv terdiri dari persentase populasi pekerja pada lapangan usaha (industri) yang berbeda di 26 negera di Eropa pada tahun 1979. Dataset ini memiliki 10 variabel.

Country : nama negara

  • Agr : % dari pekerja di Agriculture

  • Min : % dari pekerja di Mining

  • Man : % dari pekerja di Manufacturing

  • PS : % dari pekerja di Power Supplies Industries

  • Con : % dari pekerja di Construction

  • SI : % dari pekerja di Service Industries

  • Fin : % dari pekerja di Finance

  • SPS : % dari pekerja di Social and Personal Services

  • TC : % dari pekerja di Transportation and Communications

Library

library(classInt)
library(cluster)
library(factoextra)
## Loading required package: ggplot2
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
library(parameters)
## Warning: package 'parameters' was built under R version 4.4.3
library(factoextra)
library(NbClust)
library(clusterSim)
## Warning: package 'clusterSim' was built under R version 4.4.2
## Loading required package: MASS
library(fpc)
## Warning: package 'fpc' was built under R version 4.4.3

Eksplorasi

ejobs <- read.csv(
  file = "C:\\Users\\Ghonniyu\\Downloads\\Eurojobs.csv",
  header = TRUE,
  row.names = 1
)

head(ejobs)
##               Agr Min  Man  PS  Con   SI Fin  SPS  TC
## Belgium       3.3 0.9 27.6 0.9  8.2 19.1 6.2 26.6 7.2
## Denmark       9.2 0.1 21.8 0.6  8.3 14.6 6.5 32.2 7.1
## France       10.8 0.8 27.5 0.9  8.9 16.8 6.0 22.6 5.7
## West Germany  6.7 1.3 35.8 0.9  7.3 14.4 5.0 22.3 6.1
## Ireland      23.2 1.0 20.7 1.3  7.5 16.8 2.8 20.8 6.1
## Italy        15.9 0.6 27.6 0.5 10.0 18.1 1.6 20.1 5.7
str(ejobs)
## 'data.frame':    26 obs. of  9 variables:
##  $ Agr: num  3.3 9.2 10.8 6.7 23.2 15.9 7.7 6.3 2.7 12.7 ...
##  $ Min: num  0.9 0.1 0.8 1.3 1 0.6 3.1 0.1 1.4 1.1 ...
##  $ Man: num  27.6 21.8 27.5 35.8 20.7 27.6 30.8 22.5 30.2 30.2 ...
##  $ PS : num  0.9 0.6 0.9 0.9 1.3 0.5 0.8 1 1.4 1.4 ...
##  $ Con: num  8.2 8.3 8.9 7.3 7.5 10 9.2 9.9 6.9 9 ...
##  $ SI : num  19.1 14.6 16.8 14.4 16.8 18.1 18.5 18 16.9 16.8 ...
##  $ Fin: num  6.2 6.5 6 5 2.8 1.6 4.6 6.8 5.7 4.9 ...
##  $ SPS: num  26.6 32.2 22.6 22.3 20.8 20.1 19.2 28.5 28.3 16.8 ...
##  $ TC : num  7.2 7.1 5.7 6.1 6.1 5.7 6.2 6.8 6.4 7 ...
summary(ejobs)
##       Agr             Min             Man              PS        
##  Min.   : 2.70   Min.   :0.100   Min.   : 7.90   Min.   :0.1000  
##  1st Qu.: 7.70   1st Qu.:0.525   1st Qu.:23.00   1st Qu.:0.6000  
##  Median :14.45   Median :0.950   Median :27.55   Median :0.8500  
##  Mean   :19.13   Mean   :1.254   Mean   :27.01   Mean   :0.9077  
##  3rd Qu.:23.68   3rd Qu.:1.800   3rd Qu.:30.20   3rd Qu.:1.1750  
##  Max.   :66.80   Max.   :3.100   Max.   :41.20   Max.   :1.9000  
##       Con               SI             Fin              SPS       
##  Min.   : 2.800   Min.   : 5.20   Min.   : 0.500   Min.   : 5.30  
##  1st Qu.: 7.525   1st Qu.: 9.25   1st Qu.: 1.225   1st Qu.:16.25  
##  Median : 8.350   Median :14.40   Median : 4.650   Median :19.65  
##  Mean   : 8.165   Mean   :12.96   Mean   : 4.000   Mean   :20.02  
##  3rd Qu.: 8.975   3rd Qu.:16.88   3rd Qu.: 5.925   3rd Qu.:24.12  
##  Max.   :11.500   Max.   :19.10   Max.   :11.300   Max.   :32.40  
##        TC       
##  Min.   :3.200  
##  1st Qu.:5.700  
##  Median :6.700  
##  Mean   :6.546  
##  3rd Qu.:7.075  
##  Max.   :9.400
par(mfrow = c(3,3))
for(i in 1:ncol(ejobs)) {
  hist(ejobs[,i],
       main = paste("Histogram of", colnames(ejobs)[i]),
       xlab = "%",
       col = "skyblue",
       border = "white")
}

Agr dan PS sangat tidak merata (banyak negara rendah, sedikit yang sangat tinggi). Man, Con, SPS menunjukkan distribusi yang lebih seragam dan terpusat. Ada sektor yang secara umum tidak dominan (Min, PS, Fin), tapi tetap penting untuk mengidentifikasi karakteristik negara tertentu

cor_matrix <- cor(ejobs)
round(cor_matrix, 2)
##       Agr   Min   Man    PS   Con    SI   Fin   SPS    TC
## Agr  1.00  0.04 -0.67 -0.40 -0.54 -0.74 -0.22 -0.75 -0.56
## Min  0.04  1.00  0.45  0.41 -0.03 -0.40 -0.44 -0.28  0.16
## Man -0.67  0.45  1.00  0.39  0.49  0.20 -0.16  0.15  0.35
## PS  -0.40  0.41  0.39  1.00  0.06  0.20  0.11  0.13  0.38
## Con -0.54 -0.03  0.49  0.06  1.00  0.36  0.02  0.16  0.39
## SI  -0.74 -0.40  0.20  0.20  0.36  1.00  0.37  0.57  0.19
## Fin -0.22 -0.44 -0.16  0.11  0.02  0.37  1.00  0.11 -0.25
## SPS -0.75 -0.28  0.15  0.13  0.16  0.57  0.11  1.00  0.57
## TC  -0.56  0.16  0.35  0.38  0.39  0.19 -0.25  0.57  1.00
library(corrplot)
## corrplot 0.94 loaded
corrplot(cor_matrix, method = "circle", type = "upper")

  • Korelasi yang mendekati 1:

Man – Con, SI, SPS → artinya negara yang kuat di sektor manufaktur biasanya juga kuat di sektor jasa publik.

  • Korelasi yang mendekati -1:

Agr – Man, SPS, TC → negara yang agraris umumnya lemah di sektor-sektor modern/industri.

Pada dataset ini tidak perlu melakukan standardisasi data karena semua variabel memiliki satuan yang sama yaitu persen (%).

Hierarchical Clustering

Satu variable

Agriculture

stripchart(ejobs$Agr, method = "stack", pch = 19, cex = 1, main = "Agriculture")

Mining

stripchart(ejobs$Min, method = "stack", pch = 19, cex = 1, main = "Mining")

Manufacturing

stripchart(ejobs$Man, method = "stack", pch = 19, cex = 1, main = "Manufacturing")

Public Services

stripchart(ejobs$PS, method = "stack", pch = 19, cex = 1, main = "Public Services")

Construction

stripchart(ejobs$Con, method = "stack", pch = 19, cex = 1, main = "Construction")

Social Infrastructure

stripchart(ejobs$SI, method = "stack", pch = 19, cex = 1, main = "Social Infrastructure")

Finance

stripchart(ejobs$Fin, method = "stack", pch = 19, cex = 1, main = "Finance")

Social & Personal Service

stripchart(ejobs$SPS, method = "stack", pch = 19, cex = 1, main = "Social & Personal Services")

Transport & Communication

stripchart(ejobs$TC, method = "stack", pch = 19, cex = 1, main = "Transport & Communication")

Per Sector

# Buat data hanya dari kolom numerik (exclude Country)
sector_data <- ejobs[, sapply(ejobs, is.numeric)]

stripchart(sector_data,
           method = "stack",
           vertical = TRUE,
           pch = 19,
           cex = 1,
           col = rainbow(ncol(sector_data)),
           group.names = colnames(sector_data),
           main = "Stripchart per Sector",
           ylab = "Percentage",
           las = 2)

  • Agr dan SPS adalah dua sektor dengan sebaran paling luas, menunjukkan kontras besar antar negara.

  • Min dan PS adalah sektor yang konsisten kecil di semua negara.

Dua Variabel

par(mfrow = c(2, 2))
plot(ejobs$Agr,ejobs$Man,pch=19,cex=1,ylab="Manufactur",xlab="Agriculture",col=2)
plot(ejobs$Agr,ejobs$Fin,pch=19,cex=1,ylab="Financial",xlab="Agriculture",col=2)
plot(ejobs$PS,ejobs$Min,pch=19,cex=1,ylab="Mining",xlab="PS",col=2)
plot(ejobs$Man,ejobs$SPS,pch=19,cex=1,ylab="SPS",xlab="Agriculture",col=2)

Matriks Jarak

Euclidean

jarak1 <- dist(ejobs[,-1])
as.matrix(jarak1)
##                  Belgium   Denmark    France West Germany   Ireland     Italy
## Belgium         0.000000  9.278470  4.908156    10.556515  9.998500  8.375560
## Denmark         9.278470  0.000000 11.516944    17.315600 12.354756 14.880188
## France          4.908156 11.516944  0.000000     8.871866  7.876547  5.359104
## West Germany   10.556515 17.315600  8.871866     0.000000 15.529005 10.267911
## Ireland         9.998500 12.354756  7.876547    15.529005  0.000000  7.644606
## Italy           8.375560 14.880188  5.359104    10.267911  7.644606  0.000000
## Luxembourg      8.646965 16.717655  5.739338     7.645260 10.874741  5.238320
## Netherlands     5.906776  5.351635  8.037413    15.499355  9.333810 11.195535
## United Kingdom  4.191658  9.822423  6.706713     8.637708 12.471568 10.188229
## Austria        10.523783 17.811794  6.646804     8.448077 10.664896  5.829237
## Finland         5.407402  9.048204  4.036087    10.275213  7.321885  7.638717
## Greece         20.396078 22.224986 16.594879    21.810089 11.630563 15.219396
## Norway          6.348228  5.969087  8.160270    15.073818  8.083935 10.492378
## Portugal       12.500000 16.299693  8.218272    12.961867  6.742403  6.933974
## Spain          18.092264 22.413389 13.458826    14.702721 15.540270 13.792752
## Sweden          7.751129  4.309292 10.422572    14.224627 13.371238 14.014635
## Switzerland    15.404220 23.484889 12.634872     8.217664 18.258149 11.860860
## Turkey         29.482876 27.728866 26.482636    31.876010 20.310835 26.081603
## Bulgaria       15.733404 19.672570 12.297561     9.469952 14.999667 11.646029
## Czechoslovakia 16.388411 21.472541 13.269891     8.289753 17.166537 12.494399
## East Germany   17.279468 22.989780 15.996562     7.872738 21.558525 15.990935
## Hungary        14.866741 18.861336 11.243220    10.720075 12.625767 10.263040
## Poland         16.709279 19.028663 12.750294    14.427751 11.876447 11.841875
## Rumania        20.811776 24.503877 16.394511    15.319595 17.221498 15.171684
## USSR           14.814857 14.337015 12.733028    14.310136 12.938702 13.226867
## Yugoslavia     27.913438 29.364434 23.863152    27.639465 21.150177 24.428058
##                Luxembourg Netherlands United Kingdom   Austria   Finland
## Belgium          8.646965    5.906776       4.191658 10.523783  5.407402
## Denmark         16.717655    5.351635       9.822423 17.811794  9.048204
## France           5.739338    8.037413       6.706713  6.646804  4.036087
## West Germany     7.645260   15.499355       8.637708  8.448077 10.275213
## Ireland         10.874741    9.333810      12.471568 10.664896  7.321885
## Italy            5.238320   11.195535      10.188229  5.829237  7.638717
## Luxembourg       0.000000   13.052203       9.773433  3.760319  8.832327
## Netherlands     13.052203    0.000000       8.529947 14.256227  6.989278
## United Kingdom   9.773433    8.529947       0.000000 11.737121  6.486139
## Austria          3.760319   14.256227      11.737121  0.000000  9.106591
## Finland          8.832327    6.989278       6.486139  9.106591  0.000000
## Greece          17.408906   19.887936      22.381019 15.117209 16.354204
## Norway          12.690548    3.884585       8.682742 13.570925  5.793099
## Portugal         9.239048   13.630847      13.914022  7.274613  8.638866
## Spain           12.797656   19.786359      18.911372 10.016986 14.790199
## Sweden          15.121839    6.913031       6.576473 16.521199  8.178019
## Switzerland      8.583705   20.239071      15.288558  7.967434 15.395129
## Turkey          28.688848   27.378641      30.879281 26.926381 25.088244
## Bulgaria        11.494781   18.621224      14.581152 10.199510 12.243366
## Czechoslovakia  11.182576   20.074113      14.982323 10.316492 13.886684
## East Germany    13.751727   22.000682      14.796283 14.188376 16.631296
## Hungary         10.362915   17.349640      14.500000  8.784646 11.036304
## Poland          13.107631   17.807021      16.865646 11.216506 12.097107
## Rumania         15.136710   22.923787      20.548966 12.787494 16.831815
## USSR            15.082109   14.992998      14.123385 14.335620 10.347947
## Yugoslavia      24.627018   27.574445      29.326268 22.067850 23.807562
##                   Greece    Norway  Portugal     Spain    Sweden Switzerland
## Belgium        20.396078  6.348228 12.500000 18.092264  7.751129   15.404220
## Denmark        22.224986  5.969087 16.299693 22.413389  4.309292   23.484889
## France         16.594879  8.160270  8.218272 13.458826 10.422572   12.634872
## West Germany   21.810089 15.073818 12.961867 14.702721 14.224627    8.217664
## Ireland        11.630563  8.083935  6.742403 15.540270 13.371238   18.258149
## Italy          15.219396 10.492378  6.933974 13.792752 14.014635   11.860860
## Luxembourg     17.408906 12.690548  9.239048 12.797656 15.121839    8.583705
## Netherlands    19.887936  3.884585 13.630847 19.786359  6.913031   20.239071
## United Kingdom 22.381019  8.682742 13.914022 18.911372  6.576473   15.288558
## Austria        15.117209 13.570925  7.274613 10.016986 16.521199    7.967434
## Finland        16.354204  5.793099  8.638866 14.790199  8.178019   15.395129
## Greece          0.000000 18.456435  9.198369 13.151046 23.433310   21.793806
## Norway         18.456435  0.000000 12.409271 19.412625  7.208329   20.032723
## Portugal        9.198369 12.409271  0.000000  9.824459 16.224981   14.291256
## Spain          13.151046 19.412625  9.824459  0.000000 21.904566   13.226489
## Sweden         23.433310  7.208329 16.224981 21.904566  0.000000   21.148286
## Switzerland    21.793806 20.032723 14.291256 13.226489 21.148286    0.000000
## Turkey         13.299624 26.061466 20.119394 24.098340 29.762392   33.571863
## Bulgaria       16.876018 17.069271  9.949372 11.608187 17.732456   12.489596
## Czechoslovakia 19.536120 18.738196 12.304064 12.608331 19.082977   10.467569
## East Germany   26.279650 20.891146 18.162874 18.743265 19.562208   11.462548
## Hungary        14.097518 15.517087  7.718160 10.587256 17.512281   13.116783
## Poland         10.663020 16.007498  6.711930 10.170054 18.580097   16.559287
## Rumania        13.957435 21.601620 10.812030  8.867920 23.428402   15.110261
## USSR           16.351758 12.769495 10.990450 15.607370 13.706933   19.462014
## Yugoslavia     12.527570 26.951809 18.101105 15.631059 30.393091   26.982402
##                  Turkey  Bulgaria Czechoslovakia East Germany   Hungary
## Belgium        29.48288 15.733404      16.388411    17.279468 14.866741
## Denmark        27.72887 19.672570      21.472541    22.989780 18.861336
## France         26.48264 12.297561      13.269891    15.996562 11.243220
## West Germany   31.87601  9.469952       8.289753     7.872738 10.720075
## Ireland        20.31083 14.999667      17.166537    21.558525 12.625767
## Italy          26.08160 11.646029      12.494399    15.990935 10.263040
## Luxembourg     28.68885 11.494781      11.182576    13.751727 10.362915
## Netherlands    27.37864 18.621224      20.074113    22.000682 17.349640
## United Kingdom 30.87928 14.581152      14.982323    14.796283 14.500000
## Austria        26.92638 10.199510      10.316492    14.188376  8.784646
## Finland        25.08824 12.243366      13.886684    16.631296 11.036304
## Greece         13.29962 16.876018      19.536120    26.279650 14.097518
## Norway         26.06147 17.069271      18.738196    20.891146 15.517087
## Portugal       20.11939  9.949372      12.304064    18.162874  7.718160
## Spain          24.09834 11.608187      12.608331    18.743265 10.587256
## Sweden         29.76239 17.732456      19.082977    19.562208 17.512281
## Switzerland    33.57186 12.489596      10.467569    11.462548 13.116783
## Turkey          0.00000 26.134269      29.480502    36.128936 24.038719
## Bulgaria       26.13427  0.000000       3.728270    10.458489  3.898718
## Czechoslovakia 29.48050  3.728270       0.000000     7.576279  6.092618
## East Germany   36.12894 10.458489       7.576279     0.000000 12.760094
## Hungary        24.03872  3.898718       6.092618    12.760094  0.000000
## Poland         19.71649  7.000000      10.125216    17.124252  4.758151
## Rumania        23.10130  7.445133       9.146037    16.533905  7.406079
## USSR           23.18146  9.152049      12.020815    16.493029  8.586035
## Yugoslavia     15.32775 23.200862      25.492352    32.113860 21.276748
##                   Poland   Rumania      USSR Yugoslavia
## Belgium        16.709279 20.811776 14.814857   27.91344
## Denmark        19.028663 24.503877 14.337015   29.36443
## France         12.750294 16.394511 12.733028   23.86315
## West Germany   14.427751 15.319595 14.310136   27.63946
## Ireland        11.876447 17.221498 12.938702   21.15018
## Italy          11.841875 15.171684 13.226867   24.42806
## Luxembourg     13.107631 15.136710 15.082109   24.62702
## Netherlands    17.807021 22.923787 14.992998   27.57444
## United Kingdom 16.865646 20.548966 14.123385   29.32627
## Austria        11.216506 12.787494 14.335620   22.06785
## Finland        12.097107 16.831815 10.347947   23.80756
## Greece         10.663020 13.957435 16.351758   12.52757
## Norway         16.007498 21.601620 12.769495   26.95181
## Portugal        6.711930 10.812030 10.990450   18.10110
## Spain          10.170054  8.867920 15.607370   15.63106
## Sweden         18.580097 23.428402 13.706933   30.39309
## Switzerland    16.559287 15.110261 19.462014   26.98240
## Turkey         19.716491 23.101299 23.181458   15.32775
## Bulgaria        7.000000  7.445133  9.152049   23.20086
## Czechoslovakia 10.125216  9.146037 12.020815   25.49235
## East Germany   17.124252 16.533905 16.493029   32.11386
## Hungary         4.758151  7.406079  8.586035   21.27675
## Poland          0.000000  6.737210  8.128961   18.08093
## Rumania         6.737210  0.000000 13.416781   18.27977
## USSR            8.128961 13.416781  0.000000   24.07198
## Yugoslavia     18.080929 18.279770 24.071975    0.00000

Euclidean (scaled)

jarak1sc <- dist(scale(ejobs[,-1]))
as.matrix(jarak1sc)
##                 Belgium  Denmark   France West Germany  Ireland    Italy
## Belgium        0.000000 1.913380 1.398099     2.024304 2.314730 2.687861
## Denmark        1.913380 0.000000 2.280847     3.071147 3.139385 3.142171
## France         1.398099 2.280847 0.000000     1.760833 2.071338 2.071850
## West Germany   2.024304 3.071147 1.760833     0.000000 2.611834 2.832038
## Ireland        2.314730 3.139385 2.071338     2.611834 0.000000 2.885474
## Italy          2.687861 3.142171 2.071850     2.832038 2.885474 0.000000
## Luxembourg     2.797269 4.125789 2.590611     2.527962 3.194806 3.003237
## Netherlands    1.615921 1.728998 1.729461     3.131611 2.704444 2.852434
## United Kingdom 1.857198 3.064551 2.176238     1.911463 2.128854 3.739920
## Austria        2.174809 3.584441 1.939532     2.204076 2.017716 3.010821
## Finland        1.695412 2.406994 2.086228     2.296645 1.870234 3.441709
## Greece         3.565205 3.598793 3.049447     3.510200 2.750969 2.809650
## Norway         1.971916 2.084009 2.924175     3.401170 3.100368 3.389147
## Portugal       2.766680 2.876070 1.972610     2.495986 2.367563 1.676145
## Spain          3.925897 4.145629 2.919303     3.647972 4.264841 3.476381
## Sweden         1.621321 1.117308 2.078270     2.344783 2.728719 3.257727
## Switzerland    2.722247 3.699448 1.985831     2.190709 3.376774 2.290328
## Turkey         6.975945 6.470535 6.423003     6.392958 5.882189 6.390488
## Bulgaria       3.681015 4.047691 3.310189     2.500259 3.422288 3.084621
## Czechoslovakia 4.017661 4.951754 3.748105     2.888136 3.565864 3.975108
## East Germany   4.075999 5.178487 4.296125     3.087630 4.121792 4.709833
## Hungary        4.751438 5.767370 4.715206     4.164232 3.773670 5.325247
## Poland         3.900430 4.363259 3.508984     3.101222 3.118327 3.535860
## Rumania        4.584458 4.903991 3.723544     3.305269 3.929457 3.478610
## USSR           4.000701 3.811592 4.139482     3.899066 4.102031 3.878408
## Yugoslavia     5.751929 5.936472 5.068101     5.135482 5.012223 6.329129
##                Luxembourg Netherlands United Kingdom  Austria  Finland   Greece
## Belgium          2.797269    1.615921       1.857198 2.174809 1.695412 3.565205
## Denmark          4.125789    1.728998       3.064551 3.584441 2.406994 3.598793
## France           2.590611    1.729461       2.176238 1.939532 2.086228 3.049447
## West Germany     2.527962    3.131611       1.911463 2.204076 2.296645 3.510200
## Ireland          3.194806    2.704444       2.128854 2.017716 1.870234 2.750969
## Italy            3.003237    2.852434       3.739920 3.010821 3.441709 2.809650
## Luxembourg       0.000000    3.754659       3.106050 2.723963 3.682594 3.930071
## Netherlands      3.754659    0.000000       2.784278 2.679966 2.172200 3.758823
## United Kingdom   3.106050    2.784278       0.000000 2.197096 1.710339 4.266752
## Austria          2.723963    2.679966       2.197096 0.000000 1.887206 3.349992
## Finland          3.682594    2.172200       1.710339 1.887206 0.000000 3.317867
## Greece           3.930071    3.758823       4.266752 3.349992 3.317867 0.000000
## Norway           3.959648    2.281092       3.239779 3.115320 2.185745 3.548572
## Portugal         3.416434    2.980749       3.492823 2.840624 2.841405 1.574046
## Spain            3.848529    3.653089       4.630820 3.417022 4.125931 3.526701
## Sweden           3.832322    2.081390       2.183799 3.210012 1.885289 3.727973
## Switzerland      3.243016    3.117831       3.406561 2.373048 3.203635 3.633781
## Turkey           7.154294    7.322203       7.005417 7.257127 6.689246 4.745617
## Bulgaria         3.135473    4.448289       3.799724 3.430151 3.614566 2.876548
## Czechoslovakia   2.819866    4.809966       3.564331 3.024492 3.795910 4.053181
## East Germany     3.413218    5.141248       3.481326 3.398859 3.845834 4.983846
## Hungary          4.049772    5.367946       3.878780 3.380534 3.999684 4.869442
## Poland           3.032606    4.496571       3.842104 3.251652 3.611736 2.733098
## Rumania          3.516261    5.064422       4.625750 3.944939 4.511161 2.976682
## USSR             4.326760    4.344614       4.548803 4.083766 3.732499 3.353008
## Yugoslavia       5.788866    6.052692       5.417066 5.340476 5.249552 4.709772
##                  Norway Portugal    Spain   Sweden Switzerland   Turkey
## Belgium        1.971916 2.766680 3.925897 1.621321    2.722247 6.975945
## Denmark        2.084009 2.876070 4.145629 1.117308    3.699448 6.470535
## France         2.924175 1.972610 2.919303 2.078270    1.985831 6.423003
## West Germany   3.401170 2.495986 3.647972 2.344783    2.190709 6.392958
## Ireland        3.100368 2.367563 4.264841 2.728719    3.376774 5.882189
## Italy          3.389147 1.676145 3.476381 3.257727    2.290328 6.390488
## Luxembourg     3.959648 3.416434 3.848529 3.832322    3.243016 7.154294
## Netherlands    2.281092 2.980749 3.653089 2.081390    3.117831 7.322203
## United Kingdom 3.239779 3.492823 4.630820 2.183799    3.406561 7.005417
## Austria        3.115320 2.840624 3.417022 3.210012    2.373048 7.257127
## Finland        2.185745 2.841405 4.125931 1.885289    3.203635 6.689246
## Greece         3.548572 1.574046 3.526701 3.727973    3.633781 4.745617
## Norway         0.000000 3.342825 4.641898 2.341445    3.943175 7.316513
## Portugal       3.342825 0.000000 3.104232 2.866156    2.465606 5.129281
## Spain          4.641898 3.104232 0.000000 4.361890    2.862956 7.056781
## Sweden         2.341445 2.866156 4.361890 0.000000    3.495983 6.332430
## Switzerland    3.943175 2.465606 2.862956 3.495983    0.000000 7.174045
## Turkey         7.316513 5.129281 7.056781 6.332430    7.174045 0.000000
## Bulgaria       4.002133 2.542873 3.990036 3.679657    3.549299 5.709432
## Czechoslovakia 4.517483 3.787175 4.432895 4.427430    3.997172 7.145495
## East Germany   4.441425 4.631191 5.442631 4.499453    4.454183 8.020179
## Hungary        4.969826 4.969085 5.570656 5.209386    5.279530 7.919549
## Poland         4.083596 2.928918 4.004394 4.070353    4.136405 5.805518
## Rumania        5.184721 2.787273 3.494919 4.654024    3.816895 5.333140
## USSR           3.109906 3.515949 4.662901 3.852573    4.695428 6.795206
## Yugoslavia     6.626604 4.997056 4.909996 5.655063    5.775981 5.052574
##                Bulgaria Czechoslovakia East Germany  Hungary   Poland  Rumania
## Belgium        3.681015       4.017661     4.075999 4.751438 3.900430 4.584458
## Denmark        4.047691       4.951754     5.178487 5.767370 4.363259 4.903991
## France         3.310189       3.748105     4.296125 4.715206 3.508984 3.723544
## West Germany   2.500259       2.888136     3.087630 4.164232 3.101222 3.305269
## Ireland        3.422288       3.565864     4.121792 3.773670 3.118327 3.929457
## Italy          3.084621       3.975108     4.709833 5.325247 3.535860 3.478610
## Luxembourg     3.135473       2.819866     3.413218 4.049772 3.032606 3.516261
## Netherlands    4.448289       4.809966     5.141248 5.367946 4.496571 5.064422
## United Kingdom 3.799724       3.564331     3.481326 3.878780 3.842104 4.625750
## Austria        3.430151       3.024492     3.398859 3.380534 3.251652 3.944939
## Finland        3.614566       3.795910     3.845834 3.999684 3.611736 4.511161
## Greece         2.876548       4.053181     4.983846 4.869442 2.733098 2.976682
## Norway         4.002133       4.517483     4.441425 4.969826 4.083596 5.184721
## Portugal       2.542873       3.787175     4.631191 4.969085 2.928918 2.787273
## Spain          3.990036       4.432895     5.442631 5.570656 4.004394 3.494919
## Sweden         3.679657       4.427430     4.499453 5.209386 4.070353 4.654024
## Switzerland    3.549299       3.997172     4.454183 5.279530 4.136405 3.816895
## Turkey         5.709432       7.145495     8.020179 7.919549 5.805518 5.333140
## Bulgaria       0.000000       2.042874     2.917277 3.826906 1.459455 1.741331
## Czechoslovakia 2.042874       0.000000     1.664958 2.198753 1.734211 2.692212
## East Germany   2.917277       1.664958     0.000000 2.494510 3.004719 4.090286
## Hungary        3.826906       2.198753     2.494510 0.000000 2.931830 4.359212
## Poland         1.459455       1.734211     3.004719 2.931830 0.000000 1.911946
## Rumania        1.741331       2.692212     4.090286 4.359212 1.911946 0.000000
## USSR           2.458499       3.294087     3.660471 4.238674 2.540305 3.695740
## Yugoslavia     5.645526       6.063399     6.876221 6.329391 5.302411 5.018509
##                    USSR Yugoslavia
## Belgium        4.000701   5.751929
## Denmark        3.811592   5.936472
## France         4.139482   5.068101
## West Germany   3.899066   5.135482
## Ireland        4.102031   5.012223
## Italy          3.878408   6.329129
## Luxembourg     4.326760   5.788866
## Netherlands    4.344614   6.052692
## United Kingdom 4.548803   5.417066
## Austria        4.083766   5.340476
## Finland        3.732499   5.249552
## Greece         3.353008   4.709772
## Norway         3.109906   6.626604
## Portugal       3.515949   4.997056
## Spain          4.662901   4.909996
## Sweden         3.852573   5.655063
## Switzerland    4.695428   5.775981
## Turkey         6.795206   5.052574
## Bulgaria       2.458499   5.645526
## Czechoslovakia 3.294087   6.063399
## East Germany   3.660471   6.876221
## Hungary        4.238674   6.329391
## Poland         2.540305   5.302411
## Rumania        3.695740   5.018509
## USSR           0.000000   6.837729
## Yugoslavia     6.837729   0.000000

Manhattan

jarak2 <- dist(ejobs[,-1],method="manhattan")
as.matrix(jarak2)
##                Belgium Denmark France West Germany Ireland Italy Luxembourg
## Belgium            0.0    17.5    8.9         20.8    20.7  16.1       17.1
## Denmark           17.5     0.0   21.0         29.1    21.8  30.0       32.8
## France             8.9    21.0    0.0         14.5    14.2  10.0       13.0
## West Germany      20.8    29.1   14.5          0.0    22.1  21.7       16.5
## Ireland           20.7    21.8   14.2         22.1     0.0  14.2       19.6
## Italy             16.1    30.0   10.0         21.7    14.2   0.0       11.6
## Luxembourg        17.1    32.8   13.0         16.5    19.6  11.6        0.0
## Netherlands       11.7    10.4   15.8         29.5    19.0  21.0       24.8
## United Kingdom    10.1    19.6   12.6         16.1    21.4  21.6       17.2
## Austria           17.7    30.2   11.8         16.9    18.2  14.2        8.6
## Finland           11.2    15.5   10.1         15.6    15.7  18.7       21.1
## Greece            38.2    33.7   32.7         37.4    20.9  29.5       34.9
## Norway            13.0    12.5   15.9         27.0    15.9  22.5       24.9
## Portugal          24.9    25.0   17.0         23.1    14.2  14.4       20.2
## Spain             32.7    39.6   24.4         31.5    35.0  26.6       27.8
## Sweden            14.4     6.9   17.1         22.8    24.5  26.5       28.9
## Switzerland       27.5    39.8   20.2         16.1    29.4  20.4       16.2
## Turkey            63.8    59.5   56.3         60.2    44.1  51.5       59.5
## Bulgaria          31.8    39.5   26.7         20.4    27.7  22.1       20.1
## Czechoslovakia    34.8    42.9   29.3         18.2    31.3  25.3       20.9
## East Germany      35.2    43.7   31.1         17.2    33.3  31.1       28.5
## Hungary           30.4    38.9   26.3         26.0    27.1  22.3       19.9
## Poland            31.4    35.7   26.1         30.4    24.5  22.3       25.1
## Rumania           39.7    47.2   31.6         32.1    35.0  27.0       27.0
## USSR              27.4    31.5   23.7         29.6    26.9  23.7       30.9
## Yugoslavia        57.2    53.3   50.3         55.2    43.7  55.3       55.1
##                Netherlands United Kingdom Austria Finland Greece Norway
## Belgium               11.7           10.1    17.7    11.2   38.2   13.0
## Denmark               10.4           19.6    30.2    15.5   33.7   12.5
## France                15.8           12.6    11.8    10.1   32.7   15.9
## West Germany          29.5           16.1    16.9    15.6   37.4   27.0
## Ireland               19.0           21.4    18.2    15.7   20.9   15.9
## Italy                 21.0           21.6    14.2    18.7   29.5   22.5
## Luxembourg            24.8           17.2     8.6    21.1   34.9   24.9
## Netherlands            0.0           15.2    25.0    16.1   36.1    8.7
## United Kingdom        15.2            0.0    15.4    13.5   41.7   15.7
## Austria               25.0           15.4     0.0    17.5   28.7   22.9
## Finland               16.1           13.5    17.5     0.0   30.4   13.4
## Greece                36.1           41.7    28.7    30.4    0.0   32.6
## Norway                 8.7           15.7    22.9    13.4   32.6    0.0
## Portugal              25.8           28.0    15.0    16.9   16.3   22.9
## Spain                 36.6           35.0    22.4    30.3   24.5   40.1
## Sweden                14.9           13.5    26.7    10.4   37.6   16.2
## Switzerland           32.2           26.6    13.4    28.5   36.5   33.7
## Turkey                61.9           64.3    54.3    54.8   27.6   58.4
## Bulgaria              40.5           28.7    19.5    27.6   28.6   37.2
## Czechoslovakia        42.7           32.3    20.3    30.6   32.4   39.6
## East Germany          44.5           31.7    30.3    28.8   41.4   38.4
## Hungary               39.7           29.1    16.7    25.2   27.0   34.4
## Poland                36.1           34.5    21.1    24.4   21.4   32.8
## Rumania               47.4           36.8    23.8    36.1   23.7   44.3
## USSR                  31.3           31.1    29.9    19.6   32.6   24.2
## Yugoslavia            54.3           57.3    49.5    49.6   27.8   55.4
##                Portugal Spain Sweden Switzerland Turkey Bulgaria Czechoslovakia
## Belgium            24.9  32.7   14.4        27.5   63.8     31.8           34.8
## Denmark            25.0  39.6    6.9        39.8   59.5     39.5           42.9
## France             17.0  24.4   17.1        20.2   56.3     26.7           29.3
## West Germany       23.1  31.5   22.8        16.1   60.2     20.4           18.2
## Ireland            14.2  35.0   24.5        29.4   44.1     27.7           31.3
## Italy              14.4  26.6   26.5        20.4   51.5     22.1           25.3
## Luxembourg         20.2  27.8   28.9        16.2   59.5     20.1           20.9
## Netherlands        25.8  36.6   14.9        32.2   61.9     40.5           42.7
## United Kingdom     28.0  35.0   13.5        26.6   64.3     28.7           32.3
## Austria            15.0  22.4   26.7        13.4   54.3     19.5           20.3
## Finland            16.9  30.3   10.4        28.5   54.8     27.6           30.6
## Greece             16.3  24.5   37.6        36.5   27.6     28.6           32.4
## Norway             22.9  40.1   16.2        33.7   58.4     37.2           39.6
## Portugal            0.0  22.2   24.1        22.8   40.1     19.7           22.9
## Spain              22.2   0.0   36.5        26.8   44.3     25.7           28.1
## Sweden             24.1  36.5    0.0        36.3   61.6     34.8           39.0
## Switzerland        22.8  26.8   36.3         0.0   60.3     26.9           22.7
## Turkey             40.1  44.3   61.6        60.3    0.0     44.2           50.8
## Bulgaria           19.7  25.7   34.8        26.9   44.2      0.0            7.6
## Czechoslovakia     22.9  28.1   39.0        22.7   50.8      7.6            0.0
## East Germany       32.5  41.3   38.6        28.3   63.0     20.2           14.8
## Hungary            17.9  23.7   35.0        30.1   45.8      9.4            9.2
## Poland             13.1  23.3   32.0        31.9   36.4     11.0           14.4
## Rumania            22.2  17.4   43.3        30.6   32.9     14.1           18.7
## USSR               23.1  32.9   28.4        41.7   44.8     18.4           23.8
## Yugoslavia         41.5  33.5   56.0        56.1   31.6     47.2           52.8
##                East Germany Hungary Poland Rumania USSR Yugoslavia
## Belgium                35.2    30.4   31.4    39.7 27.4       57.2
## Denmark                43.7    38.9   35.7    47.2 31.5       53.3
## France                 31.1    26.3   26.1    31.6 23.7       50.3
## West Germany           17.2    26.0   30.4    32.1 29.6       55.2
## Ireland                33.3    27.1   24.5    35.0 26.9       43.7
## Italy                  31.1    22.3   22.3    27.0 23.7       55.3
## Luxembourg             28.5    19.9   25.1    27.0 30.9       55.1
## Netherlands            44.5    39.7   36.1    47.4 31.3       54.3
## United Kingdom         31.7    29.1   34.5    36.8 31.1       57.3
## Austria                30.3    16.7   21.1    23.8 29.9       49.5
## Finland                28.8    25.2   24.4    36.1 19.6       49.6
## Greece                 41.4    27.0   21.4    23.7 32.6       27.8
## Norway                 38.4    34.4   32.8    44.3 24.2       55.4
## Portugal               32.5    17.9   13.1    22.2 23.1       41.5
## Spain                  41.3    23.7   23.3    17.4 32.9       33.5
## Sweden                 38.6    35.0   32.0    43.3 28.4       56.0
## Switzerland            28.3    30.1   31.9    30.6 41.7       56.1
## Turkey                 63.0    45.8   36.4    32.9 44.8       31.6
## Bulgaria               20.2     9.4   11.0    14.1 18.4       47.2
## Czechoslovakia         14.8     9.2   14.4    18.7 23.8       52.8
## East Germany            0.0    20.4   28.6    32.9 27.4       64.8
## Hungary                20.4     0.0    9.8    15.7 19.2       47.8
## Poland                 28.6     9.8    0.0    13.7 14.0       38.8
## Rumania                32.9    15.7   13.7     0.0 22.7       36.1
## USSR                   27.4    19.2   14.0    22.7  0.0       48.6
## Yugoslavia             64.8    47.8   38.8    36.1 48.6        0.0

Manhattan (scaled)

jarak2sc <- dist(scale(ejobs[,-1]),method="manhattan")
as.matrix(jarak2sc)
##                  Belgium   Denmark    France West Germany   Ireland     Italy
## Belgium         0.000000  4.492820  2.780393     5.004385  5.930244  6.353646
## Denmark         4.492820  0.000000  5.767818     7.386368  7.618614  7.930704
## France          2.780393  5.767818  0.000000     3.884401  4.781720  4.170068
## West Germany    5.004385  7.386368  3.884401     0.000000  5.176846  7.225460
## Ireland         5.930244  7.618614  4.781720     5.176846  0.000000  6.144297
## Italy           6.353646  7.930704  4.170068     7.225460  6.144297  0.000000
## Luxembourg      6.101492  9.535152  5.017609     5.553915  7.287261  5.964866
## Netherlands     3.871218  3.742790  4.510355     7.819824  6.758544  6.528136
## United Kingdom  4.488326  7.377880  5.014636     4.364269  4.767327  8.898666
## Austria         4.936946  8.159087  4.259799     5.379696  4.616797  6.763799
## Finland         4.142746  5.196117  4.866946     5.079067  4.432831  8.268354
## Greece          8.253042  6.766360  7.760740     8.248320  6.247035  6.626099
## Norway          4.406061  4.682420  5.361371     7.593613  6.821618  7.617363
## Portugal        7.022196  5.566021  4.849489     6.276613  5.359839  3.928632
## Spain           9.031317  9.808582  6.421987     8.884014 10.676585  7.431272
## Sweden          3.866765  2.561146  4.689577     5.005328  6.738207  7.915683
## Switzerland     6.621259  8.174550  4.175400     5.104315  7.931167  5.106804
## Turkey         18.307615 17.027109 16.377983    16.468197 14.709986 14.347815
## Bulgaria        8.656357  9.443511  8.398771     6.242486  8.170343  7.077850
## Czechoslovakia  9.760197 12.020642  9.326124     7.228864  8.475166  9.600032
## East Germany   10.459818 12.985533 10.920897     7.401108  8.582119 11.780495
## Hungary        11.171222 13.696937 11.632301    10.611202  9.642047 11.906209
## Poland          8.218923  9.937112  7.977189     7.798499  7.842731  8.279636
## Rumania        11.088818 11.754434  8.786215     8.805035 10.105018  7.465294
## USSR            8.998191  9.293824  8.872815     9.389665  9.901705  7.947935
## Yugoslavia     14.708155 15.221045 13.127222    12.899170 12.264022 16.565176
##                Luxembourg Netherlands United Kingdom   Austria   Finland
## Belgium          6.101492    3.871218       4.488326  4.936946  4.142746
## Denmark          9.535152    3.742790       7.377880  8.159087  5.196117
## France           5.017609    4.510355       5.014636  4.259799  4.866946
## West Germany     5.553915    7.819824       4.364269  5.379696  5.079067
## Ireland          7.287261    6.758544       4.767327  4.616797  4.432831
## Italy            5.964866    6.528136       8.898666  6.763799  8.268354
## Luxembourg       0.000000    7.920126       7.048450  5.268551  8.809583
## Netherlands      7.920126    0.000000       6.274318  6.535943  5.485449
## United Kingdom   7.048450    6.274318       0.000000  4.007368  4.214333
## Austria          5.268551    6.535943       4.007368  0.000000  4.775470
## Finland          8.809583    5.485449       4.214333  4.775470  0.000000
## Greece           9.534739    8.994423      10.583163  8.100829  8.074780
## Norway           8.158592    4.737204       7.283539  6.968763  5.203468
## Portugal         7.342153    7.472769       9.042654  6.626908  6.553118
## Spain            9.262302    9.146877      11.151225  8.576347 10.370951
## Sweden           8.456912    4.609739       4.962731  7.368313  3.455241
## Switzerland      5.554476    6.413479       8.161964  5.345753  7.861333
## Turkey          18.870646   19.255172      18.748089 18.155401 17.484768
## Bulgaria         6.963018   11.471796       8.970487  7.759740  9.338725
## Czechoslovakia   6.360218   11.723806       9.275310  6.573212  9.212349
## East Germany     8.804242   13.318579       9.001563  8.866326  8.076204
## Hungary          8.596519   14.029983      10.081820  7.782417  9.516832
## Poland           6.777800   10.392764       9.927165  7.411282  8.780726
## Rumania          7.856553   13.296570      11.364900  9.203071 12.135798
## USSR            10.040818   10.659473      11.137632  9.740141  8.985062
## Yugoslavia      15.705922   15.108886      13.410836 14.006769 13.733272
##                   Greece    Norway  Portugal     Spain    Sweden Switzerland
## Belgium         8.253042  4.406061  7.022196  9.031317  3.866765    6.621259
## Denmark         6.766360  4.682420  5.566021  9.808582  2.561146    8.174550
## France          7.760740  5.361371  4.849489  6.421987  4.689577    4.175400
## West Germany    8.248320  7.593613  6.276613  8.884014  5.005328    5.104315
## Ireland         6.247035  6.821618  5.359839 10.676585  6.738207    7.931167
## Italy           6.626099  7.617363  3.928632  7.431272  7.915683    5.106804
## Luxembourg      9.534739  8.158592  7.342153  9.262302  8.456912    5.554476
## Netherlands     8.994423  4.737204  7.472769  9.146877  4.609739    6.413479
## United Kingdom 10.583163  7.283539  9.042654 11.151225  4.962731    8.161964
## Austria         8.100829  6.968763  6.626908  8.576347  7.368313    5.345753
## Finland         8.074780  5.203468  6.553118 10.370951  3.455241    7.861333
## Greece          0.000000  7.994278  3.529780  7.639966  7.590969    8.384861
## Norway          7.994278  0.000000  6.913516 11.251748  5.034271    7.844088
## Portugal        3.529780  6.913516  0.000000  6.950498  6.069307    5.235779
## Spain           7.639966 11.251748  6.950498  0.000000  9.530832    6.942669
## Sweden          7.590969  5.034271  6.069307  9.530832  0.000000    7.508663
## Switzerland     8.384861  7.844088  5.235779  6.942669  7.508663    0.000000
## Turkey         10.524310 18.255027 12.353199 15.212185 16.757882   17.208279
## Bulgaria        5.984308 10.500191  5.875625  9.079968  8.854914    8.885302
## Czechoslovakia  9.147860 11.649491  8.674565 10.982686 11.142442    9.343138
## East Germany   11.243360 11.110464 11.134677 14.463111 11.400305   11.511446
## Hungary        10.641359 12.396801 10.411139 13.083871 12.840932   13.128170
## Poland          6.393475  9.809036  6.095887  9.392027  8.972258    9.750263
## Rumania         6.634811 12.446502  6.188413  7.305735 11.651987    9.080654
## USSR            8.233994  6.823765  7.760699 10.763317  9.651115   11.653163
## Yugoslavia     11.376408 16.668452 13.255073 11.213820 14.244907   15.194135
##                  Turkey  Bulgaria Czechoslovakia East Germany   Hungary
## Belgium        18.30761  8.656357       9.760197    10.459818 11.171222
## Denmark        17.02711  9.443511      12.020642    12.985533 13.696937
## France         16.37798  8.398771       9.326124    10.920897 11.632301
## West Germany   16.46820  6.242486       7.228864     7.401108 10.611202
## Ireland        14.70999  8.170343       8.475166     8.582119  9.642047
## Italy          14.34782  7.077850       9.600032    11.780495 11.906209
## Luxembourg     18.87065  6.963018       6.360218     8.804242  8.596519
## Netherlands    19.25517 11.471796      11.723806    13.318579 14.029983
## United Kingdom 18.74809  8.970487       9.275310     9.001563 10.081820
## Austria        18.15540  7.759740       6.573212     8.866326  7.782417
## Finland        17.48477  9.338725       9.212349     8.076204  9.516832
## Greece         10.52431  5.984308       9.147860    11.243360 10.641359
## Norway         18.25503 10.500191      11.649491    11.110464 12.396801
## Portugal       12.35320  5.875625       8.674565    11.134677 10.411139
## Spain          15.21218  9.079968      10.982686    14.463111 13.083871
## Sweden         16.75788  8.854914      11.142442    11.400305 12.840932
## Switzerland    17.20828  8.885302       9.343138    11.511446 13.128170
## Turkey          0.00000 13.339437      17.270624    19.703968 18.851550
## Bulgaria       13.33944  0.000000       4.161564     7.014189  6.718056
## Czechoslovakia 17.27062  4.161564       0.000000     3.912777  4.077451
## East Germany   19.70397  7.014189       3.912777     0.000000  5.326174
## Hungary        18.85155  6.718056       4.077451     5.326174  0.000000
## Poland         13.77311  3.293365       3.497513     7.045678  5.321514
## Rumania        11.07266  3.852517       6.399054    10.098046  8.730365
## USSR           15.00164  5.378727       8.136794     8.807357  9.093067
## Yugoslavia     11.46685 13.732085      15.005224    17.367307 16.586150
##                   Poland   Rumania      USSR Yugoslavia
## Belgium         8.218923 11.088818  8.998191   14.70815
## Denmark         9.937112 11.754434  9.293824   15.22105
## France          7.977189  8.786215  8.872815   13.12722
## West Germany    7.798499  8.805035  9.389665   12.89917
## Ireland         7.842731 10.105018  9.901705   12.26402
## Italy           8.279636  7.465294  7.947935   16.56518
## Luxembourg      6.777800  7.856553 10.040818   15.70592
## Netherlands    10.392764 13.296570 10.659473   15.10889
## United Kingdom  9.927165 11.364900 11.137632   13.41084
## Austria         7.411282  9.203071  9.740141   14.00677
## Finland         8.780726 12.135798  8.985062   13.73327
## Greece          6.393475  6.634811  8.233994   11.37641
## Norway          9.809036 12.446502  6.823765   16.66845
## Portugal        6.095887  6.188413  7.760699   13.25507
## Spain           9.392027  7.305735 10.763317   11.21382
## Sweden          8.972258 11.651987  9.651115   14.24491
## Switzerland     9.750263  9.080654 11.653163   15.19413
## Turkey         13.773110 11.072662 15.001641   11.46685
## Bulgaria        3.293365  3.852517  5.378727   13.73208
## Czechoslovakia  3.497513  6.399054  8.136794   15.00522
## East Germany    7.045678 10.098046  8.807357   17.36731
## Hungary         5.321514  8.730365  9.093067   16.58615
## Poland          0.000000  4.521902  5.703287   12.57093
## Rumania         4.521902  0.000000  6.800515   11.48279
## USSR            5.703287  6.800515  0.000000   15.73161
## Yugoslavia     12.570930 11.482786 15.731606    0.00000

Visualisasi Dendogram

clustsingle1 <- hclust(jarak1, method="single")
clustcomp1 <- hclust(jarak1, method="complete")
clustsingle1sc <- hclust(jarak1sc, method="single")
clustcomp1sc <- hclust(jarak1sc, method="complete")
clustsingle2 <- hclust(jarak2, method="single")
clustcomp2 <- hclust(jarak2, method="complete")
clustsingle2sc <- hclust(jarak2sc, method="single")
clustcomp2sc <- hclust(jarak2sc, method="complete")

Single Linkage

par(mfrow = c(1, 2))
plot(clustsingle1, main = "Eucledian")
plot(clustsingle2, main = "Manhattan")

Single Linkage (Scaled)

par(mfrow=c(1,2))
plot(clustsingle1sc, main = "Eucledian Scaled")
plot(clustsingle2sc, main = "Manhattan Scaled")

Complete Linkage

par(mfrow=c(1,2))
plot(clustcomp1, main = "Eucledian")
plot(clustcomp2, main = "Manhattan")

Complete Linkage (Scaled)

par(mfrow=c(1,2))
plot(clustcomp1sc, main = "Eucledian Scaled")
plot(clustcomp2sc, main = "Manhattan Scaled")

Package cluster memuat lebih banyak pilihan untuk melakukan cluster analysis.

pltree(diana(jarak1sc))

Non Hierachical

Berikutnya kita akan melakukan k-means clustering dengan 2 klaster.

set.seed(121)
model <- kmeans(ejobs, centers = 2)
model
## K-means clustering with 2 clusters of sizes 21, 5
## 
## Cluster means:
##        Agr  Min      Man        PS      Con       SI      Fin      SPS      TC
## 1 13.08095 1.20 28.76667 0.9666667 8.542857 14.30476 4.142857 22.12381 6.87619
## 2 44.54000 1.48 19.62000 0.6600000 6.580000  7.30000 3.400000 11.20000 5.16000
## 
## Clustering vector:
##        Belgium        Denmark         France   West Germany        Ireland 
##              1              1              1              1              1 
##          Italy     Luxembourg    Netherlands United Kingdom        Austria 
##              1              1              1              1              1 
##        Finland         Greece         Norway       Portugal          Spain 
##              1              2              1              1              1 
##         Sweden    Switzerland         Turkey       Bulgaria Czechoslovakia 
##              1              1              2              1              1 
##   East Germany        Hungary         Poland        Rumania           USSR 
##              1              1              2              2              1 
##     Yugoslavia 
##              2 
## 
## Within cluster sum of squares by cluster:
## [1] 2953.174 1301.360
##  (between_SS / total_SS =  54.3 %)
## 
## Available components:
## 
## [1] "cluster"      "centers"      "totss"        "withinss"     "tot.withinss"
## [6] "betweenss"    "size"         "iter"         "ifault"
# displays the class determined by
# the model for all observations:
model$cluster
##        Belgium        Denmark         France   West Germany        Ireland 
##              1              1              1              1              1 
##          Italy     Luxembourg    Netherlands United Kingdom        Austria 
##              1              1              1              1              1 
##        Finland         Greece         Norway       Portugal          Spain 
##              1              2              1              1              1 
##         Sweden    Switzerland         Turkey       Bulgaria Czechoslovakia 
##              1              1              2              1              1 
##   East Germany        Hungary         Poland        Rumania           USSR 
##              1              1              2              2              1 
##     Yugoslavia 
##              2
table(model$cluster)
## 
##  1  2 
## 21  5

Klaster pada masing-masing amatan dapat disimpan langsung ke dalam dataset menjadi sebuah kolom.

Eurojobs_cluster <- data.frame(ejobs,
  cluster = as.factor(model$cluster)
)

Eurojobs_cluster
##                 Agr Min  Man  PS  Con   SI  Fin  SPS  TC cluster
## Belgium         3.3 0.9 27.6 0.9  8.2 19.1  6.2 26.6 7.2       1
## Denmark         9.2 0.1 21.8 0.6  8.3 14.6  6.5 32.2 7.1       1
## France         10.8 0.8 27.5 0.9  8.9 16.8  6.0 22.6 5.7       1
## West Germany    6.7 1.3 35.8 0.9  7.3 14.4  5.0 22.3 6.1       1
## Ireland        23.2 1.0 20.7 1.3  7.5 16.8  2.8 20.8 6.1       1
## Italy          15.9 0.6 27.6 0.5 10.0 18.1  1.6 20.1 5.7       1
## Luxembourg      7.7 3.1 30.8 0.8  9.2 18.5  4.6 19.2 6.2       1
## Netherlands     6.3 0.1 22.5 1.0  9.9 18.0  6.8 28.5 6.8       1
## United Kingdom  2.7 1.4 30.2 1.4  6.9 16.9  5.7 28.3 6.4       1
## Austria        12.7 1.1 30.2 1.4  9.0 16.8  4.9 16.8 7.0       1
## Finland        13.0 0.4 25.9 1.3  7.4 14.7  5.5 24.3 7.6       1
## Greece         41.4 0.6 17.6 0.6  8.1 11.5  2.4 11.0 6.7       2
## Norway          9.0 0.5 22.4 0.8  8.6 16.9  4.7 27.6 9.4       1
## Portugal       27.8 0.3 24.5 0.6  8.4 13.3  2.7 16.7 5.7       1
## Spain          22.9 0.8 28.5 0.7 11.5  9.7  8.5 11.8 5.5       1
## Sweden          6.1 0.4 25.9 0.8  7.2 14.4  6.0 32.4 6.8       1
## Switzerland     7.7 0.2 37.8 0.8  9.5 17.5  5.3 15.4 5.7       1
## Turkey         66.8 0.7  7.9 0.1  2.8  5.2  1.1 11.9 3.2       2
## Bulgaria       23.6 1.9 32.3 0.6  7.9  8.0  0.7 18.2 6.7       1
## Czechoslovakia 16.5 2.9 35.5 1.2  8.7  9.2  0.9 17.9 7.0       1
## East Germany    4.2 2.9 41.2 1.3  7.6 11.2  1.2 22.1 8.4       1
## Hungary        21.7 3.1 29.6 1.9  8.2  9.4  0.9 17.2 8.0       1
## Poland         31.1 2.5 25.7 0.9  8.4  7.5  0.9 16.1 6.9       2
## Rumania        34.7 2.1 30.1 0.6  8.7  5.9  1.3 11.7 5.0       2
## USSR           23.7 1.4 25.8 0.6  9.2  6.1  0.5 23.6 9.3       1
## Yugoslavia     48.7 1.5 16.8 1.1  4.9  6.4 11.3  5.3 4.0       2

Kualitas dari K-Means Partition dapat dilihat dengan menghitung persentase dari Total Sum of Squares (TSS) “explained” dengan formula: (BSS/TSS) x 100% di mana BSS merupakan Between Sum of Squares. Semakin tinggi persentase maka semakin baik kualitas dari K-Means Partition karena BSS yang besar atau WSS (Within Sum of Squares) yang kecil.

(BSS <- model$betweenss)
## [1] 5045.056
(TSS <- model$totss)
## [1] 9299.59
BSS / TSS * 100
## [1] 54.2503

Selanjutkan kita akan melihat bagaimana K-Means Clustering dengan 3 klaster.

set.seed(123)
model2 <- kmeans(ejobs, centers = 3)
model2
## K-means clustering with 3 clusters of sizes 9, 14, 3
## 
## Cluster means:
##         Agr       Min      Man        PS      Con        SI      Fin      SPS
## 1 25.022222 1.7777778 28.07778 0.9333333 8.722222  9.544444 2.133333 17.11111
## 2  8.235714 0.9857143 29.08571 0.9571429 8.428571 16.278571 5.000000 24.17143
## 3 52.300000 0.9333333 14.10000 0.6000000 5.266667  7.700000 4.933333  9.40000
##         TC
## 1 6.688889
## 2 6.864286
## 3 4.633333
## 
## Clustering vector:
##        Belgium        Denmark         France   West Germany        Ireland 
##              2              2              2              2              1 
##          Italy     Luxembourg    Netherlands United Kingdom        Austria 
##              2              2              2              2              2 
##        Finland         Greece         Norway       Portugal          Spain 
##              2              3              2              1              1 
##         Sweden    Switzerland         Turkey       Bulgaria Czechoslovakia 
##              2              2              3              1              1 
##   East Germany        Hungary         Poland        Rumania           USSR 
##              2              1              1              1              1 
##     Yugoslavia 
##              3 
## 
## Within cluster sum of squares by cluster:
## [1]  691.3022 1139.6936  531.6067
##  (between_SS / total_SS =  74.6 %)
## 
## Available components:
## 
## [1] "cluster"      "centers"      "totss"        "withinss"     "tot.withinss"
## [6] "betweenss"    "size"         "iter"         "ifault"
model2$cluster
##        Belgium        Denmark         France   West Germany        Ireland 
##              2              2              2              2              1 
##          Italy     Luxembourg    Netherlands United Kingdom        Austria 
##              2              2              2              2              2 
##        Finland         Greece         Norway       Portugal          Spain 
##              2              3              2              1              1 
##         Sweden    Switzerland         Turkey       Bulgaria Czechoslovakia 
##              2              2              3              1              1 
##   East Germany        Hungary         Poland        Rumania           USSR 
##              2              1              1              1              1 
##     Yugoslavia 
##              3
table(model2$cluster)
## 
##  1  2  3 
##  9 14  3
BSS2 <- model2$betweenss
TSS2 <- model2$totss
BSS2 / TSS2 * 100
## [1] 74.59455

Dapat dilihat bahwa pengklasteran dengan 3 klaster memiliki nilai kualitas partition yang lebih tinggi.

Hal yang akan selalu terjadi: dengan lebih banyak kelas, partisi akan menjadi lebih halus, dan kontribusi BSS akan lebih tinggi. Di sisi lain, “model” akan menjadi lebih kompleks, memerlukan lebih banyak kelas. Dalam kasus ekstrem di mana k = n (setiap observasi adalah kelas singleton), kita memiliki BSS = TSS, tetapi partisi tersebut kehilangan semua kepentingannya.

set.seed(123)

res_kmeans <- cluster_analysis(ejobs,
  n = 3,
  method = "kmeans"
)

predict(res_kmeans)
##  [1] 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 1 2 2 2 2 2 2 2 1
library(see)
## Warning: package 'see' was built under R version 4.4.3
plot(summary(res_kmeans))

Keuntungan dari fungsi ini adalah dapat memvisualisasikan titik tengah atau rata-rata dari masing-masing variabel pada masing-masing klaster. Dimana terlihat pada hasil cluster 1 dominan ke arah AGR dan CON sementar rendah di MIN

Optimal K

Elbow Method

# Elbow method
fviz_nbclust(ejobs, kmeans, method = "wss") +
  geom_vline(xintercept = 4, linetype = 2) + # add line for better visualisation
  labs(subtitle = "Elbow method") # add subtitle

Lokasi lengkungan/siku dalam plot biasanya dianggap sebagai indikator jumlah klaster yang sesuai karena ini berarti penambahan klaster lainnya tidak banyak meningkatkan partisi. Metode ini menyarankan 4 klaster.

Namun Elbow Method ini kadang-kadang juga ambigu.

Silhouette Method

# Silhouette method
fviz_nbclust(ejobs, kmeans, method = "silhouette") +
  labs(subtitle = "Silhouette method")

Gap Statistic Method

# Gap statistic
set.seed(123)
fviz_nbclust(ejobs, kmeans,
  nstart = 25,
  method = "gap_stat",
  nboot = 500 # reduce it for lower computation time (but less precise results)
) +
  labs(subtitle = "Gap statistic method")

Consensus-based algorithm

n_clust <- n_clusters(ejobs,
  package = c("easystats", "NbClust", "mclust"),
  standardize = FALSE
)
n_clust
## # Method Agreement Procedure:
## 
## The choice of 3 clusters is supported by 15 (51.72%) methods out of 29 (kl, Ch, Hartigan, CCC, Scott, Marriot, trcovw, Tracew, Rubin, Beale, Ratkowsky, Ball, PtBiserial, Dunn, SDindex).
plot(n_clust)

Visualisasi

Untuk memastikan bahwa jumlah klaster memang benar-benar optimal, ada cara untuk mengevaluasi kualitas pengklasteran melalui plot silhouette.

Kita akan buat plot silhouette untuk 2 klaster sebagaimana yang disarankan oleh metode silhouette.

set.seed(123)
km_res <- kmeans(ejobs, centers = 2)

sil <- silhouette(km_res$cluster, dist(ejobs))
fviz_silhouette(sil)
##   cluster size ave.sil.width
## 1       1    5          0.33
## 2       2   21          0.54

Interpretasi dari koefisien silhouette:

Koefisien > 0 artinya amatan diklasterkan dengan baik. Semakin mendekati nilai 1 maka semakin baik pengklasteran.

Koefisien < 0 artinya amatan ditempatkan pada klaster yang salah.

Koefisien = 0 artinya amatan berada di antara dua klaster.

Dilihat pada plot, jika sebagian besar koefisien silhouette positif maka ini menunjukkan bahwa amatan ditempatkan dalam klaster yang benar.

fviz_cluster(km_res, ejobs, ellipse.type = "norm")

Misal kita pilih klaster sebanyak 3.

K Medoids Clustering

pam.res <- pam(ejobs, 2)
print(pam.res)
## Medoids:
##        ID  Agr Min  Man  PS Con   SI Fin  SPS  TC
## France  3 10.8 0.8 27.5 0.9 8.9 16.8 6.0 22.6 5.7
## Poland 23 31.1 2.5 25.7 0.9 8.4  7.5 0.9 16.1 6.9
## Clustering vector:
##        Belgium        Denmark         France   West Germany        Ireland 
##              1              1              1              1              2 
##          Italy     Luxembourg    Netherlands United Kingdom        Austria 
##              1              1              1              1              1 
##        Finland         Greece         Norway       Portugal          Spain 
##              1              2              1              2              2 
##         Sweden    Switzerland         Turkey       Bulgaria Czechoslovakia 
##              1              1              2              2              1 
##   East Germany        Hungary         Poland        Rumania           USSR 
##              1              2              2              2              2 
##     Yugoslavia 
##              2 
## Objective function:
##    build     swap 
## 11.82808 11.35165 
## 
## Available components:
##  [1] "medoids"    "id.med"     "clustering" "objective"  "isolation" 
##  [6] "clusinfo"   "silinfo"    "diss"       "call"       "data"
pam<-eclust(ejobs, "pam", hc_metric="euclidean",k=2)

pam$medoids
##         Agr Min  Man  PS Con   SI Fin  SPS  TC
## France 10.8 0.8 27.5 0.9 8.9 16.8 6.0 22.6 5.7
## Poland 31.1 2.5 25.7 0.9 8.4  7.5 0.9 16.1 6.9
#pam.res$clustering
pam$clustering
##        Belgium        Denmark         France   West Germany        Ireland 
##              1              1              1              1              2 
##          Italy     Luxembourg    Netherlands United Kingdom        Austria 
##              1              1              1              1              1 
##        Finland         Greece         Norway       Portugal          Spain 
##              1              2              1              2              2 
##         Sweden    Switzerland         Turkey       Bulgaria Czechoslovakia 
##              1              1              2              2              1 
##   East Germany        Hungary         Poland        Rumania           USSR 
##              1              2              2              2              2 
##     Yugoslavia 
##              2

K-Means Clustering

km<-eclust(ejobs, "kmeans", hc_metric="euclidean",k=2)

km$cluster
##        Belgium        Denmark         France   West Germany        Ireland 
##              2              2              2              2              2 
##          Italy     Luxembourg    Netherlands United Kingdom        Austria 
##              2              2              2              2              2 
##        Finland         Greece         Norway       Portugal          Spain 
##              2              1              2              2              2 
##         Sweden    Switzerland         Turkey       Bulgaria Czechoslovakia 
##              2              2              1              2              2 
##   East Germany        Hungary         Poland        Rumania           USSR 
##              2              2              1              1              2 
##     Yugoslavia 
##              1

Evaluasi

CH Index

(ch.km<-index.G1(ejobs, cl=km$cluster))
## [1] 28.45936
(ch.pam<-index.G1(ejobs, cl=pam$cluster))
## [1] 25.86314

DB Index

(db.km<-index.DB(ejobs, cl=km$cluster)$DB)
## [1] 0.7919587
(db.pam<-index.DB(ejobs, cl=pam$cluster)$DB)
## [1] 0.9554143

ASW

(sil.km<-fviz_silhouette(km)) 
##   cluster size ave.sil.width
## 1       1    5          0.33
## 2       2   21          0.54

(sil.pam<-fviz_silhouette(pam))
##   cluster size ave.sil.width
## 1       1   15          0.56
## 2       2   11          0.23

Simpulan Evaluasi

clust.eval<-data.frame(
  Method=c("K-Means", "K-Medoids"),
  CH=c(ch.km, ch.pam),
  DB=c(db.km, db.pam),
  ASW=c(colMeans(sil.km$data[3]), colMeans(sil.pam$data[3]))
)
clust.eval
##      Method       CH        DB       ASW
## 1   K-Means 28.45936 0.7919587 0.4975544
## 2 K-Medoids 25.86314 0.9554143 0.4222865

Secara keseluruhan, K-Means lebih unggul dari K-Medoids pada seluruh metrik evaluasi ini:

  • Klaster lebih terpisah dan kompak (CH lebih tinggi).

  • Jarak antar klaster lebih optimal (DB lebih rendah).

  • Struktur klaster lebih sesuai dengan data (ASW lebih tinggi).

library(ggplot2)
library(sf)
## Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE
library(rnaturalearth)
library(rnaturalearthdata)
## 
## Attaching package: 'rnaturalearthdata'
## The following object is masked from 'package:rnaturalearth':
## 
##     countries110
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following object is masked from 'package:MASS':
## 
##     select
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
# Baca data dari file CSV
ejobs <- read.csv(
  file = "C:\\Users\\Ghonniyu\\Downloads\\Eurojobs.csv",
  header = TRUE,
)

# Menambahkan hasil clustering ke data ejobs
ejobs$cluster <- km$cluster  # km$cluster adalah hasil clustering yang sudah dibuat sebelumnya

# Ambil data peta Eropa
europe_map <- ne_countries(scale = "medium", continent = "Europe", returnclass = "sf")

# Gabungkan data ejobs dengan peta Eropa berdasarkan nama negara
map_data <- left_join(europe_map, ejobs, by = c("name" = "Country"))

# Visualisasi dengan ggplot
ggplot(data = map_data) +
  geom_sf(aes(fill = factor(cluster)), color = "black", size = 0.1) +
  scale_fill_manual(values = c("steelblue", "darkorange")) +
  labs(title = "Visualisasi Cluster di Peta Eropa",
       fill = "Cluster") +
  theme_minimal() +
  theme(legend.position = "bottom")

Percobaan dengan k=3

Karena semua nilai metrik sama persis, maka kedua metode menghasilkan kualitas klaster yang identik pada data yang digunakan.