The aim of this clustering analysis is to identify groups of countries based on economic and social indicators, helping to determine which countries offer the best living conditions. By applying different clustering methods, we assess patterns in economic stability, gender equality, and industrial development. The goal is to find the most suitable countries for a high quality of life while identifying those with weaker economic and social structures.
1.K-Means Clustering Using the Elbow Method, four clusters were identified as the optimal number for K-Means. The silhouette analysis showed that:
-Cluster 1 (20 countries) had an average silhouette width of 0.15, indicating weak cohesion.
-Cluster 2 (55 countries) had a silhouette width of 0.27, meaning moderately well-defined clusters.
-Cluster 3 (55 countries) had a silhouette width of 0.21, showing fair separation.
-Cluster 4 (100 countries) had a silhouette width of 0.26, suggesting a reasonable structure. The overall average silhouette score was 0.24, indicating a moderate clustering structure, but some overlap between groups.
A second test with 3 clusters was also performed, resulting in:
Cluster sizes of 56, 117, and 57 countries. The highest silhouette width of 0.31 in one cluster, but a low 0.12 in another. This suggests that 3 clusters might work better, but one cluster is poorly separated.
Using CLARA (a scalable alternative to K-Means), the results were:
3 clusters with sizes 104, 81, and 45. Silhouette scores varied significantly:
-The largest cluster (104) had a low score (0.05), indicating poor clustering. -The other two clusters had ~0.29, suggesting better-defined groups.
-The overall silhouette score (0.19) was lower than K-Means, suggesting that CLARA may not be the best approach for this dataset.
Using the Manhattan distance, PAM was applied and produced:
3 clusters with sizes 103, 55, and 72.
Silhouette scores:
-The highest was 0.21 (moderate clustering quality).
-The lowest was 0.11, indicating weak separation.
-The overall average silhouette score (0.15) was lower than K-Means but slightly better than CLARA.
With DBSCAN, only 100 points were assigned to clusters, while the rest were classified as noise. Among these:
-The largest cluster (65 points) had a silhouette width of 0.14, showing weak cohesion.
-The smallest cluster (4 points) had a high silhouette width (0.57), indicating very well-separated points.
-The overall silhouette score (0.17) suggests that DBSCAN might not be the best method for this dataset, as a large number of countries were treated as outliers.
-K-Means with 3 clusters performed the best, with a higher silhouette score (0.31) than all other methods.
-PAM and CLARA showed weaker cluster structures, with some clusters being poorly defined.
-DBSCAN struggled with the dataset, identifying many noise points rather than meaningful clusters.
-Given the results, the most reliable clustering method appears to be K-Means with 3 or 4 clusters, as it balances cluster separation and structure.
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(cluster)
library(factoextra)
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
library(ggplot2)
setwd("C:/Users/ozdil/Downloads")
data <- read.csv("P_Data_Extract_From_World_Development_Indicators (1)(Sheet3) (1).csv", stringsAsFactors = FALSE, sep = ";")
head(data)
## Feature.and.Country
## 1 Agriculture, forestry, and fishing, value added (% of GDP)
## 2 Current account balance (% of GDP)
## 3 Government expenditure on education, total (% of government expenditure)
## 4 Manufacturing, value added (% of GDP)
## 5 Net financial flows, bilateral (NFL, current US$)
## 6 Real interest rate (%)
## Afghanistan Africa.Eastern.and.Southern Africa.Western.and.Central
## 1 14,23180157 21,2095996
## 2
## 3 14,72915268
## 4 7,606649959 9,986026956 13,80788051
## 5
## 6
## Albania Algeria Andorra Angola Antigua.and.Barbuda
## 1 16,22256753 13,08678415 0,478492136 14,90215242 1,914441289
## 2 -1,196321748 2,19023557 4,933699785 -12,89162094
## 3 13,26102352 12,76951504 7,73896265 9,803515434
## 4 6,877725851 9,29539943 3,397436996 7,99574282 2,500305137
## 5 53537238,3 -33150735,8 -1075956035
## 6 0,269282389 7,084596921 -0,594013727 1,806662976
## Arab.World Argentina Armenia Aruba Australia Austria
## 1 4,925365568 5,929853762 8,481559899 2,573502062 1,296970303
## 2 -3,243512548 -2,309786441 0,254737257 1,325563772
## 3
## 4 11,64900647 16,31749874 10,55772055 5,362504494 15,87201148
## 5 -809242946,7 -62352142,3
## 6 -16,77142291 9,459385801 -0,852277921
## Azerbaijan Bahamas..The Bahrain Bangladesh Barbados Belarus
## 1 5,540890448 0,448443003 0,252106224 11,00369002 1,854009024 7,250383271
## 2 11,51161989 -7,494376622 5,858237577 1,0030677 -1,543536999
## 3 11,59396172 10,67466259 12,47315025
## 4 5,778440801 1,007776267 20,68962134 22,34201887 5,595754047 23,00917676
## 5 -50426634,5 3660785885 -526241451,5
## 6 25,52116823 -1,969468771 0,629461238 2,416056196
## Belgium Belize Benin Bhutan Bolivia
## 1 0,76908294 8,101146127 25,40202588 13,46612931
## 2 -0,698394106 -0,644082652 -33,12140918 -2,604021679
## 3 18,53170967 19,04263687 17,80044174
## 4 11,2544326 6,296362717 10,06232409 10,18579643
## 5 42524848,2 -20839997,1 66877448,3 178904628,7
## 6 1,80997445 7,565038508 9,195612617
## Bosnia.and.Herzegovina Botswana Brazil Brunei.Darussalam
## 1 4,680492361 1,581261324 6,241384676 1,194945472
## 2 -2,32154774 -0,601807749 -1,000382833 12,85044757
## 3
## 4 13,32019294 5,628737819 13,33187799 10,35635051
## 5 69076770,7 1126376 -200429909,3
## 6 -2,48323871 4,517928311 37,20750933 21,11985322
## Bulgaria Burkina.Faso Burundi Cabo.Verde Cambodia Cameroon
## 1 2,517578651 16,33445505 25,21939214 4,644068287 17,07844725 17,29494102
## 2 0,905860034 -23,67748209 -2,583797778 1,30468362
## 3 20,29719734 15,72701359 14,70472336 13,08295155
## 4 10,69070484 4,702977862 26,3329384 13,48749139
## 5 43486648,2 5977320,3 -20953566,8 366483475,5 -376223353,7
## 6 -3,283944257 -0,131115724 3,59940973
## Canada Caribbean.small.states Central.African.Republic
## 1 28,61105552
## 2 -0,729574021
## 3 9,993927956
## 4 3,994339105 17,95123789
## 5 11893644,1
## 6
## Central.Europe.and.the.Baltics Chad Channel.Islands Chile
## 1 2,885955998 25,12523115 0,598873831 3,520272875
## 2 -3,546305608
## 3 16,48435402
## 4 16,22482957 0,807306887 9,206118175
## 5 117553023,2
## 6
## China Colombia Comoros Congo..Dem..Rep. Congo..Rep.
## 1 7,12013561 8,723857807 37,18527377 17,38929861 8,952115876
## 2 1,421693486 -2,511695976 -1,820598003 -5,848935464
## 3 14,72915268
## 4 26,18064358 10,90439299 17,95150179
## 5 -624140133,5 -677584447,8 -1234791,6 50409335,9 -206975567,4
## 6 4,961288028 13,81899976
## Costa.Rica Cote.d.Ivoire Croatia Curacao Cyprus Czechia
## 1 3,800476573 14,3558741 3,357268619 0,268253398 1,179084651 1,731167726
## 2 -1,43159866 0,753574362 -19,95135896 -11,4669307 0,301691698
## 3 15,94641018
## 4 13,61878752 14,36958539 12,11755565 2,713872991 4,347455259 20,01707147
## 5 33233518,2 373215709,6
## 6 9,192541675 -3,21389906
## Denmark Djibouti Dominica Dominican.Republic
## 1 0,756712777 1,76004579 14,79629399 6,366892323
## 2 9,84084616 17,53211386 -33,93606876 -3,603545613
## 3 6,412837029 22,02540588
## 4 15,95901224 2,736467737 13,74503
## 5 92975402,8 -9105777 161866801,8
## 6 2,983837767 7,527087782
## Early.demographic.dividend East.Asia...Pacific
## 1 10,64500157 5,805241489
## 2
## 3
## 4 16,90814702 22,75986858
## 5
## 6
## East.Asia...Pacific..excluding.high.income.
## 1 7,77661183
## 2
## 3
## 4 25,24802708
## 5 508358624
## 6
## East.Asia...Pacific..IDA...IBRD.countries. Ecuador Egypt..Arab.Rep.
## 1 7,763511732 7,677376716 11,5659207
## 2 1,875521904 -3,17277519
## 3 9,694939613
## 4 25,25651215 12,4461144 14,89962455
## 5 -396068777,5 1720266283
## 6 -5,661308504
## El.Salvador Equatorial.Guinea Eritrea Estonia Eswatini
## 1 4,605443029 3,093410455 1,926658365 7,052351219
## 2 -1,369042798 -1,750173546 2,420379534
## 3
## 4 14,00330201 24,64465903 11,91405826 28,77758971
## 5 28620457 -9937764,8 -8188016,2
## 6 9,066212023
## Ethiopia Euro.area Europe...Central.Asia
## 1 35,78979912 1,544524326 2,037237095
## 2 -2,924689133
## 3
## 4 4,479422155 14,48257356 13,83038263
## 5 2052263541
## 6
## Europe...Central.Asia..excluding.high.income.
## 1 6,99571525
## 2
## 3
## 4 16,91218171
## 5 -692358169,1
## 6
## Europe...Central.Asia..IDA...IBRD.countries. European.Union Faroe.Islands
## 1 4,687124466 1,651060355 18,20150593
## 2
## 3
## 4 14,7584802 14,67023599 7,605413015
## 5
## 6
## Fiji Finland France Gabon Gambia..The Georgia
## 1 11,73291019 2,313405532 1,740502752 6,525969125 23,22462833 6,015795111
## 2 -0,424831499 -0,993970971 -8,519289807 -5,551014744
## 3 14,62911034 13,56582355 17,5029583
## 4 9,361786386 14,934509 9,731756181 20,19276648 1,50785255 8,355354957
## 5 4228562,3 -68195432,2 26628737,7 -28288624,3
## 6 0,836818516 4,453296545 10,26012186
## Germany Ghana Greece Grenada Guatemala Guinea
## 1 0,841992092 21,10265098 3,343435145 3,277471183 9,770097792 29,09129871
## 2 5,936535577 1,842485685 -6,163304182 -13,99197779 3,09422459 10,30631006
## 3 12,03531742 10,02691841
## 4 18,53620193 11,22617432 8,730572129 3,573939997 13,98979828
## 5 -23214733,2 22945855,3 -24483760,2 -83502452,7
## 6 2,992578803 4,988067349
## Guinea.Bissau Guyana Haiti Heavily.indebted.poor.countries..HIPC.
## 1 30,73927174 18,15397552 20,88841697
## 2 -3,43849434
## 3 11,23081112 14,77087021
## 4 11,89762939 24,47841491 10,25230433
## 5 -3285533,3 99341061,7 -25421000
## 6 24,37957422 -13,15302126
## Honduras Hong.Kong.SAR..China Hungary IBRD.only Iceland
## 1 11,9797587 0,037899102 4,690144135 7,822987253 3,817860645
## 2 -3,875651525 9,164949053 0,787522464 1,229042395
## 3
## 4 15,32338299 0,944459034 17,1398233 20,65791613 9,550727468
## 5 -9276040,7
## 6 7,74172345 2,912190925 0,481988652 5,517036903
## IDA...IBRD.total IDA.blend IDA.only IDA.total India
## 1 8,612164688 21,02768288 18,33294105 19,2843458 15,99836213
## 2 -0,895916593
## 3 13,85877514 13,70423794
## 4 20,19869045 13,77135838 14,29732488 14,01221822 12,93266398
## 5 9083954011 3318583705
## 6
## Indonesia Iran..Islamic.Rep. Iraq Ireland Israel
## 1 12,52930692 12,83576418 2,804395432 0,875702556
## 2 -0,155931059 11,31170136 8,114688501 4,778829733
## 3
## 4 18,66739125 19,41133549 3,569950872 29,43801615
## 5 -58001108,2 -18760395 -352235546,9
## 6 7,281955254
## Italy Jamaica Japan Jordan Kazakhstan Kenya
## 1 1,856751598 9,023869169 4,809650286 3,94185094 21,80995639
## 2 -0,010754812 3,003634186 3,584036383 -3,748316985 -3,434489785 -3,995862696
## 3
## 4 15,36856132 7,954697639 17,31946119 12,25071402 7,603929788
## 5 -11989766,8 420212847,3 27684074,2 -833705016,7
## 6 -0,875338875 -0,031236104 7,038072697 7,050093845
## Korea..Rep. Kosovo Kuwait Kyrgyz.Republic Lao.PDR
## 1 1,595605728 7,220456222 0,473544675 9,654700615 16,13905684
## 2 2,071949326 -7,499749378 31,39561724 2,553295928
## 3 12,57962227 9,803671837
## 4 24,31054209 12,91912546 7,629056496 12,60302313 9,247877358
## 5 -7937978,4 -84839521,3 1244568,5
## 6 3,06189297 13,26000172 5,017049423
## Late.demographic.dividend Latin.America...Caribbean
## 1 6,255552131 6,509134635
## 2
## 3
## 4 22,11648058 17,89462438
## 5
## 6
## Latin.America...Caribbean..excluding.high.income.
## 1 5,837670408
## 2
## 3
## 4 15,49087397
## 5 -1486013274
## 6
## Latin.America...the.Caribbean..IDA...IBRD.countries. Latvia
## 1 6,741977409 3,84563991
## 2 -3,936035881
## 3
## 4 17,72729477 11,26839571
## 5
## 6
## Least.developed.countries..UN.classification Lebanon Lesotho
## 1 18,82938041 6,639229331
## 2 -28,10366964 -6,7613062
## 3 13,70423794 11,26225662
## 4 14,30169222 13,98369406
## 5 22667701 12561278,1
## 6 11,49373938
## Liberia Lithuania Low...middle.income Low.income Lower.middle.income
## 1 35,77830189 2,715391 9,037199025 24,82304751 15,40749036
## 2 1,100877108
## 3 13,08295155
## 4 14,5770128 20,54328498 9,52462534 14,62416034
## 5 2999808,8 13049881915 2586699143 14076597470
## 6
## Luxembourg Macao.SAR..China Madagascar Malawi Malaysia
## 1 0,229008783 22,6374199 30,37923388 7,785903839
## 2 5,984564467 37,01676611 -17,90494204 1,56542804
## 3 17,11417961
## 4 3,531508447 0,76192436 9,476201071 23,0173409
## 5 117397462,5 -31932018,1
## 6 1,312581472 41,29923632 8,746252762 7,326807192
## Maldives Mali Malta Marshall.Islands Mauritania
## 1 5,105201163 35,10890649 0,686184603 19,47180872 18,74292463
## 2 -21,25557603 6,380450451 -9,073715925
## 3 10,63280487 19,12176895 9,530073166
## 4 1,979395302 15,1176772 6,158228366 2,376899344 6,486703441
## 5 239723351,8 -40735486,3 -64907298,8
## 6 9,616386014
## Mauritius Mexico Micronesia..Fed..Sts. Middle.East...North.Africa
## 1 3,857345641 3,822276069 22,46854348 5,132994276
## 2 -4,423104777 -0,306112938
## 3
## 4 11,05055384 20,06115111 0,492217391 12,50785074
## 5 40635438,5 86947384,7
## 6 0,914376244 6,827262956
## Middle.East...North.Africa..excluding.high.income.
## 1 10,68095941
## 2
## 3
## 4 12,90070701
## 5 2774169012
## 6
## Middle.East...North.Africa..IDA...IBRD.countries. Middle.income Moldova
## 1 10,72358435 8,756595506 7,619443029
## 2 -11,44676238
## 3
## 4 12,91498529 20,74598094 8,218609799
## 5 10463182772 135868069,7
## 6 3,333637939
## Mongolia Montenegro Morocco Mozambique Myanmar Namibia
## 1 9,920602813 5,472186501 11,06461987 25,91145116 22,72223097 7,718255142
## 2 0,596631968 -11,30680946 -0,617116658 -11,57529873 -14,82507685
## 3 22,82551956 24,96954918
## 4 6,298087452 3,176266925 14,49125915 7,115397212 21,86542427 11,23437121
## 5 -48093313,4 -87606545,1 67710456,1 295020832,1 78546385
## 6 -3,797591398 17,47238756 4,241104375
## Nauru Nepal Netherlands Nicaragua Niger Nigeria
## 1 21,18955084 1,722556878 15,33757723 47,81317389 22,72493804
## 2 1,247030316 2,441150873 9,847544792 7,746834342 1,655285972
## 3 12,80697441 4,404170036
## 4 4,571626983 10,84114916 13,75365928 7,176043913 15,36379909
## 5 116879211,9 -14478328,1 -19496552,2 906423002,8
## 6 -1,072654128 1,233050487
## North.Macedonia Norway Oman Other.small.states
## 1 6,627144461 2,09569882 2,30987289 2,537128849
## 2 0,358884359 17,44975043 2,424053599
## 3
## 4 6,060918755 9,040150295 11,02468402
## 5 110425522,4
## 6 -2,158024038 17,81980506
## Pacific.island.small.states Pakistan Palau Panama
## 1 23,32908529 2,9898216 2,45028213
## 2 -0,244214769 -4,487217217
## 3 8,343694687 11,92409611
## 4 7,059639515 13,59728262 1,118862497 4,982166743
## 5 1430342566
## 6
## Papua.New.Guinea Paraguay Peru Philippines Poland Portugal
## 1 16,9595925 11,34884912 7,186233605 9,39675018 2,747493099 2,118419938
## 2 13,61217025 0,243886222 0,829382659 -2,703185302 1,796216938 1,37459627
## 3 18,88845062 16,72798347
## 4 1,660447478 19,43029096 12,68420737 16,21797582 16,75985783 11,86954851
## 5 381774520,1 -16221579,9 47011843,8 1074084966
## 6 12,41398207
## Pre.demographic.dividend Puerto.Rico Qatar Romania
## 1 16,96724518 0,693625146 0,292779133 3,87724564
## 2 17,11368634 -6,973260151
## 3 14,29396391
## 4 10,37806435 45,60445386 8,664704743 12,62196224
## 5
## 6 19,19511594 -3,058418445
## Russian.Federation Rwanda Samoa Sao.Tome.and.Principe
## 1 3,348558891 27,05330576 10,97385808 13,706408
## 2 2,480085622 -11,73037016 4,260104584
## 3 14,77087021 13,74215794 18,34500694
## 4 12,44555779 9,863972933 5,099303422
## 5 91022414,8 -19801628,9 -889915,4
## 6 4,248384632 5,382156617 -0,359754639 -3,183873104
## Saudi.Arabia Senegal Serbia Seychelles Sierra.Leone Singapore
## 1 2,714942864 17,41261524 3,78659627 2,816639035 29,07066848 0,029065782
## 2 3,191364579 -2,402129032 -7,247154267 -4,997292105 19,76910348
## 3 22,54717064
## 4 14,788122 15,17033435 13,29078074 5,563957506 7,670117292 17,64928666
## 5 8718301,6 280481423,9 -14609142,3
## 6 10,56051084 -7,411526866
## Slovak.Republic Slovenia Small.states Solomon.Islands South.Africa
## 1 2,002576707 1,519321619 3,417258083 2,616810424
## 2 -1,677892444 4,472484413 -10,91011573 -1,613666888
## 3
## 4 20,73678962 19,59436626 9,660365735 12,96249801
## 5 13557568,3 114056169,2
## 6 6,38879359
## South.Asia South.Asia..IDA...IBRD. South.Sudan Spain Sri.Lanka
## 1 16,0201687 16,0201687 2,499726361 8,281025141
## 2 13,61008233 2,654942704 1,847993426
## 3 8,678466797 8,678466797
## 4 13,87599418 13,87599418 10,89163625 17,91912166
## 5 10687681255 1854489087
## 6 -20,46469075
## St..Kitts.and.Nevis St..Lucia St..Vincent.and.the.Grenadines
## 1 1,413408021 1,126284025 4,153782009
## 2 -13,57285943 -1,867405401 -13,39284174
## 3
## 4 3,791077521 3,308745085 3,13123241
## 5 112486188 16372331,3
## 6 1,448588007 4,842708966 3,008158488
## Sub.Saharan.Africa Sub.Saharan.Africa..excluding.high.income.
## 1 16,94569281 16,96050019
## 2
## 3 13,85877514 13,85877514
## 4 11,47877784 11,48496103
## 5 1258044467
## 6
## Sub.Saharan.Africa..IDA...IBRD.countries. Sudan Suriname
## 1 16,94569281 5,470144393 7,474500241
## 2 4,297746148
## 3 13,85877514 7,536292076
## 4 11,47877784 25,61056121
## 5 -65825328,2 -22624797
## 6 -13,68110269
## Sweden Switzerland Tajikistan Tanzania Thailand Timor.Leste
## 1 0,99369615 0,62920242 23,68714738 8,576206568 16,86013994
## 2 6,453155172 6,598718032 4,842398854 -3,741731927 1,439234682 -0,833268209
## 3 13,70423794
## 4 14,19071058 18,10646848 8,398510723 24,91144701 1,644998413
## 5 -79411587,6 20018425,2 -215622004,2 -1490501,6
## 6 1,822186737 3,028638612 39,86298328
## Togo Tonga Trinidad.and.Tobago Tunisia Turkiye
## 1 18,13083205 9,473220646 6,159480502
## 2 -5,911365932 12,40942895 -2,288321776 -3,621989057
## 3 14,82360458 8,442249298 18,1078968
## 4 12,69169029 15,14067833 19,54660848
## 5 -11538662,1 854482998,9 -258237032,7
## 6 7,759865756 19,71218223
## Turkmenistan Uganda Ukraine United.Arab.Emirates United.Kingdom
## 1 11,29165273 24,08957469 7,405367993 0,701206778 0,579699702
## 2 -7,722776306 -5,401186423 -1,965412177
## 3 20,39550972 8,626471519
## 4 15,64934868 8,247115822 10,84579034 8,275426475
## 5 -681178068,7 -30593137,7 57396841,3
## 6 3,064902991
## Upper.middle.income Uruguay Uzbekistan Vanuatu Viet.Nam
## 1 7,075550515 5,567799372 20,56955637 11,96048582
## 2 -3,338839349 -7,677644386 6,011631344
## 3 15,43375587 20,89686012
## 4 22,29184432 9,45742196 18,87523315 23,8827678
## 5 -3613414699 439691476,8 -6599229,3 -426368645,9
## 6 8,183682955 8,425058735 -2,132950803 7,278032563
## World Zambia Zimbabwe
## 1 4,103064414 2,230120343 4,108253654
## 2 -2,112975524 0,379995091
## 3 13,85877514
## 4 15,23655327 8,502958799 16,42947397
## 5 -54362933,3 33739732,9
## 6 -73,54044052
summary(data)
## Feature.and.Country Afghanistan Africa.Eastern.and.Southern
## Length:8 Length:8 Length:8
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
## Africa.Western.and.Central Albania Algeria
## Length:8 Length:8 Length:8
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
## Andorra Angola Antigua.and.Barbuda Arab.World
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Argentina Armenia Aruba Australia
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Austria Azerbaijan Bahamas..The Bahrain
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Bangladesh Barbados Belarus Belgium
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Belize Benin Bhutan Bolivia
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Bosnia.and.Herzegovina Botswana Brazil
## Length:8 Length:8 Length:8
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
## Brunei.Darussalam Bulgaria Burkina.Faso Burundi
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Cabo.Verde Cambodia Cameroon Canada
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Caribbean.small.states Central.African.Republic Central.Europe.and.the.Baltics
## Length:8 Length:8 Length:8
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
## Chad Channel.Islands Chile China
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Colombia Comoros Congo..Dem..Rep. Congo..Rep.
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Costa.Rica Cote.d.Ivoire Croatia Curacao
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Cyprus Czechia Denmark Djibouti
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Dominica Dominican.Republic Early.demographic.dividend
## Length:8 Length:8 Length:8
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
## East.Asia...Pacific East.Asia...Pacific..excluding.high.income.
## Length:8 Length:8
## Class :character Class :character
## Mode :character Mode :character
## East.Asia...Pacific..IDA...IBRD.countries. Ecuador
## Length:8 Length:8
## Class :character Class :character
## Mode :character Mode :character
## Egypt..Arab.Rep. El.Salvador Equatorial.Guinea Eritrea
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Estonia Eswatini Ethiopia Euro.area
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Europe...Central.Asia Europe...Central.Asia..excluding.high.income.
## Length:8 Length:8
## Class :character Class :character
## Mode :character Mode :character
## Europe...Central.Asia..IDA...IBRD.countries. European.Union
## Length:8 Length:8
## Class :character Class :character
## Mode :character Mode :character
## Faroe.Islands Fiji Finland France
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Gabon Gambia..The Georgia Germany
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Ghana Greece Grenada Guatemala
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Guinea Guinea.Bissau Guyana Haiti
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Heavily.indebted.poor.countries..HIPC. Honduras Hong.Kong.SAR..China
## Length:8 Length:8 Length:8
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
## Hungary IBRD.only Iceland IDA...IBRD.total
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## IDA.blend IDA.only IDA.total India
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Indonesia Iran..Islamic.Rep. Iraq Ireland
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Israel Italy Jamaica Japan
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Jordan Kazakhstan Kenya Korea..Rep.
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Kosovo Kuwait Kyrgyz.Republic Lao.PDR
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Late.demographic.dividend Latin.America...Caribbean
## Length:8 Length:8
## Class :character Class :character
## Mode :character Mode :character
## Latin.America...Caribbean..excluding.high.income.
## Length:8
## Class :character
## Mode :character
## Latin.America...the.Caribbean..IDA...IBRD.countries. Latvia
## Length:8 Length:8
## Class :character Class :character
## Mode :character Mode :character
## Least.developed.countries..UN.classification Lebanon
## Length:8 Length:8
## Class :character Class :character
## Mode :character Mode :character
## Lesotho Liberia Lithuania Low...middle.income
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Low.income Lower.middle.income Luxembourg Macao.SAR..China
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Madagascar Malawi Malaysia Maldives
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Mali Malta Marshall.Islands Mauritania
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Mauritius Mexico Micronesia..Fed..Sts.
## Length:8 Length:8 Length:8
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
## Middle.East...North.Africa Middle.East...North.Africa..excluding.high.income.
## Length:8 Length:8
## Class :character Class :character
## Mode :character Mode :character
## Middle.East...North.Africa..IDA...IBRD.countries. Middle.income
## Length:8 Length:8
## Class :character Class :character
## Mode :character Mode :character
## Moldova Mongolia Montenegro Morocco
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Mozambique Myanmar Namibia Nauru
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Nepal Netherlands Nicaragua Niger
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Nigeria North.Macedonia Norway Oman
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Other.small.states Pacific.island.small.states Pakistan
## Length:8 Length:8 Length:8
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
## Palau Panama Papua.New.Guinea Paraguay
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Peru Philippines Poland Portugal
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Pre.demographic.dividend Puerto.Rico Qatar
## Length:8 Length:8 Length:8
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
## Romania Russian.Federation Rwanda Samoa
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Sao.Tome.and.Principe Saudi.Arabia Senegal Serbia
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Seychelles Sierra.Leone Singapore Slovak.Republic
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Slovenia Small.states Solomon.Islands South.Africa
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## South.Asia South.Asia..IDA...IBRD. South.Sudan
## Length:8 Length:8 Length:8
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
## Spain Sri.Lanka St..Kitts.and.Nevis St..Lucia
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## St..Vincent.and.the.Grenadines Sub.Saharan.Africa
## Length:8 Length:8
## Class :character Class :character
## Mode :character Mode :character
## Sub.Saharan.Africa..excluding.high.income.
## Length:8
## Class :character
## Mode :character
## Sub.Saharan.Africa..IDA...IBRD.countries. Sudan
## Length:8 Length:8
## Class :character Class :character
## Mode :character Mode :character
## Suriname Sweden Switzerland Tajikistan
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Tanzania Thailand Timor.Leste Togo
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Tonga Trinidad.and.Tobago Tunisia Turkiye
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Turkmenistan Uganda Ukraine United.Arab.Emirates
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## United.Kingdom Upper.middle.income Uruguay Uzbekistan
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Vanuatu Viet.Nam World Zambia
## Length:8 Length:8 Length:8 Length:8
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## Zimbabwe
## Length:8
## Class :character
## Mode :character
str(data)
## 'data.frame': 8 obs. of 231 variables:
## $ Feature.and.Country : chr "Agriculture, forestry, and fishing, value added (% of GDP)" "Current account balance (% of GDP)" "Government expenditure on education, total (% of government expenditure)" "Manufacturing, value added (% of GDP)" ...
## $ Afghanistan : chr "" "" "" "7,606649959" ...
## $ Africa.Eastern.and.Southern : chr "14,23180157" "" "" "9,986026956" ...
## $ Africa.Western.and.Central : chr "21,2095996" "" "14,72915268" "13,80788051" ...
## $ Albania : chr "16,22256753" "-1,196321748" "" "6,877725851" ...
## $ Algeria : chr "13,08678415" "2,19023557" "13,26102352" "9,29539943" ...
## $ Andorra : chr "0,478492136" "" "12,76951504" "3,397436996" ...
## $ Angola : chr "14,90215242" "4,933699785" "7,73896265" "7,99574282" ...
## $ Antigua.and.Barbuda : chr "1,914441289" "-12,89162094" "9,803515434" "2,500305137" ...
## $ Arab.World : chr "4,925365568" "" "" "11,64900647" ...
## $ Argentina : chr "5,929853762" "-3,243512548" "" "16,31749874" ...
## $ Armenia : chr "8,481559899" "-2,309786441" "" "10,55772055" ...
## $ Aruba : chr "" "" "" "" ...
## $ Australia : chr "2,573502062" "0,254737257" "" "5,362504494" ...
## $ Austria : chr "1,296970303" "1,325563772" "" "15,87201148" ...
## $ Azerbaijan : chr "5,540890448" "11,51161989" "" "5,778440801" ...
## $ Bahamas..The : chr "0,448443003" "-7,494376622" "11,59396172" "1,007776267" ...
## $ Bahrain : chr "0,252106224" "5,858237577" "" "20,68962134" ...
## $ Bangladesh : chr "11,00369002" "1,0030677" "10,67466259" "22,34201887" ...
## $ Barbados : chr "1,854009024" "" "12,47315025" "5,595754047" ...
## $ Belarus : chr "7,250383271" "-1,543536999" "" "23,00917676" ...
## $ Belgium : chr "0,76908294" "-0,698394106" "" "11,2544326" ...
## $ Belize : chr "8,101146127" "-0,644082652" "18,53170967" "6,296362717" ...
## $ Benin : chr "25,40202588" "" "19,04263687" "10,06232409" ...
## $ Bhutan : chr "" "-33,12140918" "17,80044174" "" ...
## $ Bolivia : chr "13,46612931" "-2,604021679" "" "10,18579643" ...
## $ Bosnia.and.Herzegovina : chr "4,680492361" "-2,32154774" "" "13,32019294" ...
## $ Botswana : chr "1,581261324" "-0,601807749" "" "5,628737819" ...
## $ Brazil : chr "6,241384676" "-1,000382833" "" "13,33187799" ...
## $ Brunei.Darussalam : chr "1,194945472" "12,85044757" "" "10,35635051" ...
## $ Bulgaria : chr "2,517578651" "0,905860034" "" "" ...
## $ Burkina.Faso : chr "16,33445505" "" "20,29719734" "10,69070484" ...
## $ Burundi : chr "25,21939214" "-23,67748209" "15,72701359" "" ...
## $ Cabo.Verde : chr "4,644068287" "-2,583797778" "14,70472336" "4,702977862" ...
## $ Cambodia : chr "17,07844725" "1,30468362" "" "26,3329384" ...
## $ Cameroon : chr "17,29494102" "" "13,08295155" "13,48749139" ...
## $ Canada : chr "" "-0,729574021" "" "" ...
## $ Caribbean.small.states : chr "" "" "" "3,994339105" ...
## $ Central.African.Republic : chr "28,61105552" "" "9,993927956" "17,95123789" ...
## $ Central.Europe.and.the.Baltics : chr "2,885955998" "" "" "16,22482957" ...
## $ Chad : chr "25,12523115" "" "16,48435402" "" ...
## $ Channel.Islands : chr "0,598873831" "" "" "0,807306887" ...
## $ Chile : chr "3,520272875" "-3,546305608" "" "9,206118175" ...
## $ China : chr "7,12013561" "1,421693486" "" "26,18064358" ...
## $ Colombia : chr "8,723857807" "-2,511695976" "" "10,90439299" ...
## $ Comoros : chr "37,18527377" "-1,820598003" "" "" ...
## $ Congo..Dem..Rep. : chr "17,38929861" "-5,848935464" "" "17,95150179" ...
## $ Congo..Rep. : chr "8,952115876" "" "14,72915268" "" ...
## $ Costa.Rica : chr "3,800476573" "-1,43159866" "" "13,61878752" ...
## $ Cote.d.Ivoire : chr "14,3558741" "" "15,94641018" "14,36958539" ...
## $ Croatia : chr "3,357268619" "0,753574362" "" "12,11755565" ...
## $ Curacao : chr "0,268253398" "-19,95135896" "" "2,713872991" ...
## $ Cyprus : chr "1,179084651" "-11,4669307" "" "4,347455259" ...
## $ Czechia : chr "1,731167726" "0,301691698" "" "20,01707147" ...
## $ Denmark : chr "0,756712777" "9,84084616" "" "15,95901224" ...
## $ Djibouti : chr "1,76004579" "17,53211386" "" "" ...
## $ Dominica : chr "14,79629399" "-33,93606876" "6,412837029" "2,736467737" ...
## $ Dominican.Republic : chr "6,366892323" "-3,603545613" "22,02540588" "13,74503" ...
## $ Early.demographic.dividend : chr "10,64500157" "" "" "16,90814702" ...
## $ East.Asia...Pacific : chr "5,805241489" "" "" "22,75986858" ...
## $ East.Asia...Pacific..excluding.high.income. : chr "7,77661183" "" "" "25,24802708" ...
## $ East.Asia...Pacific..IDA...IBRD.countries. : chr "7,763511732" "" "" "25,25651215" ...
## $ Ecuador : chr "7,677376716" "1,875521904" "9,694939613" "12,4461144" ...
## $ Egypt..Arab.Rep. : chr "11,5659207" "-3,17277519" "" "14,89962455" ...
## $ El.Salvador : chr "4,605443029" "-1,369042798" "" "14,00330201" ...
## $ Equatorial.Guinea : chr "3,093410455" "" "" "24,64465903" ...
## $ Eritrea : chr "" "" "" "" ...
## $ Estonia : chr "1,926658365" "-1,750173546" "" "11,91405826" ...
## $ Eswatini : chr "7,052351219" "2,420379534" "" "28,77758971" ...
## $ Ethiopia : chr "35,78979912" "-2,924689133" "" "4,479422155" ...
## $ Euro.area : chr "1,544524326" "" "" "14,48257356" ...
## $ Europe...Central.Asia : chr "2,037237095" "" "" "13,83038263" ...
## $ Europe...Central.Asia..excluding.high.income. : chr "6,99571525" "" "" "16,91218171" ...
## $ Europe...Central.Asia..IDA...IBRD.countries. : chr "4,687124466" "" "" "14,7584802" ...
## $ European.Union : chr "1,651060355" "" "" "14,67023599" ...
## $ Faroe.Islands : chr "18,20150593" "" "" "7,605413015" ...
## $ Fiji : chr "11,73291019" "" "14,62911034" "9,361786386" ...
## $ Finland : chr "2,313405532" "-0,424831499" "" "14,934509" ...
## $ France : chr "1,740502752" "-0,993970971" "" "9,731756181" ...
## $ Gabon : chr "6,525969125" "" "13,56582355" "20,19276648" ...
## $ Gambia..The : chr "23,22462833" "-8,519289807" "17,5029583" "1,50785255" ...
## $ Georgia : chr "6,015795111" "-5,551014744" "" "8,355354957" ...
## $ Germany : chr "0,841992092" "5,936535577" "" "18,53620193" ...
## $ Ghana : chr "21,10265098" "1,842485685" "12,03531742" "11,22617432" ...
## $ Greece : chr "3,343435145" "-6,163304182" "" "8,730572129" ...
## $ Grenada : chr "3,277471183" "-13,99197779" "" "3,573939997" ...
## $ Guatemala : chr "9,770097792" "3,09422459" "" "13,98979828" ...
## $ Guinea : chr "29,09129871" "10,30631006" "10,02691841" "" ...
## $ Guinea.Bissau : chr "30,73927174" "" "" "11,89762939" ...
## $ Guyana : chr "" "" "" "" ...
## $ Haiti : chr "18,15397552" "-3,43849434" "11,23081112" "24,47841491" ...
## $ Heavily.indebted.poor.countries..HIPC. : chr "20,88841697" "" "14,77087021" "10,25230433" ...
## $ Honduras : chr "11,9797587" "-3,875651525" "" "15,32338299" ...
## $ Hong.Kong.SAR..China : chr "0,037899102" "9,164949053" "" "0,944459034" ...
## $ Hungary : chr "4,690144135" "0,787522464" "" "17,1398233" ...
## $ IBRD.only : chr "7,822987253" "" "" "20,65791613" ...
## $ Iceland : chr "3,817860645" "1,229042395" "" "9,550727468" ...
## $ IDA...IBRD.total : chr "8,612164688" "" "" "20,19869045" ...
## $ IDA.blend : chr "21,02768288" "" "" "13,77135838" ...
## [list output truncated]
# Rename first column for clarity
colnames(data)[1] <- "Feature"
# Convert dataset from wide to long format
data_long <- pivot_longer(data, cols = -Feature, names_to = "Country", values_to = "Value")
# Replace commas with dots and convert to numeric
data_long$Value <- as.numeric(gsub(",", ".", data_long$Value))
# Check for NAs
sum(is.na(data_long$Value))
## [1] 689
# Transform back to wide format
data_clean <- pivot_wider(data_long, names_from = Feature, values_from = Value)
# Remove columns with more than 40% missing values
data_clean <- data_clean %>% select_if(~ mean(!is.na(.)) > 0.60)
# Impute missing values with column mean
data_clean <- data_clean %>% mutate(across(where(is.numeric), ~ replace(., is.na(.), mean(., na.rm = TRUE))))
# Scale numeric data
data_scaled <- scale(data_clean[, -1])
set.seed(123)
wss <- sapply(1:10, function(k) {kmeans(data_scaled, centers = k, nstart = 10)$tot.withinss})
plot(1:10, wss, type = "b", pch = 19, frame = FALSE, xlab = "Number of clusters K", ylab = "Total within-cluster sum of squares", main = "Elbow Method")
set.seed(123)
k <- 4 # Choose optimal K based on elbow plot
km_res <- kmeans(data_scaled, centers = k, nstart = 25)
fviz_cluster(km_res, data = data_scaled, geom = "point", ellipse.type = "convex", main = "K-Means Clustering (k=4)")
# Silhouette Score
silhouette_score <- silhouette(km_res$cluster, dist(data_scaled))
fviz_silhouette(silhouette_score)
## cluster size ave.sil.width
## 1 1 20 0.15
## 2 2 55 0.27
## 3 3 55 0.21
## 4 4 100 0.26
summary(silhouette_score)
## Silhouette of 230 units in 4 clusters from silhouette.default(x = km_res$cluster, dist = dist(data_scaled)) :
## Cluster sizes and average silhouette widths:
## 20 55 55 100
## 0.1497749 0.2690363 0.2111001 0.2568430
## Individual silhouette widths:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.1112 0.1324 0.2518 0.2395 0.3383 0.4882
set.seed(123)
k2 <- 3
km_res2 <- kmeans(data_scaled, centers = k2, nstart = 25)
# Visualize clusters
fviz_cluster(km_res2, data = data_scaled, geom = "point", ellipse.type = "convex", main = "K-Means Clustering (k=3)")
data_clean$Cluster <- as.factor(km_res$cluster)
sil_score_km2 <- silhouette(km_res2$cluster, dist(data_scaled))
summary(sil_score_km2)
## Silhouette of 230 units in 3 clusters from silhouette.default(x = km_res2$cluster, dist = dist(data_scaled)) :
## Cluster sizes and average silhouette widths:
## 64 56 110
## 0.1340302 0.2255680 0.2966941
## Individual silhouette widths:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.1003 0.1278 0.2409 0.2341 0.3478 0.4843
clara_res <- clara(data_scaled, k = 3, metric = "euclidean")
fviz_cluster(clara_res, geom = "point", ellipse.type = "convex", main = "CLARA Clustering")
sil_score_clara <- silhouette(clara_res$cluster, dist(data_scaled))
summary(sil_score_clara)
## Silhouette of 230 units in 3 clusters from silhouette.default(x = clara_res$cluster, dist = dist(data_scaled)) :
## Cluster sizes and average silhouette widths:
## 104 81 45
## 0.05526254 0.29830313 0.29470428
## Individual silhouette widths:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.29567 0.04092 0.20491 0.18770 0.33026 0.49768
manhattan_dist <- daisy(data_scaled, metric = "manhattan")
pam_res <- pam(manhattan_dist, k = 3)
pam_res$data <- data_scaled
fviz_cluster(pam_res, geom = "point", ellipse.type = "convex", main = "PAM Clustering")
sil_score_pam <- silhouette(pam_res$cluster, dist(data_scaled))
summary(sil_score_pam)
## Silhouette of 230 units in 3 clusters from silhouette.default(x = pam_res$cluster, dist = dist(data_scaled)) :
## Cluster sizes and average silhouette widths:
## 103 55 72
## 0.1123322 0.2144665 0.1514790
## Individual silhouette widths:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.22876 0.06549 0.14851 0.14901 0.24855 0.38222
data_clean$Cluster <- as.factor(km_res$cluster)
numeric_data <- data_clean %>% select(-Country)
cluster_summary <- aggregate(. ~ Cluster, data = numeric_data, FUN = mean, na.rm = TRUE)
print(cluster_summary)
## Cluster Agriculture, forestry, and fishing, value added (% of GDP)
## 1 1 6.845016
## 2 2 6.534229
## 3 3 21.944769
## 4 4 5.733099
## Current account balance (% of GDP) Manufacturing, value added (% of GDP)
## 1 8.1006121 9.400342
## 2 0.7360242 20.519575
## 3 -4.4077960 11.326838
## 4 -1.4667624 9.682459
## Women Business and the Law Index Score (scale 1-100)
## 1 53.27421
## 2 78.54100
## 3 72.75181
## 4 86.28832
data_clean$Cluster <- factor(data_clean$Cluster, levels = c(1, 2, 3), labels = c("Agriculture-based", "Intermediate_economies", "Industrialized_economies"))
Industrial <- data_clean %>% filter(Cluster == "Industrialized_economies")
print(Industrial)
## # A tibble: 55 × 6
## Country Agriculture, forestr…¹ Current account bala…² Manufacturing, value…³
## <chr> <dbl> <dbl> <dbl>
## 1 Africa.… 14.2 -0.811 9.99
## 2 Africa.… 21.2 -0.811 13.8
## 3 Benin 25.4 -0.811 10.1
## 4 Bhutan 9.90 -33.1 12.6
## 5 Burkina… 16.3 -0.811 10.7
## 6 Burundi 25.2 -23.7 12.6
## 7 Cameroon 17.3 -0.811 13.5
## 8 Central… 28.6 -0.811 18.0
## 9 Chad 25.1 -0.811 12.6
## 10 Comoros 37.2 -1.82 12.6
## # ℹ 45 more rows
## # ℹ abbreviated names:
## # ¹​`Agriculture, forestry, and fishing, value added (% of GDP)`,
## # ²​`Current account balance (% of GDP)`,
## # ³​`Manufacturing, value added (% of GDP)`
## # ℹ 2 more variables:
## # `Women Business and the Law Index Score (scale 1-100)` <dbl>, …
# Scatter plot
ggplot(Industrial, aes(x = `Agriculture, forestry, and fishing, value added (% of GDP)`, y = `Manufacturing, value added (% of GDP)`, label = Country)) +
geom_point(aes(color = `Women Business and the Law Index Score (scale 1-100)`), size = 3) +
geom_text(vjust = 1.5, hjust = 0.5, size = 3, check_overlap = TRUE) +
labs(title = "Agriculture vs Manufacturing Value Added (%) in Industrialized Countries", x = "Agriculture Value Added (% of GDP)", y = "Manufacturing Value Added (% of GDP)") +
theme_minimal() +
scale_color_gradient(low = "red", high = "blue", name = "Women Business & Law Index")
# Bar plot for Women Business and Law Index
ggplot(Industrial, aes(x = reorder(Country, `Women Business and the Law Index Score (scale 1-100)`), y = `Women Business and the Law Index Score (scale 1-100)`)) +
geom_bar(stat = "identity", fill = "steelblue") +
coord_flip() +
labs(title = "Women Business and Law Index in Industrialized Countries", x = "Country", y = "Women Business and Law Index Score") +
theme_minimal()
# Bar plot for Current Account Balance
ggplot(Industrial, aes(x = reorder(Country, `Current account balance (% of GDP)`), y = `Current account balance (% of GDP)`)) +
geom_bar(stat = "identity", fill = "darkgreen") +
coord_flip() +
labs(title = "Current Account Balance in Industrialized Countries", x = "Country", y = "Current Account Balance (% of GDP)") +
theme_minimal()
Results & Insight
-Based on the three graphs, , Ireland appears to be the best country to live in. It ranks highest in the Women Business & Law Index, indicating strong gender equality and legal rights for women. Additionally, it has a positive current account balance, reflecting a stable and strong economy, and it also has a well-developed manufacturing sector.
-Singapore, is another great choice, as it also has a high Women Business & Law Index, a strong economy, and a positive current account balance, making it an economically and socially progressive nation.
-South Korea and Vietnam, also stand out due to their strong manufacturing sectors and high gender equality ratings, making them attractive options for economic and social opportunities.
-Afghanistan, Iran, and Sudan, rank among the least suitable countries to live in. These countries have very low Women Business & Law Index scores, indicating poor gender equality and limited legal rights for women. Additionally,Afghanistan and Iran have negative current account balances, suggesting economic instability.
-Tonga and Honduras, also rank poorly due to their negative current account balances, which indicate weak economic conditions.
-Overall, if one prioritizes economic stability, gender equality, and industrial growth, Ireland, Singapore, and South Korea emerge as the best choices.