EJERCICIO 1:

library(rio)
data1 = import("~/PUCP/PUCP FACU/6TO CICLO/ESTADÍSTICA/GPIFINAL_data.xlsx")
data1
##                              Country 2022_safesec 2022_milit 2022_oncon
## 1                        Afghanistan        4.127      2.472      3.650
## 2                            Albania        2.120      1.666      1.403
## 3                            Algeria        2.302      2.041      2.068
## 4                             Angola        2.413      1.706      1.666
## 5                          Argentina        2.656      1.611      1.201
## 6                            Armenia        1.977      2.041      1.990
## 7                          Australia        1.657      1.848      1.266
## 8                            Austria        1.452      1.331      1.097
## 9                         Azerbaijan        2.528      2.108      2.579
## 10                           Bahrain        2.405      1.717      1.955
## 11                        Bangladesh        2.438      1.534      2.004
## 12                           Belarus        2.526      1.896      2.208
## 13                           Belgium        1.806      1.602      1.141
## 14                             Benin        2.574      2.022      1.666
## 15                            Bhutan        1.601      1.336      1.436
## 16                           Bolivia        2.503      1.934      1.403
## 17            Bosnia and Herzegovina        2.044      1.526      1.835
## 18                          Botswana        2.441      1.812      1.000
## 19                            Brazil        3.284      1.965      1.853
## 20                          Bulgaria        1.929      1.633      1.000
## 21                      Burkina Faso        2.993      2.189      3.023
## 22                           Burundi        3.024      1.556      2.443
## 23                          Cambodia        2.080      1.933      1.638
## 24                          Cameroon        3.014      1.877      2.967
## 25                            Canada        1.637      1.465      1.030
## 26          Central African Republic        3.579      2.273      2.874
## 27                              Chad        2.903      2.189      2.552
## 28                             Chile        2.361      1.585      1.403
## 29                             China        2.107      2.022      1.858
## 30                          Colombia        3.596      2.052      2.099
## 31                        Costa Rica        2.229      1.614      1.201
## 32                    Cote d' Ivoire        2.764      1.724      1.694
## 33                           Croatia        1.564      1.565      1.201
## 34                              Cuba        2.614      1.533      1.805
## 35                            Cyprus        2.251      1.605      1.604
## 36                    Czech Republic        1.566      1.263      1.034
## 37  Democratic Republic of the Congo        3.747      1.881      3.413
## 38                           Denmark        1.295      1.368      1.242
## 39                          Djibouti        2.561      2.140      1.856
## 40                Dominican Republic        2.614      1.720      1.403
## 41                           Ecuador        2.509      1.866      1.426
## 42                             Egypt        2.503      2.014      2.426
## 43                       El Salvador        3.062      1.879      1.436
## 44                 Equatorial Guinea        2.200      1.638      1.604
## 45                           Eritrea        3.359      1.914      1.705
## 46                           Estonia        1.703      1.607      1.638
## 47                          Eswatini        2.576      1.706      1.604
## 48                          Ethiopia        2.917      1.809      3.457
## 49                           Finland        1.349      1.598      1.436
## 50                            France        1.867      2.773      1.305
## 51                             Gabon        2.378      1.807      1.604
## 52                           Georgia        2.413      1.790      1.805
## 53                           Germany        1.619      1.750      1.062
## 54                             Ghana        2.026      1.726      1.472
## 55                            Greece        1.773      2.036      1.805
## 56                         Guatemala        2.819      1.698      1.626
## 57                            Guinea        2.587      2.069      2.262
## 58                     Guinea-Bissau        2.586      2.218      1.615
## 59                            Guyana        2.895      1.551      1.604
## 60                             Haiti        2.735      1.740      2.077
## 61                          Honduras        3.064      1.812      1.604
## 62                           Hungary        1.528      1.184      1.421
## 63                           Iceland        1.237      1.020      1.000
## 64                             India        2.373      2.461      2.982
## 65                         Indonesia        2.107      1.496      1.644
## 66                              Iran        2.838      2.123      2.923
## 67                              Iraq        3.646      2.298      3.207
## 68                           Ireland        1.525      1.259      1.015
## 69                            Israel        2.237      3.813      2.167
## 70                             Italy        1.927      2.013      1.034
## 71                           Jamaica        2.791      1.721      1.201
## 72                             Japan        1.283      1.308      1.403
## 73                            Jordan        2.037      1.964      1.542
## 74                        Kazakhstan        2.492      1.781      1.805
## 75                             Kenya        2.599      1.794      2.345
## 76                            Kosovo        2.266      1.575      1.805
## 77                            Kuwait        1.762      2.184      1.431
## 78                   Kyrgyz Republic        2.282      1.671      2.006
## 79                              Laos        2.076      1.949      1.403
## 80                            Latvia        1.798      1.479      1.634
## 81                           Lebanon        2.748      2.317      2.701
## 82                           Lesotho        2.528      1.748      1.805
## 83                           Liberia        2.491      1.804      1.462
## 84                             Libya        3.093      2.433      3.160
## 85                         Lithuania        1.775      1.735      1.638
## 86                        Madagascar        2.612      1.444      1.630
## 87                            Malawi        2.144      1.723      1.739
## 88                          Malaysia        1.973      1.205      1.015
## 89                              Mali        3.589      1.873      2.861
## 90                        Mauritania        2.782      1.969      1.638
## 91                         Mauritius        2.132      1.373      1.000
## 92                            Mexico        3.158      1.736      2.642
## 93                           Moldova        2.142      1.243      2.006
## 94                          Mongolia        2.459      1.348      1.201
## 95                        Montenegro        2.243      1.602      1.403
## 96                           Morocco        2.158      1.752      1.891
## 97                        Mozambique        2.803      1.677      2.215
## 98                           Myanmar        3.116      1.744      2.700
## 99                           Namibia        2.569      1.755      1.201
## 100                            Nepal        2.493      1.706      1.436
## 101                      Netherlands        1.525      2.206      1.045
## 102                      New Zealand        1.530      1.168      1.008
## 103                        Nicaragua        2.966      1.723      2.006
## 104                            Niger        2.957      1.957      2.839
## 105                          Nigeria        3.107      2.059      2.806
## 106                      North Korea        3.113      3.120      2.610
## 107                  North Macedonia        1.928      1.771      1.403
## 108                           Norway        1.266      2.184      1.235
## 109                             Oman        1.892      2.651      1.403
## 110                         Pakistan        2.653      2.581      3.172
## 111                        Palestine        2.950      1.991      2.612
## 112                           Panama        2.524      1.547      1.403
## 113                 Papua New Guinea        2.802      1.697      1.605
## 114                         Paraguay        2.534      2.004      1.403
## 115                             Peru        2.625      1.938      1.420
## 116                      Philippines        2.855      1.700      2.410
## 117                           Poland        1.933      1.527      1.403
## 118                         Portugal        1.390      1.312      1.007
## 119                            Qatar        1.495      2.196      1.246
## 120            Republic of the Congo        2.903      2.194      1.620
## 121                          Romania        1.837      1.773      1.007
## 122                           Russia        2.912      3.234      2.844
## 123                           Rwanda        2.374      1.512      1.858
## 124                     Saudi Arabia        2.254      2.614      2.425
## 125                          Senegal        2.337      1.701      1.418
## 126                           Serbia        1.976      1.796      1.604
## 127                     Sierra Leone        2.313      1.605      1.413
## 128                        Singapore        1.238      1.943      1.000
## 129                         Slovakia        1.835      1.274      1.403
## 130                         Slovenia        1.407      1.129      1.403
## 131                          Somalia        3.624      2.155      3.474
## 132                     South Africa        3.234      1.758      1.613
## 133                      South Korea        1.591      2.370      1.805
## 134                      South Sudan        3.957      2.594      3.267
## 135                            Spain        1.808      1.898      1.218
## 136                        Sri Lanka        2.377      2.047      1.855
## 137                            Sudan        3.303      2.312      3.040
## 138                           Sweden        1.475      1.802      1.221
## 139                      Switzerland        1.236      1.929      1.005
## 140                            Syria        3.741      2.287      3.828
## 141                           Taiwan        1.731      1.704      1.604
## 142                       Tajikistan        2.428      1.707      2.057
## 143                         Tanzania        2.353      1.687      1.479
## 144                         Thailand        2.863      1.562      1.916
## 145                       The Gambia        2.373      1.830      1.409
## 146                      Timor-Leste        2.369      1.667      1.403
## 147                             Togo        2.615      2.020      1.818
## 148              Trinidad and Tobago        2.736      2.098      1.201
## 149                          Tunisia        2.508      1.769      1.820
## 150                           Turkey        3.217      2.058      3.159
## 151                     Turkmenistan        2.501      2.383      1.604
## 152                           Uganda        2.762      1.760      1.765
## 153                          Ukraine        3.230      2.044      2.765
## 154             United Arab Emirates        1.712      2.652      1.464
## 155                   United Kingdom        1.729      2.489      1.042
## 156         United States of America        2.225      3.172      1.770
## 157                          Uruguay        2.323      1.582      1.000
## 158                       Uzbekistan        2.215      2.213      1.805
## 159                        Venezuela        4.007      2.002      2.103
## 160                          Vietnam        2.289      1.876      1.403
## 161                            Yemen        3.771      2.272      3.559
## 162                           Zambia        2.511      1.519      1.604
## 163                         Zimbabwe        2.990      2.044      2.112
data1 = data1[complete.cases(data1),]
data1
##                              Country 2022_safesec 2022_milit 2022_oncon
## 1                        Afghanistan        4.127      2.472      3.650
## 2                            Albania        2.120      1.666      1.403
## 3                            Algeria        2.302      2.041      2.068
## 4                             Angola        2.413      1.706      1.666
## 5                          Argentina        2.656      1.611      1.201
## 6                            Armenia        1.977      2.041      1.990
## 7                          Australia        1.657      1.848      1.266
## 8                            Austria        1.452      1.331      1.097
## 9                         Azerbaijan        2.528      2.108      2.579
## 10                           Bahrain        2.405      1.717      1.955
## 11                        Bangladesh        2.438      1.534      2.004
## 12                           Belarus        2.526      1.896      2.208
## 13                           Belgium        1.806      1.602      1.141
## 14                             Benin        2.574      2.022      1.666
## 15                            Bhutan        1.601      1.336      1.436
## 16                           Bolivia        2.503      1.934      1.403
## 17            Bosnia and Herzegovina        2.044      1.526      1.835
## 18                          Botswana        2.441      1.812      1.000
## 19                            Brazil        3.284      1.965      1.853
## 20                          Bulgaria        1.929      1.633      1.000
## 21                      Burkina Faso        2.993      2.189      3.023
## 22                           Burundi        3.024      1.556      2.443
## 23                          Cambodia        2.080      1.933      1.638
## 24                          Cameroon        3.014      1.877      2.967
## 25                            Canada        1.637      1.465      1.030
## 26          Central African Republic        3.579      2.273      2.874
## 27                              Chad        2.903      2.189      2.552
## 28                             Chile        2.361      1.585      1.403
## 29                             China        2.107      2.022      1.858
## 30                          Colombia        3.596      2.052      2.099
## 31                        Costa Rica        2.229      1.614      1.201
## 32                    Cote d' Ivoire        2.764      1.724      1.694
## 33                           Croatia        1.564      1.565      1.201
## 34                              Cuba        2.614      1.533      1.805
## 35                            Cyprus        2.251      1.605      1.604
## 36                    Czech Republic        1.566      1.263      1.034
## 37  Democratic Republic of the Congo        3.747      1.881      3.413
## 38                           Denmark        1.295      1.368      1.242
## 39                          Djibouti        2.561      2.140      1.856
## 40                Dominican Republic        2.614      1.720      1.403
## 41                           Ecuador        2.509      1.866      1.426
## 42                             Egypt        2.503      2.014      2.426
## 43                       El Salvador        3.062      1.879      1.436
## 44                 Equatorial Guinea        2.200      1.638      1.604
## 45                           Eritrea        3.359      1.914      1.705
## 46                           Estonia        1.703      1.607      1.638
## 47                          Eswatini        2.576      1.706      1.604
## 48                          Ethiopia        2.917      1.809      3.457
## 49                           Finland        1.349      1.598      1.436
## 50                            France        1.867      2.773      1.305
## 51                             Gabon        2.378      1.807      1.604
## 52                           Georgia        2.413      1.790      1.805
## 53                           Germany        1.619      1.750      1.062
## 54                             Ghana        2.026      1.726      1.472
## 55                            Greece        1.773      2.036      1.805
## 56                         Guatemala        2.819      1.698      1.626
## 57                            Guinea        2.587      2.069      2.262
## 58                     Guinea-Bissau        2.586      2.218      1.615
## 59                            Guyana        2.895      1.551      1.604
## 60                             Haiti        2.735      1.740      2.077
## 61                          Honduras        3.064      1.812      1.604
## 62                           Hungary        1.528      1.184      1.421
## 63                           Iceland        1.237      1.020      1.000
## 64                             India        2.373      2.461      2.982
## 65                         Indonesia        2.107      1.496      1.644
## 66                              Iran        2.838      2.123      2.923
## 67                              Iraq        3.646      2.298      3.207
## 68                           Ireland        1.525      1.259      1.015
## 69                            Israel        2.237      3.813      2.167
## 70                             Italy        1.927      2.013      1.034
## 71                           Jamaica        2.791      1.721      1.201
## 72                             Japan        1.283      1.308      1.403
## 73                            Jordan        2.037      1.964      1.542
## 74                        Kazakhstan        2.492      1.781      1.805
## 75                             Kenya        2.599      1.794      2.345
## 76                            Kosovo        2.266      1.575      1.805
## 77                            Kuwait        1.762      2.184      1.431
## 78                   Kyrgyz Republic        2.282      1.671      2.006
## 79                              Laos        2.076      1.949      1.403
## 80                            Latvia        1.798      1.479      1.634
## 81                           Lebanon        2.748      2.317      2.701
## 82                           Lesotho        2.528      1.748      1.805
## 83                           Liberia        2.491      1.804      1.462
## 84                             Libya        3.093      2.433      3.160
## 85                         Lithuania        1.775      1.735      1.638
## 86                        Madagascar        2.612      1.444      1.630
## 87                            Malawi        2.144      1.723      1.739
## 88                          Malaysia        1.973      1.205      1.015
## 89                              Mali        3.589      1.873      2.861
## 90                        Mauritania        2.782      1.969      1.638
## 91                         Mauritius        2.132      1.373      1.000
## 92                            Mexico        3.158      1.736      2.642
## 93                           Moldova        2.142      1.243      2.006
## 94                          Mongolia        2.459      1.348      1.201
## 95                        Montenegro        2.243      1.602      1.403
## 96                           Morocco        2.158      1.752      1.891
## 97                        Mozambique        2.803      1.677      2.215
## 98                           Myanmar        3.116      1.744      2.700
## 99                           Namibia        2.569      1.755      1.201
## 100                            Nepal        2.493      1.706      1.436
## 101                      Netherlands        1.525      2.206      1.045
## 102                      New Zealand        1.530      1.168      1.008
## 103                        Nicaragua        2.966      1.723      2.006
## 104                            Niger        2.957      1.957      2.839
## 105                          Nigeria        3.107      2.059      2.806
## 106                      North Korea        3.113      3.120      2.610
## 107                  North Macedonia        1.928      1.771      1.403
## 108                           Norway        1.266      2.184      1.235
## 109                             Oman        1.892      2.651      1.403
## 110                         Pakistan        2.653      2.581      3.172
## 111                        Palestine        2.950      1.991      2.612
## 112                           Panama        2.524      1.547      1.403
## 113                 Papua New Guinea        2.802      1.697      1.605
## 114                         Paraguay        2.534      2.004      1.403
## 115                             Peru        2.625      1.938      1.420
## 116                      Philippines        2.855      1.700      2.410
## 117                           Poland        1.933      1.527      1.403
## 118                         Portugal        1.390      1.312      1.007
## 119                            Qatar        1.495      2.196      1.246
## 120            Republic of the Congo        2.903      2.194      1.620
## 121                          Romania        1.837      1.773      1.007
## 122                           Russia        2.912      3.234      2.844
## 123                           Rwanda        2.374      1.512      1.858
## 124                     Saudi Arabia        2.254      2.614      2.425
## 125                          Senegal        2.337      1.701      1.418
## 126                           Serbia        1.976      1.796      1.604
## 127                     Sierra Leone        2.313      1.605      1.413
## 128                        Singapore        1.238      1.943      1.000
## 129                         Slovakia        1.835      1.274      1.403
## 130                         Slovenia        1.407      1.129      1.403
## 131                          Somalia        3.624      2.155      3.474
## 132                     South Africa        3.234      1.758      1.613
## 133                      South Korea        1.591      2.370      1.805
## 134                      South Sudan        3.957      2.594      3.267
## 135                            Spain        1.808      1.898      1.218
## 136                        Sri Lanka        2.377      2.047      1.855
## 137                            Sudan        3.303      2.312      3.040
## 138                           Sweden        1.475      1.802      1.221
## 139                      Switzerland        1.236      1.929      1.005
## 140                            Syria        3.741      2.287      3.828
## 141                           Taiwan        1.731      1.704      1.604
## 142                       Tajikistan        2.428      1.707      2.057
## 143                         Tanzania        2.353      1.687      1.479
## 144                         Thailand        2.863      1.562      1.916
## 145                       The Gambia        2.373      1.830      1.409
## 146                      Timor-Leste        2.369      1.667      1.403
## 147                             Togo        2.615      2.020      1.818
## 148              Trinidad and Tobago        2.736      2.098      1.201
## 149                          Tunisia        2.508      1.769      1.820
## 150                           Turkey        3.217      2.058      3.159
## 151                     Turkmenistan        2.501      2.383      1.604
## 152                           Uganda        2.762      1.760      1.765
## 153                          Ukraine        3.230      2.044      2.765
## 154             United Arab Emirates        1.712      2.652      1.464
## 155                   United Kingdom        1.729      2.489      1.042
## 156         United States of America        2.225      3.172      1.770
## 157                          Uruguay        2.323      1.582      1.000
## 158                       Uzbekistan        2.215      2.213      1.805
## 159                        Venezuela        4.007      2.002      2.103
## 160                          Vietnam        2.289      1.876      1.403
## 161                            Yemen        3.771      2.272      3.559
## 162                           Zambia        2.511      1.519      1.604
## 163                         Zimbabwe        2.990      2.044      2.112
library(rio)
data2 = import("~/PUCP/PUCP FACU/6TO CICLO/ESTADÍSTICA/ETR_data.xlsx")
data2
##                                        Country foodr_score naturald_score
## 1                                      Burundi           5              5
## 2                     Central African Republic           5              5
## 3                        Republic of the Congo           5              5
## 4                                        Kenya           5              5
## 5                                   Mozambique           5              5
## 6                                       Malawi           5              5
## 7                                        Niger           5              5
## 8                                      Somalia           5              5
## 9                                  South Sudan           5              5
## 10                                        Chad           5              5
## 11                                      Uganda           5              5
## 12                                       Yemen           5              5
## 13                                 Afghanistan           4              5
## 14                                       Benin           5              4
## 15                                    Cameroon           5              4
## 16            Democratic Republic of the Congo           5              4
## 17                                     Comoros           4              5
## 18                                  The Gambia           4              5
## 19                               Guinea-Bissau           5              4
## 20                                     Namibia           5              5
## 21                                     Nigeria           5              4
## 22                                    Zimbabwe           5              4
## 23                                      Angola           5              3
## 24                                    Ethiopia           4              4
## 25                                      Guinea           5              3
## 26                                       Haiti           5              5
## 27                                        Iraq           3              5
## 28                                  Madagascar           5              3
## 29                                  Mauritania           4              4
## 30                                      Rwanda           5              3
## 31                                       Sudan           4              4
## 32                                     Senegal           4              4
## 33                                Sierra Leone           5              4
## 34                       São Tomé and Príncipe           5              3
## 35                                    Tanzania           4              4
## 36                                      Zambia           5              3
## 37                                Burkina Faso           4              3
## 38                                    Botswana           4              5
## 39                              Cote d' Ivoire           4              3
## 40                                  Cape Verde           5              4
## 41                                     Ecuador           4              5
## 42                                       Ghana           4              3
## 43                                   Guatemala           4              5
## 44                                    Cambodia           4              5
## 45                                        Laos           4              5
## 46                                     Lesotho           5              4
## 47                                        Mali           4              3
## 48                                 Philippines           4              5
## 49                             Solomon Islands           2              5
## 50                                       Syria           5              5
## 51                                        Togo           4              3
## 52                                  Tajikistan           4              3
## 53                                 Timor-Leste           2              5
## 54                                   Venezuela           5              4
## 55                                    Djibouti           3              5
## 56                                     Eritrea           5              1
## 57                           Equatorial Guinea           5              1
## 58                                    Honduras           4              4
## 59                                     Liberia           5              1
## 60                                       Libya           3              5
## 61                                     Myanmar           4              5
## 62                                     Mayotte           5              1
## 63                                       Nepal           4              5
## 64                                    Pakistan           3              5
## 65                                        Peru           3              5
## 66                            Papua New Guinea           2              5
## 67                                      Belize           2              5
## 68                                     Bolivia           3              4
## 69                          Dominican Republic           3              5
## 70                                       Gabon           5              1
## 71                                     Morocco           3              4
## 72                                    Mongolia           2              5
## 73                                   Nicaragua           4              4
## 74                                    Eswatini           5              2
## 75                                     Vanuatu           2              5
## 76                                      Bhutan           2              5
## 77                                       Egypt           3              5
## 78                                   Indonesia           2              5
## 79                                   Sri Lanka           4              5
## 80                                 El Salvador           4              5
## 81                    Turks and Caicos Islands           3              5
## 82                                     Vietnam           2              5
## 83                         Antigua and Barbuda           3              5
## 84                                    Colombia           3              4
## 85                                        Cuba           3              5
## 86                                     Algeria           2              5
## 87              Federated States of Micronesia           2              5
## 88                               French Guiana           3              2
## 89                                        Iran           3              5
## 90                                   Mauritius           3              4
## 91                               New Caledonia           2              5
## 92                                      Panama           2              3
## 93                                       Palau           2              5
## 94                                    Suriname           2              5
## 95                                       Tonga           2              5
## 96                                      Tuvalu           2              5
## 97                                South Africa           3              2
## 98                                    Anguilla           3              5
## 99                                 The Bahamas           3              5
## 100                                     Brazil           2              4
## 101                                   Dominica           3              5
## 102                             Western Sahara           5              1
## 103                                       Fiji           2              4
## 104                                    Georgia           2              5
## 105                                     Guyana           2              5
## 106                                      India           3              4
## 107                            Kyrgyz Republic           2              4
## 108                                Saint Lucia           3              5
## 109                                   Malaysia           2              4
## 110                                   Paraguay           3              4
## 111                                  Palestine           3              1
## 112                                    Réunion           5              1
## 113                                     Russia           2              5
## 114                                 St. Helena           5              1
## 115                                 Seychelles           5              1
## 116                                   Thailand           2              5
## 117                                     Turkey           3              5
## 118           Saint Vincent and the Grenadines           3              5
## 119                     British Virgin Islands           3              5
## 120                                      Samoa           2              5
## 121                                 Bangladesh           4              4
## 122                                 Kazakhstan           2              4
## 123                                    Moldova           2              3
## 124                   Northern Mariana Islands           2              5
## 125                                Puerto Rico           2              5
## 126                                    Romania           2              5
## 127                                    Tokelau           2              1
## 128                                    Uruguay           2              5
## 129                                  Argentina           2              4
## 130                                  Australia           1              4
## 131                                   Barbados           3              4
## 132                                 Costa Rica           2              4
## 133                                    Jamaica           3              3
## 134                                     Jordan           3              3
## 135                      Saint Kitts and Nevis           3              4
## 136                                     Mexico           2              4
## 137                            North Macedonia           2              5
## 138                           French Polynesia           2              4
## 139                        Trinidad and Tobago           3              3
## 140                                    Tunisia           2              4
## 141                        U.S. Virgin Islands           3              4
## 142                                    Albania           2              4
## 143                                 Azerbaijan           2              1
## 144                                      China           1              4
## 145                                     Israel           1              3
## 146                                New Zealand           1              4
## 147                                       Oman           2              4
## 148                               Saudi Arabia           2              3
## 149                                    Ukraine           2              4
## 150                   United States of America           1              4
## 151                                 Uzbekistan           3              2
## 152                       United Arab Emirates           2              2
## 153                                    Armenia           2              2
## 154                                     Brunei           2              1
## 155                                     Canada           1              4
## 156                                      Chile           1              4
## 157                                    Croatia           1              5
## 158                                      Japan           1              5
## 159                                    Lebanon           3              4
## 160                                North Korea           2              4
## 161                                   Slovenia           1              5
## 162                                   Bulgaria           2              4
## 163                                    Bahrain           2              1
## 164                             St. Barthélemy           3              1
## 165                             Cayman Islands           3              1
## 166                                 Guadeloupe           3              2
## 167                                     Greece           1              4
## 168                                South Korea           2              4
## 169                                     Norway           1              4
## 170                                     Serbia           2              4
## 171                                     Taiwan           2              3
## 172                      Caribbean Netherlands           3              1
## 173                                    Bermuda           3              1
## 174                                Switzerland           1              4
## 175                                    Grenada           3              1
## 176                                     Kuwait           2              1
## 177                                  Lithuania           1              1
## 178                                 Luxembourg           1              3
## 179                           Marshall Islands           2              1
## 180                                 Montserrat           3              1
## 181                                 Martinique           3              1
## 182                                     Poland           1              3
## 183                                   Portugal           1              4
## 184                                     Sweden           1              4
## 185                             American Samoa           2              1
## 186                French Southern Territories           2              1
## 187                               Cook Islands           2              1
## 188                             Czech Republic           1              3
## 189                                       Guam           2              1
## 190                                    Ireland           1              3
## 191                                      Nauru           2              1
## 192                                      Qatar           2              1
## 193                               Turkmenistan           1              1
## 194 United States Minor Outlying Islands (the)           2              1
## 195                            Wallis & Futuna           2              1
## 196                                    Austria           1              3
## 197                                      Spain           1              3
## 198                                      Italy           1              3
## 199                                   Slovakia           2              2
## 200                     Bosnia and Herzegovina           2              2
## 201                                    Belarus           2              1
## 202                                    Estonia           1              2
## 203                                     Latvia           1              2
## 204                                 Montenegro           2              2
## 205                              Åland Islands           2              1
## 206                                    Andorra           2              1
## 207                                    Belgium           1              2
## 208                                     Cyprus           1              2
## 209                                    Germany           1              2
## 210                                    Finland           1              1
## 211                                     France           1              2
## 212                              Faroe Islands           2              1
## 213                                   Guernsey           2              1
## 214                                  Greenland           2              1
## 215                                    Hungary           1              2
## 216                                Isle of Man           2              1
## 217                                     Jersey           2              1
## 218                              Liechtenstein           2              1
## 219                                Netherlands           1              2
## 220                       Svalbard & Jan Mayen           2              1
## 221                                 San Marino           2              1
## 222                      St. Pierre & Miquelon           1              1
## 223                                     Kosovo           2              1
## 224                                    Denmark           1              1
## 225                             United Kingdom           1              1
## 226                                    Iceland           1              1
## 227                                      Malta           1              1
## 228                                  Singapore           1              1
##     RPG_score waterisk_score
## 1           5              5
## 2           5              5
## 3           5              5
## 4           5              5
## 5           5              5
## 6           5              5
## 7           5              5
## 8           5              5
## 9           5              5
## 10          5              5
## 11          5              5
## 12          5              5
## 13          5              5
## 14          5              5
## 15          5              5
## 16          5              5
## 17          5              5
## 18          5              5
## 19          5              5
## 20          4              5
## 21          5              5
## 22          5              5
## 23          5              5
## 24          5              5
## 25          5              5
## 26          3              5
## 27          5              5
## 28          5              5
## 29          5              5
## 30          5              5
## 31          5              5
## 32          5              5
## 33          4              5
## 34          5              5
## 35          5              5
## 36          5              5
## 37          5              5
## 38          3              5
## 39          5              5
## 40          3              5
## 41          3              5
## 42          5              5
## 43          4              4
## 44          3              5
## 45          3              5
## 46          3              5
## 47          5              5
## 48          3              5
## 49          5              5
## 50          5              2
## 51          5              5
## 52          5              5
## 53          5              5
## 54          3              5
## 55          3              5
## 56          5              5
## 57          5              5
## 58          3              5
## 59          5              5
## 60          5              3
## 61          2              5
## 62          5              5
## 63          2              5
## 64          4              4
## 65          3              5
## 66          4              5
## 67          4              4
## 68          3              5
## 69          2              5
## 70          4              5
## 71          3              5
## 72          3              5
## 73          2              5
## 74          3              5
## 75          4              4
## 76          3              4
## 77          4              2
## 78          2              5
## 79          1              4
## 80          1              4
## 81          3              3
## 82          2              5
## 83          2              3
## 84          1              5
## 85          1              4
## 86          3              3
## 87          3              3
## 88          5              3
## 89          1              4
## 90          1              5
## 91          3              3
## 92          3              5
## 93          3              3
## 94          1              5
## 95          3              3
## 96          3              3
## 97          3              5
## 98          1              3
## 99          1              3
## 100         1              5
## 101         1              3
## 102         4              2
## 103         1              5
## 104         1              4
## 105         1              4
## 106         2              4
## 107         3              4
## 108         1              3
## 109         3              4
## 110         2              4
## 111         5              3
## 112         1              5
## 113         1              4
## 114         1              5
## 115         1              5
## 116         1              4
## 117         1              3
## 118         1              3
## 119         1              3
## 120         2              3
## 121         2              2
## 122         2              4
## 123         1              5
## 124         1              3
## 125         1              3
## 126         1              3
## 127         5              3
## 128         1              3
## 129         2              3
## 130         3              3
## 131         1              3
## 132         1              4
## 133         1              4
## 134         3              3
## 135         1              3
## 136         2              3
## 137         1              2
## 138         2              3
## 139         1              4
## 140         2              3
## 141         1              3
## 142         1              3
## 143         1              5
## 144         2              3
## 145         4              2
## 146         2              3
## 147         3              1
## 148         3              3
## 149         1              3
## 150         2              3
## 151         3              3
## 152         3              3
## 153         1              4
## 154         2              4
## 155         2              2
## 156         1              3
## 157         1              1
## 158         1              1
## 159         1              1
## 160         1              2
## 161         1              1
## 162         1              1
## 163         3              3
## 164         2              3
## 165         2              3
## 166         1              3
## 167         1              2
## 168         1              1
## 169         2              1
## 170         1              1
## 171         1              3
## 172         1              3
## 173         1              3
## 174         1              1
## 175         1              3
## 176         3              2
## 177         1              4
## 178         3              1
## 179         2              3
## 180         1              3
## 181         1              3
## 182         1              3
## 183         1              1
## 184         1              1
## 185         1              3
## 186         1              3
## 187         1              3
## 188         1              2
## 189         1              3
## 190         2              1
## 191         1              3
## 192         3              1
## 193         3              2
## 194         1              3
## 195         1              3
## 196         1              1
## 197         1              1
## 198         1              1
## 199         1              2
## 200         1              1
## 201         1              2
## 202         1              2
## 203         1              2
## 204         1              1
## 205         1              1
## 206         1              1
## 207         1              1
## 208         1              1
## 209         1              1
## 210         1              2
## 211         1              1
## 212         1              1
## 213         1              1
## 214         1              1
## 215         1              1
## 216         1              1
## 217         1              1
## 218         1              1
## 219         1              1
## 220         1              1
## 221         1              1
## 222         1              2
## 223         1              1
## 224         1              1
## 225         1              1
## 226         1              1
## 227         1              1
## 228         1              1
data2 = data2[complete.cases(data2),]
data2
##                                        Country foodr_score naturald_score
## 1                                      Burundi           5              5
## 2                     Central African Republic           5              5
## 3                        Republic of the Congo           5              5
## 4                                        Kenya           5              5
## 5                                   Mozambique           5              5
## 6                                       Malawi           5              5
## 7                                        Niger           5              5
## 8                                      Somalia           5              5
## 9                                  South Sudan           5              5
## 10                                        Chad           5              5
## 11                                      Uganda           5              5
## 12                                       Yemen           5              5
## 13                                 Afghanistan           4              5
## 14                                       Benin           5              4
## 15                                    Cameroon           5              4
## 16            Democratic Republic of the Congo           5              4
## 17                                     Comoros           4              5
## 18                                  The Gambia           4              5
## 19                               Guinea-Bissau           5              4
## 20                                     Namibia           5              5
## 21                                     Nigeria           5              4
## 22                                    Zimbabwe           5              4
## 23                                      Angola           5              3
## 24                                    Ethiopia           4              4
## 25                                      Guinea           5              3
## 26                                       Haiti           5              5
## 27                                        Iraq           3              5
## 28                                  Madagascar           5              3
## 29                                  Mauritania           4              4
## 30                                      Rwanda           5              3
## 31                                       Sudan           4              4
## 32                                     Senegal           4              4
## 33                                Sierra Leone           5              4
## 34                       São Tomé and Príncipe           5              3
## 35                                    Tanzania           4              4
## 36                                      Zambia           5              3
## 37                                Burkina Faso           4              3
## 38                                    Botswana           4              5
## 39                              Cote d' Ivoire           4              3
## 40                                  Cape Verde           5              4
## 41                                     Ecuador           4              5
## 42                                       Ghana           4              3
## 43                                   Guatemala           4              5
## 44                                    Cambodia           4              5
## 45                                        Laos           4              5
## 46                                     Lesotho           5              4
## 47                                        Mali           4              3
## 48                                 Philippines           4              5
## 49                             Solomon Islands           2              5
## 50                                       Syria           5              5
## 51                                        Togo           4              3
## 52                                  Tajikistan           4              3
## 53                                 Timor-Leste           2              5
## 54                                   Venezuela           5              4
## 55                                    Djibouti           3              5
## 56                                     Eritrea           5              1
## 57                           Equatorial Guinea           5              1
## 58                                    Honduras           4              4
## 59                                     Liberia           5              1
## 60                                       Libya           3              5
## 61                                     Myanmar           4              5
## 62                                     Mayotte           5              1
## 63                                       Nepal           4              5
## 64                                    Pakistan           3              5
## 65                                        Peru           3              5
## 66                            Papua New Guinea           2              5
## 67                                      Belize           2              5
## 68                                     Bolivia           3              4
## 69                          Dominican Republic           3              5
## 70                                       Gabon           5              1
## 71                                     Morocco           3              4
## 72                                    Mongolia           2              5
## 73                                   Nicaragua           4              4
## 74                                    Eswatini           5              2
## 75                                     Vanuatu           2              5
## 76                                      Bhutan           2              5
## 77                                       Egypt           3              5
## 78                                   Indonesia           2              5
## 79                                   Sri Lanka           4              5
## 80                                 El Salvador           4              5
## 81                    Turks and Caicos Islands           3              5
## 82                                     Vietnam           2              5
## 83                         Antigua and Barbuda           3              5
## 84                                    Colombia           3              4
## 85                                        Cuba           3              5
## 86                                     Algeria           2              5
## 87              Federated States of Micronesia           2              5
## 88                               French Guiana           3              2
## 89                                        Iran           3              5
## 90                                   Mauritius           3              4
## 91                               New Caledonia           2              5
## 92                                      Panama           2              3
## 93                                       Palau           2              5
## 94                                    Suriname           2              5
## 95                                       Tonga           2              5
## 96                                      Tuvalu           2              5
## 97                                South Africa           3              2
## 98                                    Anguilla           3              5
## 99                                 The Bahamas           3              5
## 100                                     Brazil           2              4
## 101                                   Dominica           3              5
## 102                             Western Sahara           5              1
## 103                                       Fiji           2              4
## 104                                    Georgia           2              5
## 105                                     Guyana           2              5
## 106                                      India           3              4
## 107                            Kyrgyz Republic           2              4
## 108                                Saint Lucia           3              5
## 109                                   Malaysia           2              4
## 110                                   Paraguay           3              4
## 111                                  Palestine           3              1
## 112                                    Réunion           5              1
## 113                                     Russia           2              5
## 114                                 St. Helena           5              1
## 115                                 Seychelles           5              1
## 116                                   Thailand           2              5
## 117                                     Turkey           3              5
## 118           Saint Vincent and the Grenadines           3              5
## 119                     British Virgin Islands           3              5
## 120                                      Samoa           2              5
## 121                                 Bangladesh           4              4
## 122                                 Kazakhstan           2              4
## 123                                    Moldova           2              3
## 124                   Northern Mariana Islands           2              5
## 125                                Puerto Rico           2              5
## 126                                    Romania           2              5
## 127                                    Tokelau           2              1
## 128                                    Uruguay           2              5
## 129                                  Argentina           2              4
## 130                                  Australia           1              4
## 131                                   Barbados           3              4
## 132                                 Costa Rica           2              4
## 133                                    Jamaica           3              3
## 134                                     Jordan           3              3
## 135                      Saint Kitts and Nevis           3              4
## 136                                     Mexico           2              4
## 137                            North Macedonia           2              5
## 138                           French Polynesia           2              4
## 139                        Trinidad and Tobago           3              3
## 140                                    Tunisia           2              4
## 141                        U.S. Virgin Islands           3              4
## 142                                    Albania           2              4
## 143                                 Azerbaijan           2              1
## 144                                      China           1              4
## 145                                     Israel           1              3
## 146                                New Zealand           1              4
## 147                                       Oman           2              4
## 148                               Saudi Arabia           2              3
## 149                                    Ukraine           2              4
## 150                   United States of America           1              4
## 151                                 Uzbekistan           3              2
## 152                       United Arab Emirates           2              2
## 153                                    Armenia           2              2
## 154                                     Brunei           2              1
## 155                                     Canada           1              4
## 156                                      Chile           1              4
## 157                                    Croatia           1              5
## 158                                      Japan           1              5
## 159                                    Lebanon           3              4
## 160                                North Korea           2              4
## 161                                   Slovenia           1              5
## 162                                   Bulgaria           2              4
## 163                                    Bahrain           2              1
## 164                             St. Barthélemy           3              1
## 165                             Cayman Islands           3              1
## 166                                 Guadeloupe           3              2
## 167                                     Greece           1              4
## 168                                South Korea           2              4
## 169                                     Norway           1              4
## 170                                     Serbia           2              4
## 171                                     Taiwan           2              3
## 172                      Caribbean Netherlands           3              1
## 173                                    Bermuda           3              1
## 174                                Switzerland           1              4
## 175                                    Grenada           3              1
## 176                                     Kuwait           2              1
## 177                                  Lithuania           1              1
## 178                                 Luxembourg           1              3
## 179                           Marshall Islands           2              1
## 180                                 Montserrat           3              1
## 181                                 Martinique           3              1
## 182                                     Poland           1              3
## 183                                   Portugal           1              4
## 184                                     Sweden           1              4
## 185                             American Samoa           2              1
## 186                French Southern Territories           2              1
## 187                               Cook Islands           2              1
## 188                             Czech Republic           1              3
## 189                                       Guam           2              1
## 190                                    Ireland           1              3
## 191                                      Nauru           2              1
## 192                                      Qatar           2              1
## 193                               Turkmenistan           1              1
## 194 United States Minor Outlying Islands (the)           2              1
## 195                            Wallis & Futuna           2              1
## 196                                    Austria           1              3
## 197                                      Spain           1              3
## 198                                      Italy           1              3
## 199                                   Slovakia           2              2
## 200                     Bosnia and Herzegovina           2              2
## 201                                    Belarus           2              1
## 202                                    Estonia           1              2
## 203                                     Latvia           1              2
## 204                                 Montenegro           2              2
## 205                              Åland Islands           2              1
## 206                                    Andorra           2              1
## 207                                    Belgium           1              2
## 208                                     Cyprus           1              2
## 209                                    Germany           1              2
## 210                                    Finland           1              1
## 211                                     France           1              2
## 212                              Faroe Islands           2              1
## 213                                   Guernsey           2              1
## 214                                  Greenland           2              1
## 215                                    Hungary           1              2
## 216                                Isle of Man           2              1
## 217                                     Jersey           2              1
## 218                              Liechtenstein           2              1
## 219                                Netherlands           1              2
## 220                       Svalbard & Jan Mayen           2              1
## 221                                 San Marino           2              1
## 222                      St. Pierre & Miquelon           1              1
## 223                                     Kosovo           2              1
## 224                                    Denmark           1              1
## 225                             United Kingdom           1              1
## 226                                    Iceland           1              1
## 227                                      Malta           1              1
## 228                                  Singapore           1              1
##     RPG_score waterisk_score
## 1           5              5
## 2           5              5
## 3           5              5
## 4           5              5
## 5           5              5
## 6           5              5
## 7           5              5
## 8           5              5
## 9           5              5
## 10          5              5
## 11          5              5
## 12          5              5
## 13          5              5
## 14          5              5
## 15          5              5
## 16          5              5
## 17          5              5
## 18          5              5
## 19          5              5
## 20          4              5
## 21          5              5
## 22          5              5
## 23          5              5
## 24          5              5
## 25          5              5
## 26          3              5
## 27          5              5
## 28          5              5
## 29          5              5
## 30          5              5
## 31          5              5
## 32          5              5
## 33          4              5
## 34          5              5
## 35          5              5
## 36          5              5
## 37          5              5
## 38          3              5
## 39          5              5
## 40          3              5
## 41          3              5
## 42          5              5
## 43          4              4
## 44          3              5
## 45          3              5
## 46          3              5
## 47          5              5
## 48          3              5
## 49          5              5
## 50          5              2
## 51          5              5
## 52          5              5
## 53          5              5
## 54          3              5
## 55          3              5
## 56          5              5
## 57          5              5
## 58          3              5
## 59          5              5
## 60          5              3
## 61          2              5
## 62          5              5
## 63          2              5
## 64          4              4
## 65          3              5
## 66          4              5
## 67          4              4
## 68          3              5
## 69          2              5
## 70          4              5
## 71          3              5
## 72          3              5
## 73          2              5
## 74          3              5
## 75          4              4
## 76          3              4
## 77          4              2
## 78          2              5
## 79          1              4
## 80          1              4
## 81          3              3
## 82          2              5
## 83          2              3
## 84          1              5
## 85          1              4
## 86          3              3
## 87          3              3
## 88          5              3
## 89          1              4
## 90          1              5
## 91          3              3
## 92          3              5
## 93          3              3
## 94          1              5
## 95          3              3
## 96          3              3
## 97          3              5
## 98          1              3
## 99          1              3
## 100         1              5
## 101         1              3
## 102         4              2
## 103         1              5
## 104         1              4
## 105         1              4
## 106         2              4
## 107         3              4
## 108         1              3
## 109         3              4
## 110         2              4
## 111         5              3
## 112         1              5
## 113         1              4
## 114         1              5
## 115         1              5
## 116         1              4
## 117         1              3
## 118         1              3
## 119         1              3
## 120         2              3
## 121         2              2
## 122         2              4
## 123         1              5
## 124         1              3
## 125         1              3
## 126         1              3
## 127         5              3
## 128         1              3
## 129         2              3
## 130         3              3
## 131         1              3
## 132         1              4
## 133         1              4
## 134         3              3
## 135         1              3
## 136         2              3
## 137         1              2
## 138         2              3
## 139         1              4
## 140         2              3
## 141         1              3
## 142         1              3
## 143         1              5
## 144         2              3
## 145         4              2
## 146         2              3
## 147         3              1
## 148         3              3
## 149         1              3
## 150         2              3
## 151         3              3
## 152         3              3
## 153         1              4
## 154         2              4
## 155         2              2
## 156         1              3
## 157         1              1
## 158         1              1
## 159         1              1
## 160         1              2
## 161         1              1
## 162         1              1
## 163         3              3
## 164         2              3
## 165         2              3
## 166         1              3
## 167         1              2
## 168         1              1
## 169         2              1
## 170         1              1
## 171         1              3
## 172         1              3
## 173         1              3
## 174         1              1
## 175         1              3
## 176         3              2
## 177         1              4
## 178         3              1
## 179         2              3
## 180         1              3
## 181         1              3
## 182         1              3
## 183         1              1
## 184         1              1
## 185         1              3
## 186         1              3
## 187         1              3
## 188         1              2
## 189         1              3
## 190         2              1
## 191         1              3
## 192         3              1
## 193         3              2
## 194         1              3
## 195         1              3
## 196         1              1
## 197         1              1
## 198         1              1
## 199         1              2
## 200         1              1
## 201         1              2
## 202         1              2
## 203         1              2
## 204         1              1
## 205         1              1
## 206         1              1
## 207         1              1
## 208         1              1
## 209         1              1
## 210         1              2
## 211         1              1
## 212         1              1
## 213         1              1
## 214         1              1
## 215         1              1
## 216         1              1
## 217         1              1
## 218         1              1
## 219         1              1
## 220         1              1
## 221         1              1
## 222         1              2
## 223         1              1
## 224         1              1
## 225         1              1
## 226         1              1
## 227         1              1
## 228         1              1
MERGEdatas =merge(data1, data2, by = "Country")
str(MERGEdatas)
## 'data.frame':    163 obs. of  8 variables:
##  $ Country       : chr  "Afghanistan" "Albania" "Algeria" "Angola" ...
##  $ 2022_safesec  : num  4.13 2.12 2.3 2.41 2.66 ...
##  $ 2022_milit    : num  2.47 1.67 2.04 1.71 1.61 ...
##  $ 2022_oncon    : num  3.65 1.4 2.07 1.67 1.2 ...
##  $ foodr_score   : num  4 2 2 5 2 2 1 1 2 2 ...
##  $ naturald_score: num  5 4 5 3 4 2 4 3 1 1 ...
##  $ RPG_score     : num  5 1 3 5 2 1 3 1 1 3 ...
##  $ waterisk_score: num  5 3 3 5 3 4 3 1 5 3 ...
head(MERGEdatas)
##       Country 2022_safesec 2022_milit 2022_oncon foodr_score naturald_score
## 1 Afghanistan        4.127      2.472      3.650           4              5
## 2     Albania        2.120      1.666      1.403           2              4
## 3     Algeria        2.302      2.041      2.068           2              5
## 4      Angola        2.413      1.706      1.666           5              3
## 5   Argentina        2.656      1.611      1.201           2              4
## 6     Armenia        1.977      2.041      1.990           2              2
##   RPG_score waterisk_score
## 1         5              5
## 2         1              3
## 3         3              3
## 4         5              5
## 5         2              3
## 6         1              4

Clusterización con PAM sin tipificar:

clusMERGEdatas2=MERGEdatas[,c(2:8)]
row.names(clusMERGEdatas2)=MERGEdatas$Country
library(cluster)
g.dist2 = daisy(clusMERGEdatas2, metric="gower")
library(factoextra)
## Loading required package: ggplot2
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
fviz_nbclust(clusMERGEdatas2, pam,diss=g.dist2,method ="gap_stat",k.max =10,verbose =F)

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(kableExtra)
## 
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
## 
##     group_rows
set.seed(123)
res.pam2=pam(g.dist2,3,cluster.only=F) #el número refleja la cantidad de clusters
#nueva columna
clusMERGEdatas2$pam=res.pam2$cluster
# ver
head(clusMERGEdatas2,15)%>%kbl()%>%kable_styling()
2022_safesec 2022_milit 2022_oncon foodr_score naturald_score RPG_score waterisk_score pam
Afghanistan 4.127 2.472 3.650 4 5 5 5 1
Albania 2.120 1.666 1.403 2 4 1 3 2
Algeria 2.302 2.041 2.068 2 5 3 3 2
Angola 2.413 1.706 1.666 5 3 5 5 1
Argentina 2.656 1.611 1.201 2 4 2 3 2
Armenia 1.977 2.041 1.990 2 2 1 4 2
Australia 1.657 1.848 1.266 1 4 3 3 2
Austria 1.452 1.331 1.097 1 3 1 1 3
Azerbaijan 2.528 2.108 2.579 2 1 1 5 2
Bahrain 2.405 1.717 1.955 2 1 3 3 2
Bangladesh 2.438 1.534 2.004 4 4 2 2 2
Belarus 2.526 1.896 2.208 2 1 1 2 3
Belgium 1.806 1.602 1.141 1 2 1 1 3
Benin 2.574 2.022 1.666 5 4 5 5 1
Bhutan 1.601 1.336 1.436 2 5 3 4 2
fviz_silhouette(res.pam2,print.summary = F) #barras para abajo están mal clusterizadas

Preparación de datos para la clusterización tipificada:

boxplot(MERGEdatas[,c(2:8)],horizontal = F,las=2,cex.axis =0.5)

library(BBmisc)
## 
## Attaching package: 'BBmisc'
## The following objects are masked from 'package:dplyr':
## 
##     coalesce, collapse
## The following object is masked from 'package:base':
## 
##     isFALSE
boxplot(normalize(MERGEdatas[,c(2:8)],method='range',range=c(0,10))) #CAMBIAR ORIENTACIÓN DE NOMBRES

library(BBmisc)
boxplot(normalize(MERGEdatas[,c(2:8)],method='standardize'))

MERGEdatas[,c(2:8)]=normalize(MERGEdatas[,c(2:8)],method='standardize') #preguntar si nos quedamos con este o cambiamos por el de range
cor(MERGEdatas[,c(2:8)])
##                2022_safesec 2022_milit 2022_oncon foodr_score naturald_score
## 2022_safesec      1.0000000 0.32475365  0.7341753  0.66058571     0.35251645
## 2022_milit        0.3247536 1.00000000  0.4495004  0.08883541     0.05969936
## 2022_oncon        0.7341753 0.44950043  1.0000000  0.44921226     0.25637791
## foodr_score       0.6605857 0.08883541  0.4492123  1.00000000     0.28711933
## naturald_score    0.3525165 0.05969936  0.2563779  0.28711933     1.00000000
## RPG_score         0.5078034 0.18837463  0.4321162  0.76202029     0.17405917
## waterisk_score    0.6370051 0.01704344  0.3393531  0.75129538     0.36454740
##                RPG_score waterisk_score
## 2022_safesec   0.5078034     0.63700512
## 2022_milit     0.1883746     0.01704344
## 2022_oncon     0.4321162     0.33935309
## foodr_score    0.7620203     0.75129538
## naturald_score 0.1740592     0.36454740
## RPG_score      1.0000000     0.63011932
## waterisk_score 0.6301193     1.00000000

Clusterización con PAM:

clusMERGEdatas=MERGEdatas[,c(2:8)]
row.names(clusMERGEdatas)=MERGEdatas$Country
library(cluster)
g.dist = daisy(clusMERGEdatas, metric="gower")
library(factoextra)
fviz_nbclust(clusMERGEdatas, pam,diss=g.dist,method ="gap_stat",k.max =10,verbose =F)

library(dplyr)
library(kableExtra)
set.seed(123)
res.pam=pam(g.dist,8,cluster.only=F) #el número refleja la cantidad de clusters
#nueva columna
clusMERGEdatas$pam=res.pam$cluster
# ver
head(clusMERGEdatas,15)%>%kbl()%>%kable_styling()
2022_safesec 2022_milit 2022_oncon foodr_score naturald_score RPG_score waterisk_score pam
Afghanistan 2.7198722 1.4692293 2.7432847 0.775457 1.0174633 1.3896665 0.9195792 1
Albania -0.4643791 -0.5017953 -0.6274257 -0.591024 0.2636155 -1.0525507 -0.3560924 2
Algeria -0.1756229 0.4152447 0.3701366 -0.591024 1.0174633 0.1685579 -0.3560924 2
Angola 0.0004867 -0.4039777 -0.2329010 1.458697 -0.4902323 1.3896665 0.9195792 3
Argentina 0.3860238 -0.6362945 -0.9304446 -0.591024 0.2636155 -0.4419964 -0.3560924 2
Armenia -0.6912590 0.4152447 0.2531293 -0.591024 -1.2440801 -1.0525507 0.2817434 4
Australia -1.1989622 -0.0567252 -0.8329385 -1.274264 0.2636155 0.1685579 -0.3560924 2
Austria -1.5242096 -1.3210176 -1.0864543 -1.274264 -0.4902323 -1.0525507 -1.6317640 5
Azerbaijan 0.1829425 0.5790892 1.1366845 -0.591024 -1.9979279 -1.0525507 0.9195792 4
Bahrain -0.0122059 -0.3770778 0.2006260 -0.591024 -1.9979279 0.1685579 -0.3560924 6
Bangladesh 0.0401510 -0.8245933 0.2741306 0.775457 0.2636155 -0.4419964 -0.9939282 2
Belarus 0.1797694 0.0606559 0.5801497 -0.591024 -1.9979279 -1.0525507 -0.9939282 6
Belgium -0.9625629 -0.6583034 -1.0204502 -1.274264 -1.2440801 -1.0525507 -1.6317640 7
Benin 0.2559249 0.3687813 -0.2329010 1.458697 0.2636155 1.3896665 0.9195792 3
Bhutan -1.2878103 -1.3087904 -0.5779226 -0.591024 1.0174633 0.1685579 0.2817434 4
fviz_silhouette(res.pam,print.summary = F) #barras para abajo están mal clusterizadas