Introduction

This report presents Exploratory Data Analysis and K-Means Clustering using World Bank data.

Summary of Income Groups:

summary(s1)
##   Country Code              Country Name GDP per capita   Life expectancy
##  ABW    : 1    Andorra            : 1    Min.   : 12752   Min.   :62.11  
##  AND    : 1    Antigua and Barbuda: 1    1st Qu.: 25584   1st Qu.:78.11  
##  ARE    : 1    Aruba              : 1    Median : 38232   Median :81.41  
##  ATG    : 1    Australia          : 1    Mean   : 51700   Mean   :80.29  
##  AUS    : 1    Austria            : 1    3rd Qu.: 59880   3rd Qu.:83.07  
##  AUT    : 1    Bahamas, The       : 1    Max.   :256800   Max.   :86.37  
##  (Other):74    (Other)            :74    NA's   :7                       
##    Population        Urban population                        Region  
##  Min.   :    11875   Min.   : 14.68   East Asia & Pacific       :13  
##  1st Qu.:   116670   1st Qu.: 66.47   Europe & Central Asia     :38  
##  Median :  2763808   Median : 82.80   Latin America & Caribbean :17  
##  Mean   : 15356838   Mean   : 77.98   Middle East & North Africa: 8  
##  3rd Qu.: 10426451   3rd Qu.: 94.16   North America             : 3  
##  Max.   :336806231   Max.   :100.00   South Asia                : 0  
##                                       Sub-Saharan Africa        : 1  
##               Income group
##  High income        :80   
##  Low income         : 0   
##  Lower middle income: 0   
##  Upper middle income: 0   
##                           
##                           
## 
summary(s2)
##   Country Code                   Country Name GDP per capita   Life expectancy
##  AFG    : 1    Afghanistan             : 1    Min.   : 250.6   Min.   :55.07  
##  BDI    : 1    Burkina Faso            : 1    1st Qu.: 627.6   1st Qu.:61.16  
##  BFA    : 1    Burundi                 : 1    Median : 799.2   Median :63.64  
##  CAF    : 1    Central African Republic: 1    Mean   : 823.4   Mean   :64.10  
##  COD    : 1    Chad                    : 1    3rd Qu.:1014.7   3rd Qu.:67.32  
##  ERI    : 1    Congo, Dem. Rep.        : 1    Max.   :1555.5   Max.   :73.64  
##  (Other):22    (Other)                 :22    NA's   :5                       
##    Population        Urban population                        Region  
##  Min.   :  2153339   Min.   :16.97    East Asia & Pacific       : 1  
##  1st Qu.: 10938615   1st Qu.:27.42    Europe & Central Asia     : 0  
##  Median : 20914224   Median :35.26    Latin America & Caribbean : 0  
##  Mean   : 27556994   Mean   :37.83    Middle East & North Africa: 2  
##  3rd Qu.: 31805739   3rd Qu.:44.86    North America             : 0  
##  Max.   :128691692   Max.   :72.17    South Asia                : 1  
##                                       Sub-Saharan Africa        :24  
##               Income group
##  High income        : 0   
##  Low income         :28   
##  Lower middle income: 0   
##  Upper middle income: 0   
##                           
##                           
## 
summary(s3)
##   Country Code     Country Name GDP per capita   Life expectancy
##  AGO    : 1    Algeria   : 1    Min.   : 916.3   Min.   :54.46  
##  BEN    : 1    Angola    : 1    1st Qu.:1973.7   1st Qu.:66.02  
##  BGD    : 1    Bangladesh: 1    Median :2744.2   Median :69.78  
##  BOL    : 1    Benin     : 1    Mean   :2964.6   Mean   :69.29  
##  BTN    : 1    Bhutan    : 1    3rd Qu.:3811.3   3rd Qu.:72.35  
##  CIV    : 1    Bolivia   : 1    Max.   :5838.6   Max.   :77.82  
##  (Other):48    (Other)   :48                                    
##    Population        Urban population                        Region  
##  Min.   :1.126e+05   Min.   :15.06    East Asia & Pacific       :14  
##  1st Qu.:3.866e+06   1st Qu.:34.80    Europe & Central Asia     : 4  
##  Median :1.222e+07   Median :53.93    Latin America & Caribbean : 5  
##  Mean   :6.479e+07   Mean   :50.37    Middle East & North Africa: 8  
##  3rd Qu.:3.773e+07   3rd Qu.:65.82    North America             : 0  
##  Max.   :1.438e+09   Max.   :90.45    South Asia                : 6  
##                                       Sub-Saharan Africa        :17  
##               Income group
##  High income        : 0   
##  Low income         : 0   
##  Lower middle income:54   
##  Upper middle income: 0   
##                           
##                           
## 
summary(s4)
##   Country Code         Country Name GDP per capita  Life expectancy
##  ALB    : 1    Albania       : 1    Min.   : 4188   Min.   :63.71  
##  ARG    : 1    American Samoa: 1    1st Qu.: 6595   1st Qu.:71.21  
##  ARM    : 1    Argentina     : 1    Median : 8028   Median :74.01  
##  ASM    : 1    Armenia       : 1    Mean   : 9413   Mean   :73.75  
##  AZE    : 1    Azerbaijan    : 1    3rd Qu.:12265   3rd Qu.:77.33  
##  BGR    : 1    Belarus       : 1    Max.   :20474   Max.   :81.04  
##  (Other):48    (Other)       :48    NA's   :2                      
##    Population        Urban population                        Region  
##  Min.   :9.816e+03   Min.   :21.15    East Asia & Pacific       : 9  
##  1st Qu.:8.508e+05   1st Qu.:56.26    Europe & Central Asia     :16  
##  Median :3.450e+06   Median :65.50    Latin America & Caribbean :19  
##  Mean   :4.655e+07   Mean   :64.44    Middle East & North Africa: 3  
##  3rd Qu.:1.809e+07   3rd Qu.:77.99    North America             : 0  
##  Max.   :1.411e+09   Max.   :92.68    South Asia                : 1  
##                                       Sub-Saharan Africa        : 6  
##               Income group
##  High income        : 0   
##  Low income         : 0   
##  Lower middle income: 0   
##  Upper middle income:54   
##                           
##                           
## 
##Histogram of GDP per Capita by Income Group
histogram(~`GDP per capita` | `Income group`, data = final_data, breaks = 60, main="Histogram of GDP per Capita by Income Group")

##Histogram of Population by Income Group
histogram(~Population | `Income group`,
           data = final_data,
           breaks = 60, main="Histogram of Population by Income Group")

##Histogram of Urban Population by Income Group
 histogram(~`Urban population` | `Income group`,
           data = final_data,
           breaks = 60, main = "Histogram of Urban Population by Income Group")

 boxplot(Population ~ Region, data = final_data, main = "Boxplot of Population by Region")

 boxplot(`GDP per capita` ~ Region, data = final_data, main = "Boxplot of GDP per capita by Region")

 xyplot(`GDP per capita`~`Life expectancy`,
        data = final_data,
        groups=Region,
        auto.key = TRUE,
        main = "GDP per Capita vs Life Expectancy")

mosaicplot(table(final_data$Region, final_data$`Income group`),
            main = "Region vs Income Group",
            xlab = "Region",
            ylab = "Income Group",
            color = TRUE)

 plot(density(final_data$Population),
      main = "Density Plot of Population",
      xlab = "Population",
      col = "blue",
      lwd = 2)

 numeric_data <- final_data[, sapply(final_data, is.numeric)]
 numeric_data <- na.omit(numeric_data)
df <- scale(numeric_data)
k1 <- kmeans(df, centers = 5, iter.max = 10, nstart = 1)
k1
## K-means clustering with 5 clusters of sizes 42, 46, 39, 73, 2
## 
## Cluster means:
##   GDP per capita Life expectancy  Population Urban population
## 1      1.4710350       1.2052312 -0.09705528        0.9828387
## 2     -0.5157673      -0.6084399 -0.05960753       -1.3178322
## 3     -0.5711102      -1.2922100 -0.06358461       -0.1741253
## 4     -0.2044860       0.3755374 -0.13057417        0.3719036
## 5     -0.4286952       0.1752424  9.41499104       -0.5085108
## 
## Clustering vector:
##   1   2   3   4   5   6   7   8  10  11  12  13  14  15  16  17  18  19  20  21 
##   4   2   3   4   1   1   4   4   2   1   1   4   2   1   3   2   2   4   1   4 
##  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41 
##   4   4   2   1   3   4   4   4   2   3   3   1   1   1   4   5   3   3   3   3 
##  42  43  44  45  47  48  49  50  51  52  53  54  55  56  57  58  60  61  62  63 
##   4   2   4   4   4   1   4   4   1   3   4   1   4   4   4   2   1   4   2   1 
##  64  65  66  67  68  69  70  71  73  74  75  76  77  78  79  80  82  83  84  85 
##   3   1   1   2   4   1   4   3   3   3   3   3   4   2   1   4   2   1   4   4 
##  86  87  88  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 
##   3   4   3   5   1   4   4   1   1   1   4   4   1   4   2   2   2   3   2   1 
## 107 108 109 110 111 112 113 114 115 116 117 118 119 121 122 123 124 125 126 127 
##   1   2   4   3   4   2   1   2   3   4   1   4   1   4   1   2   2   4   4   3 
## 128 129 130 131 132 133 135 136 137 138 139 140 141 142 143 144 145 146 147 148 
##   4   2   1   2   4   4   2   3   2   2   4   3   4   2   3   4   1   1   3   3 
## 149 150 151 152 153 154 155 156 157 158 160 161 162 163 164 165 166 167 168 169 
##   1   4   2   4   4   3   4   2   4   1   4   4   3   4   1   4   4   2   4   2 
## 170 171 172 173 174 175 176 177 179 180 181 182 183 184 185 186 188 189 190 191 
##   3   1   2   3   4   1   3   4   3   4   4   4   1   2   1   2   4   3   3   4 
## 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 210 211 212 213 215 
##   2   2   2   2   4   4   4   3   2   2   4   4   1   2   2   2   2   2   4   3 
## 216 217 
##   3   3 
## 
## Within cluster sum of squares by cluster:
## [1] 110.562438  29.325156  32.896680  45.648439   1.287738
##  (between_SS / total_SS =  72.7 %)
## 
## Available components:
## 
## [1] "cluster"      "centers"      "totss"        "withinss"     "tot.withinss"
## [6] "betweenss"    "size"         "iter"         "ifault"
k1$center
##   GDP per capita Life expectancy  Population Urban population
## 1      1.4710350       1.2052312 -0.09705528        0.9828387
## 2     -0.5157673      -0.6084399 -0.05960753       -1.3178322
## 3     -0.5711102      -1.2922100 -0.06358461       -0.1741253
## 4     -0.2044860       0.3755374 -0.13057417        0.3719036
## 5     -0.4286952       0.1752424  9.41499104       -0.5085108
k1$cluster
##   1   2   3   4   5   6   7   8  10  11  12  13  14  15  16  17  18  19  20  21 
##   4   2   3   4   1   1   4   4   2   1   1   4   2   1   3   2   2   4   1   4 
##  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41 
##   4   4   2   1   3   4   4   4   2   3   3   1   1   1   4   5   3   3   3   3 
##  42  43  44  45  47  48  49  50  51  52  53  54  55  56  57  58  60  61  62  63 
##   4   2   4   4   4   1   4   4   1   3   4   1   4   4   4   2   1   4   2   1 
##  64  65  66  67  68  69  70  71  73  74  75  76  77  78  79  80  82  83  84  85 
##   3   1   1   2   4   1   4   3   3   3   3   3   4   2   1   4   2   1   4   4 
##  86  87  88  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 
##   3   4   3   5   1   4   4   1   1   1   4   4   1   4   2   2   2   3   2   1 
## 107 108 109 110 111 112 113 114 115 116 117 118 119 121 122 123 124 125 126 127 
##   1   2   4   3   4   2   1   2   3   4   1   4   1   4   1   2   2   4   4   3 
## 128 129 130 131 132 133 135 136 137 138 139 140 141 142 143 144 145 146 147 148 
##   4   2   1   2   4   4   2   3   2   2   4   3   4   2   3   4   1   1   3   3 
## 149 150 151 152 153 154 155 156 157 158 160 161 162 163 164 165 166 167 168 169 
##   1   4   2   4   4   3   4   2   4   1   4   4   3   4   1   4   4   2   4   2 
## 170 171 172 173 174 175 176 177 179 180 181 182 183 184 185 186 188 189 190 191 
##   3   1   2   3   4   1   3   4   3   4   4   4   1   2   1   2   4   3   3   4 
## 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 210 211 212 213 215 
##   2   2   2   2   4   4   4   3   2   2   4   4   1   2   2   2   2   2   4   3 
## 216 217 
##   3   3
 library(cluster)
clusplot(df,k1$cluster,color = TRUE,shade = TRUE,lables=TRUE,main="K-Means Cluster Plot")