Prevalencia del VIH en mujeres a nivel mundial

###Limpieza de datas

Data Prevalencia VIH (2013-2017)

link1="https://docs.google.com/spreadsheets/d/e/2PACX-1vQ51CAVKCjF_48ylMXr4FJkuVOHpXlUhaGmIA44cdQeWt4cBNjfekSgrPMjZMXrZg/pub?gid=14954305&single=true&output=csv"
DataVIH=read.csv(link1, stringsAsFactors = F)
DataVIH2 = DataVIH[,c(1,58:62)]
names(DataVIH2) = c("Pais","2013","2014","2015", "2016", "2017")

DataVIH2$`2013` =   gsub("\\,", ".", DataVIH2$`2013`) 
DataVIH2$`2014` =   gsub("\\,", ".", DataVIH2$`2014`) 
DataVIH2$`2015` =   gsub("\\,", ".", DataVIH2$`2015`) 
DataVIH2$`2016` =   gsub("\\,", ".", DataVIH2$`2016`) 
DataVIH2$`2017` =   gsub("\\,", ".", DataVIH2$`2017`)
DataVIH2[,c(2:6)]=lapply(DataVIH2[,c(2:6)],as.numeric) #volver numerico en grupo

DataVIH2 = DataVIH2[complete.cases(DataVIH2),]
row.names(DataVIH2) = NULL

DataVIH2$VIH = rowMeans(DataVIH2[,2:6])
DataVIH2 = DataVIH2[,c (1,7)]

Data Población Activa Mujeres

link2="https://docs.google.com/spreadsheets/d/e/2PACX-1vQ-T56gOlA6lVVHHnrqUR6bc_doAmUewuvSlG4CcNgYyeZVUbPiozpcciPpDS3SyQ/pub?gid=1993384276&single=true&output=csv"
DataAct=read.csv(link2,stringsAsFactors = F)
DataAct2 = DataAct[,c(1,53:57)]
names(DataAct2) = c("Pais","2008","2009", "2010", "2011", "2012")

DataAct2$`2008` =   gsub("\\,", ".", DataAct2$`2008`) 
DataAct2$`2009` =   gsub("\\,", ".", DataAct2$`2009`) 
DataAct2$`2010` =   gsub("\\,", ".", DataAct2$`2010`) 
DataAct2$`2011` =   gsub("\\,", ".", DataAct2$`2011`) 
DataAct2$`2012` =   gsub("\\,", ".", DataAct2$`2012`) 
DataAct2[,c(2:6)]=lapply(DataAct2[,c(2:6)],as.numeric) #volver numerico en grupo

DataAct2 = DataAct2[complete.cases(DataAct2),]
row.names(DataAct2) = NULL

DataAct2$PoblacionActiva = rowMeans(DataAct2[,2:6])
DataAct2= DataAct2[,c (1,7)]

Data Participación en la Fuerza Laboral Mujeres

link3="https://docs.google.com/spreadsheets/d/e/2PACX-1vTDcvi_z6RrnoATATdOGBLj2WlKRmVxqvx2hc4lUqkMwCcF3j9BLklmz0VjjIX4vA/pub?gid=1181245938&single=true&output=csv"
DataFLM= read.csv(link3, stringsAsFactors = F)
DataFLM2 = DataFLM[,c(1,53:57)]
names(DataFLM2) = c("Pais","2008","2009","2010", "2011", "2012")

DataFLM2$`2008` =   gsub("\\,", ".", DataFLM2$`2008`) 
DataFLM2$`2009` =   gsub("\\,", ".", DataFLM2$`2009`) 
DataFLM2$`2010` =   gsub("\\,", ".", DataFLM2$`2010`) 
DataFLM2$`2011` =   gsub("\\,", ".", DataFLM2$`2011`) 
DataFLM2$`2012` =   gsub("\\,", ".", DataFLM2$`2012`)
DataFLM2[,c(2:6)]=lapply(DataFLM2[,c(2:6)],as.numeric)

DataFLM2$FLM = rowMeans(DataFLM2[,2:6],na.rm = TRUE)
DataFLM2= DataFLM2[,c (1,7)]
DataFLM2 = DataFLM2[complete.cases(DataFLM2),]
row.names(DataFLM2) = NULL

Data Prevalencia de Métodos anticoceptivos

link4="https://docs.google.com/spreadsheets/d/e/2PACX-1vRI-hkw-v7fdeFY_c1aS0c_DD86WJ-0k_G9Ti2lE_0_P3nGcPHagckLPhVM9SzD5g/pub?gid=932337199&single=true&output=csv"
DataMetodos= read.csv(link4, stringsAsFactors = F)
DataMetodos2 = DataMetodos[,c(1,53:57)]
names(DataMetodos2) = c("Pais","2008","2009","2010", "2011", "2012")

DataMetodos2$`2008` =   gsub("\\,", ".", DataMetodos2$`2008`) 
DataMetodos2$`2009` =   gsub("\\,", ".", DataMetodos2$`2009`) 
DataMetodos2$`2010` =   gsub("\\,", ".", DataMetodos2$`2010`) 
DataMetodos2$`2011` =   gsub("\\,", ".", DataMetodos2$`2011`) 
DataMetodos2$`2012` =   gsub("\\,", ".", DataMetodos2$`2012`)
DataMetodos2[,c(2:6)]=lapply(DataMetodos2[,c(2:6)],as.numeric)

DataMetodos2$Metodos = rowMeans(DataMetodos2[,2:6],na.rm = TRUE)
DataMetodos2= DataMetodos2[,c (1,7)]
DataMetodos2 = DataMetodos2[complete.cases(DataMetodos2),]
row.names(DataMetodos2) = NULL

Data de población en barrios de tugurios

link5="https://docs.google.com/spreadsheets/d/e/2PACX-1vQnghOacrnZH200jpcJc-Vym7n8rrfuQlupJ470spsBTvZ0WUWvl63x2AYL1W92sw/pub?gid=1538383881&single=true&output=csv"
DataTugurios= read.csv(link5, stringsAsFactors = F)
DataTugurios2 = DataTugurios[,c(1,53:57)]
names(DataTugurios2) = c("Pais","2008","2009","2010", "2011", "2012")

DataTugurios2$`2008` =   gsub("\\,", ".", DataTugurios2$`2008`) 
DataTugurios2$`2009` =   gsub("\\,", ".", DataTugurios2$`2009`) 
DataTugurios2$`2010` =   gsub("\\,", ".", DataTugurios2$`2010`) 
DataTugurios2$`2011` =   gsub("\\,", ".", DataTugurios2$`2011`) 
DataTugurios2$`2012` =   gsub("\\,", ".", DataTugurios2$`2012`)
DataTugurios2[,c(2:6)]=lapply(DataTugurios2[,c(2:6)],as.numeric)

DataTugurios2$BarriosTugurios= rowMeans(DataTugurios2[,2:6],na.rm = TRUE)
DataTugurios2= DataTugurios2[,c (1,7)]
DataTugurios2 = DataTugurios2[complete.cases(DataTugurios2),]
row.names(DataTugurios2) = NULL

Data de Gini

link6="https://docs.google.com/spreadsheets/d/e/2PACX-1vSOdz-vUkw9_yctGztLL_PS87cCS7GoU10PiLA3ywnO8-iNXG1OBi_8OBOpZ0r3AQ/pub?gid=826191890&single=true&output=csv"
DataGini= read.csv(link6, stringsAsFactors = F)
DataGini2 = DataGini[,c(1,53:57)]
names(DataGini2) = c("Pais","2008","2009","2010", "2011", "2012")

DataGini2$`2008` =   gsub("\\,", ".", DataGini2$`2008`) 
DataGini2$`2009` =   gsub("\\,", ".", DataGini2$`2009`) 
DataGini2$`2010` =   gsub("\\,", ".", DataGini2$`2010`) 
DataGini2$`2011` =   gsub("\\,", ".", DataGini2$`2011`) 
DataGini2$`2012` =   gsub("\\,", ".", DataGini2$`2012`)
DataGini2[,c(2:6)]=lapply(DataGini2[,c(2:6)],as.numeric)

DataGini2$Gini= rowMeans(DataGini2[,2:6],na.rm = TRUE)
DataGini2= DataGini2[,c (1,7)]
DataGini2 = DataGini2[complete.cases(DataGini2),]
row.names(DataGini2) = NULL

DATA ALFABETIZACIÓN

link7="https://docs.google.com/spreadsheets/d/e/2PACX-1vTTojodRJwkAu-98fKnnuzUCJZE-Wj4tDFm7F2XQLDeT3CSifu-yWiHZuZv-uzL2Q/pub?gid=1142139153&single=true&output=csv"
EDU=read.csv(link7,stringsAsFactors = F)

EDU2=EDU[,c(1,53:57)]
names(EDU2)=c("Pais", "2008","2009","2010","2011","2012")

EDU2$`2008`= gsub("\\,", ".",EDU2$`2008`)
EDU2$`2009`= gsub("\\,", ".",EDU2$`2009`)
EDU2$`2010`= gsub("\\,", ".",EDU2$`2010`)
EDU2$`2011`= gsub("\\,", ".",EDU2$`2011`)
EDU2$`2012`= gsub("\\,", ".",EDU2$`2012`)
EDU2[c(2:6)] = lapply(EDU2[c(2:6)], as.numeric)

EDU2$EDU = rowMeans(EDU2[,2:6],na.rm = TRUE)
EDU2= EDU2[,c (1,7)]
EDU2= EDU2[complete.cases(EDU2),]
row.names(EDU2) = NULL

DATA DE ACCESO A LA ELECTRICIDAD

link8="https://docs.google.com/spreadsheets/d/e/2PACX-1vQrlQtEYBGaf0IhPz_H9oaM8uD1UaVoR1J_xP6bYe8ZqNAVSRJiLh4DXq52KomGsQ/pub?gid=2059415238&single=true&output=csv"
ENER=read.csv(link8,stringsAsFactors = F)

ENER2=ENER[,c(1,53:57)]
names(ENER2)=c("Pais","2008","2009","2010","2011","2012")

ENER2$`2008`= gsub("\\,", ".",ENER2$`2008`)
ENER2$`2009`= gsub("\\,", ".",ENER2$`2009`)
ENER2$`2010`= gsub("\\,", ".",ENER2$`2010`)
ENER2$`2011`= gsub("\\,", ".",ENER2$`2011`)
ENER2$`2012`= gsub("\\,", ".",ENER2$`2012`)
ENER2[c(2:6)] = lapply(ENER2[c(2:6)], as.numeric)

ENER2$ENER = rowMeans(ENER2[,2:6],na.rm = TRUE)
ENER2= ENER2[,c (1,7)]
ENER2= ENER2[complete.cases(ENER2),]
row.names(ENER2) = NULL

DATA DE GASTO

link9="https://docs.google.com/spreadsheets/d/e/2PACX-1vQ6hJgrir9ZBg6Qo5dfwQGluWp4oZLEfSVgz-sVzHEqav1pulMwix_2jNcjxcCkjw/pub?gid=1845220649&single=true&output=csv"
GAST=read.csv(link9,stringsAsFactors = F)

GAST2=GAST[,c(1,53:57)]
names(GAST2)=c("Pais","2008","2009","2010","2011","2012")

GAST2$`2008`= gsub("\\,", ".",GAST2$`2008`)
GAST2$`2009`= gsub("\\,", ".",GAST2$`2009`)
GAST2$`2010`= gsub("\\,", ".",GAST2$`2010`)
GAST2$`2011`= gsub("\\,", ".",GAST2$`2011`)
GAST2$`2012`= gsub("\\,", ".",GAST2$`2012`)
GAST2[c(2:6)] = lapply(GAST2[c(2:6)], as.numeric)

GAST2$GAST = rowMeans(GAST2[,2:6],na.rm = TRUE)
GAST2= GAST2[,c (1,7)]
GAST2= GAST2[complete.cases(GAST2),]
row.names(GAST2) = NULL

BANDA ANCHA

link10="https://docs.google.com/spreadsheets/d/e/2PACX-1vTJo2T8oxMssc3utiol3H4IZDOw4jq1sNu12vGh4LUz2aZU-BTtDvkhDaESiIwCJQ/pub?gid=508597872&single=true&output=csv"
ban=read.csv(link10,stringsAsFactors = F)

ban2=ban[,c(1,53:57)]
names(ban2)=c("Pais","2008","2009","2010","2011","2012")

ban2$`2008`= gsub("\\,", ".",ban2$`2008`)
ban2$`2009`= gsub("\\,", ".",ban2$`2009`)
ban2$`2010`= gsub("\\,", ".",ban2$`2010`)
ban2$`2011`= gsub("\\,", ".",ban2$`2011`)
ban2$`2012`= gsub("\\,", ".",ban2$`2012`)
ban2[c(2:6)] = lapply(ban2[c(2:6)], as.numeric)

ban2$ban = rowMeans(ban2[,2:6],na.rm = TRUE)
ban2= ban2[,c (1,7)]
ban2= ban2[complete.cases(ban2),]
row.names(ban2) = NULL

Cobertura de tratamiento antirretroviral

link11="https://docs.google.com/spreadsheets/d/e/2PACX-1vQ7mf0BRsmhcre-RKQseWRY_aGZrVve25Wmmm85m4OMF2Eb8_NyqGhDjrRmePcuWg/pub?gid=26033417&single=true&output=csv"
antiRetrov=read.csv(link11, stringsAsFactors = F)

antiRetrov2=antiRetrov[,c(1,53:57)]
names(antiRetrov2) = c("Pais","2008","2009","2010","2011","2012")
antiRetrov2[,c(2:6)]=lapply(antiRetrov2[,c(2:6)],as.numeric) #volver numerico en grupo
## Warning in lapply(antiRetrov2[, c(2:6)], as.numeric): NAs introduced by
## coercion

## Warning in lapply(antiRetrov2[, c(2:6)], as.numeric): NAs introduced by
## coercion

## Warning in lapply(antiRetrov2[, c(2:6)], as.numeric): NAs introduced by
## coercion

## Warning in lapply(antiRetrov2[, c(2:6)], as.numeric): NAs introduced by
## coercion

## Warning in lapply(antiRetrov2[, c(2:6)], as.numeric): NAs introduced by
## coercion
antiRetrov2$CobARet = rowMeans(antiRetrov2[,2:6], na.rm = TRUE)
antiRetrov2= antiRetrov2[,c (1,7)]
antiRetrov2 = antiRetrov2[complete.cases(antiRetrov2),]
row.names(antiRetrov2) = NULL

Esperanza de vida en mujeres

link12="https://docs.google.com/spreadsheets/d/e/2PACX-1vQoWu6HPrX8qbiqsewwImM89BxWol-bI-b_ubT6v_hxbPG9JTxXFxaxX5nUJTm-bg/pub?gid=72965045&single=true&output=csv"
EspVida=read.csv(link12, stringsAsFactors = F)

EspVida2=EspVida[,c(1,53:57)]
names(EspVida2) = c("Pais","2008","2009","2010","2011","2012")
EspVida2$`2008` =   gsub("\\,", ".", EspVida2$`2008`) 
EspVida2$`2009` =   gsub("\\,", ".", EspVida2$`2009`) 
EspVida2$`2010` =   gsub("\\,", ".", EspVida2$`2010`) 
EspVida2$`2011` =   gsub("\\,", ".", EspVida2$`2011`) 
EspVida2$`2012` =   gsub("\\,", ".", EspVida2$`2012`)
EspVida2[,c(2:6)]=lapply(EspVida2[,c(2:6)],as.numeric) #volver numerico en grupo

EspVida2$VidaM = rowMeans(EspVida2[,2:6], na.rm = TRUE)
EspVida2= EspVida2[,c (1,7)]
EspVida2 = EspVida2[complete.cases(EspVida2),]
row.names(EspVida2) = NULL

Migracion neta

link13="https://docs.google.com/spreadsheets/d/e/2PACX-1vSri2T-73zRzhVczOzNqkAKmQ_qLcWrQHzuVl7QIFUE7fJRUbtKoDCeJ1zixpCjRA/pub?gid=1968467072&single=true&output=csv"
neta=read.csv(link13, stringsAsFactors = F)

migra2=neta[,c(1,57)]
names(migra2) = c("Pais","Migracion")
migra2 = migra2[complete.cases(migra2),]
row.names(migra2) = NULL

migra2[,c(2)]=as.numeric(migra2[,c(2)]) #volver numerico 

ODA

link14="https://docs.google.com/spreadsheets/d/e/2PACX-1vQMbPO51JV-DhQLOOX9GnTSN7Z4hlKuFjX6Ft9QRS07q1i28GeqAsAAhdfXkNq-uA/pub?gid=1457611805&single=true&output=csv"
ODA=read.csv(link14, stringsAsFactors = F)

ODA2=ODA[,c(1,53:57)]
names(ODA2) = c("Pais","2008","2009","2010", "2011", "2012")

ODA2$`2008` =   gsub("\\,", ".", ODA2$`2008`) 
ODA2$`2009` =   gsub("\\,", ".", ODA2$`2009`) 
ODA2$`2010` =   gsub("\\,", ".", ODA2$`2010`) 
ODA2$`2011` =   gsub("\\,", ".", ODA2$`2011`) 
ODA2$`2012` =   gsub("\\,", ".", ODA2$`2012`) 
ODA2[,c(2:6)]=lapply(ODA2[,c(2:6)],as.numeric) #volver numerico en grupo

ODA2$ODA = rowMeans(ODA2[,2:6], na.rm = TRUE)
ODA2= ODA2[,c (1,7)]
ODA2 = ODA2[complete.cases(ODA2),]
row.names(ODA2) = NULL

PAIS AFRICANO

link15="https://docs.google.com/spreadsheets/d/e/2PACX-1vT-0H84cFoinLuU8HZaFS1Yln8HhKYcVtaKCbcKn3iShculk-vuU3QJ888lCbUd_Q/pub?gid=1165629081&single=true&output=csv"
AFRICA=read.csv(link15, stringsAsFactors = F)
names(AFRICA)=c("Pais", "Africa")

Población total de mujeres

link16="https://docs.google.com/spreadsheets/d/e/2PACX-1vTnOQNQQsmZQ1Ru-bqF5mBAlnpbxQOOH_IUuMv7XylSyOIvQ_Ij1OB64-a-pXaSgg/pub?gid=871901844&single=true&output=csv"
women=read.csv(link16, stringsAsFactors = F)

women2=women[,c(1,53:57)]
names(women2) = c("Pais","2008","2009","2010", "2011", "2012")

women2$`2008` =   gsub("\\,", ".", women2$`2008`) 
women2$`2009` =   gsub("\\,", ".", women2$`2009`) 
women2$`2010` =   gsub("\\,", ".", women2$`2010`) 
women2$`2011` =   gsub("\\,", ".", women2$`2011`) 
women2$`2012` =   gsub("\\,", ".", women2$`2012`) 
women2[,c(2:6)]=lapply(women2[,c(2:6)],as.numeric) #volver numerico en grupo

women2$Women = rowMeans(women2[,2:6], na.rm = TRUE)
women2= women2[,c (1,7)]
women2 = women2[complete.cases(women2),]
row.names(women2) = NULL

Merge

Act2FLM2=merge(DataAct2,DataFLM2,all.x=T,all.y=T)

desigualdad2=merge(DataTugurios2,DataGini2,all.x=T,all.y=T)
est2=merge(EDU2,ENER2,all.x=T,all.y=T)
estado2=merge(est2,GAST2,all.x=T,all.y=T)
densidad2=merge(estado2,ban2,all.x=T,all.y=T)
Calidad2=merge(desigualdad2,densidad2,all.x=T,all.y=T)

salud2=merge(EspVida2,antiRetrov2, all.x=T,all.y=T)

Análisis Factorial

Análisis factorial empoderamiento

Act2FLM2_x=Act2FLM2
row.names(Act2FLM2) = Act2FLM2$Pais
Act2FLM2$Pais = NULL
head(Act2FLM2)
##             PoblacionActiva      FLM
## Afghanistan        43.15240 29.90230
## Albania            46.56340 47.99584
## Algeria            14.75860 14.63667
## Angola             75.30100 80.61500
## Arab World         20.13167 20.88708
## Argentina          48.21300 48.44430
Act2FLM2[is.na(Act2FLM2$PoblacionActiva), "PoblacionActiva"]=mean(Act2FLM2$PoblacionActiva, na.rm=T)
Act2FLM2[is.na(Act2FLM2$FLM), "FLM"]=mean(Act2FLM2$FLM, na.rm=T)
Act2FLM2=as.data.frame(scale(Act2FLM2[,c(1,2)]))
head(Act2FLM2)
##             PoblacionActiva        FLM
## Afghanistan      -0.5011848 -1.4197678
## Albania          -0.2705588 -0.1427890
## Algeria          -2.4209582 -2.4971627
## Angola            1.6724597  2.1593574
## Arab World       -2.0576717 -2.0560302
## Argentina        -0.1590254 -0.1111382
library(psych)
pearson2 = cor(Act2FLM2) #sacar la correlación de los puntajes estandarizadas
pearson2
##                 PoblacionActiva      FLM
## PoblacionActiva        1.000000 0.864506
## FLM                    0.864506 1.000000
cor.plot(pearson2, 
         numbers=T, 
         upper=FALSE, 
         main = "Correlation", 
         show.legend = FALSE) #verlo en un gráfico

KMO(Act2FLM2) #nos indica que mientras más cercano a uno hay una división subyacente, a partir de 0.7. Que tan buena idea es juntarlos en un indice. ver el Overall MSA(más cercano a 1)
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = Act2FLM2)
## Overall MSA =  0.5
## MSA for each item = 
## PoblacionActiva             FLM 
##             0.5             0.5
#Prueba de esfericidad de bartlett
library(psych)
cortest.bartlett(Act2FLM2, n=nrow(Act2FLM2)) 
## R was not square, finding R from data
## $chisq
## [1] 333.6392
## 
## $p.value
## [1] 1.549413e-74
## 
## $df
## [1] 1
fa.parallel(pearson2, fm="pa", fa="fa", main = "Scree Plot",n.obs = nrow(Act2FLM2)) #cuantos indices deberia formar

## Parallel analysis suggests that the number of factors =  1  and the number of components =  NA
Act2FLM2 = fa(Act2FLM2, 
                     nfactors=1, 
                     rotate="varimax") #codigo para el analisis factorial solo cambiar la data y el numero de factores
Act2FLM2$loadings
## 
## Loadings:
##                 MR1 
## PoblacionActiva 0.93
## FLM             0.93
## 
##                  MR1
## SS loadings    1.729
## Proportion Var 0.865
fa.diagram(Act2FLM2)

#Para ver el tipo de análisis factorial:
# mientras mas grande mejor (lo que aporta)
sort(Act2FLM2$communalities)
## PoblacionActiva             FLM 
##        0.864506        0.864506
# mientras mas grande peor (lo que mantiene)
sort(Act2FLM2$uniquenesses)
## PoblacionActiva             FLM 
##        0.135494        0.135494
sort(Act2FLM2$complexity)
## PoblacionActiva             FLM 
##               1               1
Act2FLM2$scores
##                                                               MR1
## Afghanistan                                          -0.957936814
## Albania                                              -0.206127451
## Algeria                                              -2.452558785
## Angola                                                1.910842948
## Arab World                                           -2.051412705
## Argentina                                            -0.134724627
## Armenia                                              -0.003203348
## Aruba                                                 0.321716349
## Australia                                             0.583245223
## Austria                                               0.248409257
## Azerbaijan                                            0.724065533
## Bahamas, The                                          1.293475038
## Bahrain                                              -0.504468467
## Bangladesh                                           -1.208854798
## Barbados                                              0.853973567
## Belarus                                               0.410514455
## Belgium                                              -0.223791856
## Belize                                                0.176865679
## Benin                                                 1.388095882
## Bermuda                                               1.055179121
## Bhutan                                                0.972773007
## Bolivia                                               0.758604626
## Bosnia and Herzegovina                               -1.081725092
## Botswana                                              0.363650970
## Brazil                                                0.290391135
## Brunei Darussalam                                     0.439111288
## Bulgaria                                             -0.169381193
## Burkina Faso                                          0.308629824
## Burundi                                               1.713822749
## Cabo Verde                                            0.276720231
## Cambodia                                              1.913624610
## Cameroon                                              1.456609287
## Canada                                                0.811835599
## Caribbean small states                                0.322600325
## Cayman Islands                                        1.049759068
## Central African Republic                              0.505677673
## Central Europe and the Baltics                       -0.174184424
## Chad                                                  0.455223801
## Channel Islands                                      -0.027021182
## Chile                                                -0.249707952
## China                                                 0.935866021
## Colombia                                              0.344824362
## Comoros                                              -0.522685446
## Congo, Dem. Rep.                                      0.889777222
## Congo, Rep.                                           0.380742695
## Costa Rica                                           -0.264711634
## Cote d'Ivoire                                         0.359120294
## Croatia                                              -0.324163072
## Cuba                                                 -0.469537629
## Cyprus                                                0.445661568
## Czech Republic                                       -0.052299602
## Denmark                                               0.671106942
## Djibouti                                              0.026426746
## Dominican Republic                                   -0.545707012
## Early-demographic dividend                           -1.148137378
## East Asia & Pacific                                   0.702412513
## East Asia & Pacific (excluding high income)           0.799843359
## East Asia & Pacific (IDA & IBRD countries)            0.794178274
## Ecuador                                              -0.025008402
## Egypt, Arab Rep.                                     -1.923753954
## El Salvador                                          -0.246904148
## Equatorial Guinea                                     0.111581975
## Eritrea                                               0.774818825
## Estonia                                               0.333192186
## Eswatini                                             -0.438737337
## Ethiopia                                              0.784165191
## Euro area                                            -0.032651759
## Europe & Central Asia                                 0.024644777
## Europe & Central Asia (excluding high income)         0.003059226
## Europe & Central Asia (IDA & IBRD countries)         -0.019337885
## European Union                                        0.005345216
## Fiji                                                 -0.430651323
## Finland                                               0.424036791
## Fragile and conflict affected situations             -0.121270395
## France                                                0.057534593
## French Polynesia                                     -0.110637088
## Gabon                                                -0.717002018
## Gambia, The                                           0.004341844
## Georgia                                               0.371760800
## Germany                                               0.196612219
## Ghana                                                 1.229293064
## Greece                                               -0.438754594
## Greenland                                             0.749668323
## Guam                                                  0.334856760
## Guatemala                                            -0.558469088
## Guinea                                                0.427164715
## Guinea-Bissau                                         0.521484133
## Guyana                                               -0.445049081
## Haiti                                                 0.495107476
## Heavily indebted poor countries (HIPC)                0.444674059
## High income                                           0.137513064
## Honduras                                             -0.601406995
## Hong Kong SAR, China                                  0.164568363
## Hungary                                              -0.459137089
## IBRD only                                            -0.350545563
## Iceland                                               1.614808242
## IDA & IBRD total                                     -0.222378554
## IDA blend                                            -0.659863816
## IDA only                                              0.137474868
## IDA total                                            -0.008244770
## India                                                -1.727627330
## Indonesia                                             0.038596582
## Iran, Islamic Rep.                                   -2.399518052
## Iraq                                                 -2.639221453
## Ireland                                               0.368276158
## Isle of Man                                           0.262940846
## Israel                                                0.467166412
## Italy                                                -0.816413641
## Jamaica                                               0.533835201
## Japan                                                -0.125779127
## Jordan                                               -2.444445892
## Kazakhstan                                            1.085802316
## Kenya                                                 1.132218882
## Kiribati                                              0.079575052
## Korea, Dem. People’s Rep.                             0.820720957
## Korea, Rep.                                          -0.041486864
## Kosovo                                               -0.927406405
## Kuwait                                                0.342453034
## Kyrgyz Republic                                       0.147533753
## Lao PDR                                               1.826360223
## Late-demographic dividend                             0.725821087
## Latin America & Caribbean                             0.051031735
## Latin America & Caribbean (excluding high income)     0.082640191
## Latin America & the Caribbean (IDA & IBRD countries)  0.067917711
## Latvia                                                0.263889255
## Least developed countries: UN classification          0.198790933
## Lebanon                                              -1.935468052
## Lesotho                                              -0.008994052
## Liberia                                               0.385196962
## Libya                                                -1.499071019
## Liechtenstein                                         0.117515231
## Lithuania                                             0.137755199
## Low & middle income                                  -0.221585361
## Low income                                            0.461308488
## Lower middle income                                  -1.062838706
## Luxembourg                                           -0.054823107
## Macao SAR, China                                      1.063540554
## Madagascar                                            2.162356901
## Malawi                                                1.392729132
## Malaysia                                             -0.305094473
## Maldives                                             -0.218579937
## Mali                                                  0.345872300
## Malta                                                -1.055523687
## Marshall Islands                                     -0.738355520
## Mauritania                                           -1.528646123
## Mauritius                                            -0.546916305
## Mexico                                               -0.492061217
## Middle East & North Africa                           -2.099511388
## Middle East & North Africa (excluding high income)   -2.212285671
## Middle East & North Africa (IDA & IBRD countries)    -2.210458196
## Middle income                                        -0.268700119
## Moldova                                              -0.754335065
## Mongolia                                              0.264793622
## Montenegro                                           -0.515949470
## Morocco                                              -1.749565070
## Mozambique                                            1.087663848
## Myanmar                                               0.104144013
## Namibia                                               0.134322117
## Nauru                                                -0.025657774
## Nepal                                                 2.004082360
## Netherlands                                           0.609649229
## New Caledonia                                         0.657928604
## New Zealand                                           0.782031149
## Nicaragua                                             0.064029970
## Niger                                                 1.221846237
## Nigeria                                               0.196544383
## North America                                         0.566246572
## North Macedonia                                      -0.508392052
## Northern Mariana Islands                              0.582158901
## Norway                                                1.066801298
## OECD members                                          0.043796360
## Oman                                                 -1.680785687
## Other small states                                    0.005153535
## Pacific island small states                          -0.071744448
## Pakistan                                             -1.994420826
## Panama                                               -0.226029029
## Papua New Guinea                                     -0.146946725
## Paraguay                                              0.504846850
## Peru                                                  1.142832351
## Philippines                                          -0.142069509
## Poland                                               -0.178585272
## Portugal                                              0.347406419
## Post-demographic dividend                             0.198455654
## Pre-demographic dividend                              0.236305410
## Puerto Rico                                          -1.056886094
## Qatar                                                 0.067587282
## Romania                                              -0.276402251
## Russian Federation                                    0.631587290
## Rwanda                                                1.903235199
## Samoa                                                -1.808000681
## Sao Tome and Principe                                -0.303977896
## Saudi Arabia                                         -2.178148313
## Senegal                                              -0.747793201
## Serbia                                               -0.586548626
## Seychelles                                            0.418502462
## Sierra Leone                                          0.334665957
## Singapore                                             0.441575795
## Slovak Republic                                       0.018743478
## Slovenia                                              0.186890300
## Small states                                          0.018817799
## Solomon Islands                                       0.852451946
## Somalia                                              -1.113485168
## South Africa                                         -0.304471943
## South Asia                                           -1.673057853
## South Asia (IDA & IBRD)                              -1.673057853
## South Sudan                                           1.441090425
## Spain                                                 0.097710499
## Sri Lanka                                            -1.079302538
## St. Lucia                                             0.586376124
## St. Vincent and the Grenadines                        0.199225502
## Sub-Saharan Africa                                    0.360199399
## Sub-Saharan Africa (excluding high income)            0.360199399
## Sub-Saharan Africa (IDA & IBRD countries)             0.360199399
## Sudan                                                -1.714188636
## Suriname                                             -0.408659681
## Sweden                                                0.808392777
## Switzerland                                           0.729499639
## Syrian Arab Republic                                 -2.526839852
## Tajikistan                                           -1.449616001
## Tanzania                                              2.207699847
## Thailand                                              1.016285752
## Timor-Leste                                          -1.619543488
## Togo                                                  1.826017425
## Tonga                                                -0.174323234
## Trinidad and Tobago                                   0.046667065
## Tunisia                                              -1.756480858
## Turkey                                               -1.619744506
## Turkmenistan                                          0.063090399
## Uganda                                                1.396774817
## Ukraine                                               0.207602776
## United Arab Emirates                                 -0.512920396
## United Kingdom                                        0.382580295
## United States                                         0.538173274
## Upper middle income                                   0.436073738
## Uruguay                                               0.371744132
## Uzbekistan                                            0.073360587
## Vanuatu                                               0.716404137
## Venezuela, RB                                        -0.007453655
## Vietnam                                               1.465705136
## Virgin Islands (U.S.)                                 0.240124002
## West Bank and Gaza                                   -2.362713114
## World                                                -0.140505894
## Yemen, Rep.                                          -2.781120503
## Zambia                                                1.011156411
## Zimbabwe                                              1.530300799
scores2=as.data.frame(Act2FLM2$scores)
names(scores2) = c("Empoderamiento")
head(scores2)
##             Empoderamiento
## Afghanistan     -0.9579368
## Albania         -0.2061275
## Algeria         -2.4525588
## Angola           1.9108429
## Arab World      -2.0514127
## Argentina       -0.1347246
scores2$Pais=row.names(scores2)
row.names(scores2) = NULL

Análisis factorial calidad de vida

#Ponemos las variables en forma intuitiva restando con el mayor valor
Calidad2$BarriosTugurios= 100 - Calidad2$BarriosTugurios 
Calidad2$Gini= 65 - Calidad2$Gini
Calidad2_X=Calidad2
row.names(Calidad2) = Calidad2$Pais
Calidad2$Pais = NULL
head(Calidad2)
##                     BarriosTugurios Gini      EDU      ENER    GAST
## Afghanistan                      NA   NA 31.74112  48.45538      NA
## Albania                          NA 35.5 96.67697 100.00000 0.15412
## Algeria                          NA 37.4 75.13605  98.94692      NA
## Andorra                          NA   NA       NA 100.00000      NA
## Angola                         34.2 22.3       NA  33.51748      NA
## Antigua and Barbuda              NA   NA       NA  94.22346      NA
##                              ban
## Afghanistan          0.003874254
## Albania              3.739381479
## Algeria              2.385431981
## Andorra             28.845289134
## Angola               0.070203059
## Antigua and Barbuda  9.959628841
Calidad2[is.na(Calidad2$BarriosTugurios), "BarriosTugurios"]=mean(Calidad2$BarriosTugurios, na.rm=T)
Calidad2[is.na(Calidad2$Gini), "Gini"]=mean(Calidad2$Gini, na.rm=T)
Calidad2[is.na(Calidad2$EDU), "EDU"]=mean(Calidad2$EDU, na.rm=T)
Calidad2[is.na(Calidad2$ENER), "ENER"]=mean(Calidad2$ENER, na.rm=T)
Calidad2[is.na(Calidad2$GAST), "GAST"]=mean(Calidad2$GAST, na.rm=T)
Calidad2[is.na(Calidad2$ban), "ban"]=mean(Calidad2$ban, na.rm=T)
Calidad2=as.data.frame(scale(Calidad2[,c(1:6)]))
head(Calidad2)
##                     BarriosTugurios      Gini        EDU       ENER
## Afghanistan                0.000000  0.000000 -3.3708303 -1.0591265
## Albania                    0.000000  1.468706  1.0350593  0.7089823
## Algeria                    0.000000  1.788523 -0.4264896  0.6728591
## Andorra                    0.000000  0.000000  0.0000000  0.7089823
## Angola                    -1.762928 -0.753182  0.0000000 -1.5715337
## Antigua and Barbuda        0.000000  0.000000  0.0000000  0.5108327
##                          GAST         ban
## Afghanistan          0.000000 -0.83285151
## Albania             -1.122095 -0.49709541
## Algeria              0.000000 -0.61879155
## Andorra              0.000000  1.75948211
## Angola               0.000000 -0.82688972
## Antigua and Barbuda  0.000000  0.06199493
library(psych)
promedio2 = cor(Calidad2) #sacar la correlación de los puntajes estandarizadas
promedio2
##                 BarriosTugurios         Gini         EDU      ENER
## BarriosTugurios     1.000000000 -0.003586325  0.38641647 0.5086595
## Gini               -0.003586325  1.000000000  0.06969314 0.3248744
## EDU                 0.386416467  0.069693141  1.00000000 0.6184280
## ENER                0.508659451  0.324874426  0.61842801 1.0000000
## GAST                0.037442304  0.283556377 -0.01961126 0.1962350
## ban                 0.092071248  0.364626587  0.28765543 0.5218063
##                        GAST        ban
## BarriosTugurios  0.03744230 0.09207125
## Gini             0.28355638 0.36462659
## EDU             -0.01961126 0.28765543
## ENER             0.19623497 0.52180626
## GAST             1.00000000 0.56726309
## ban              0.56726309 1.00000000
cor.plot(promedio2, 
         numbers=T, 
         upper=FALSE, 
         main = "Correlation", 
         show.legend = FALSE) #verlo en un gráfico

KMO(Calidad2) #nos indica que mientras más cercano a uno hay una división subyacente, a partir de 0.7. Que tan buena idea es juntarlos en un indice. ver el Overall MSA(más cercano a 1)
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = Calidad2)
## Overall MSA =  0.62
## MSA for each item = 
## BarriosTugurios            Gini             EDU            ENER 
##            0.58            0.69            0.68            0.61 
##            GAST             ban 
##            0.56            0.61
fa.parallel(promedio2, fm="pa", fa="fa", main = "Scree Plot",n.obs = nrow(Calidad2)) #cuantos indices deberia formar

## Parallel analysis suggests that the number of factors =  2  and the number of components =  NA
Calidad2 = fa(Calidad2, 
                     nfactors=3, 
                     rotate="varimax") #codigo para el analisis factorial solo cambiar la data y el numero de factores
Calidad2$loadings
## 
## Loadings:
##                 MR3    MR1    MR2   
## BarriosTugurios  0.688 -0.107       
## Gini                    0.477  0.126
## EDU              0.616  0.222       
## ENER             0.812  0.554       
## GAST                    0.360  0.931
## ban              0.208  0.664  0.352
## 
##                  MR3   MR1   MR2
## SS loadings    1.558 1.165 1.023
## Proportion Var 0.260 0.194 0.171
## Cumulative Var 0.260 0.454 0.624
fa.diagram(Calidad2)

#Para ver el tipo de análisis factorial:
# mientras mas grande mejor (lo que aporta)
sort(Calidad2$communalities)
##            Gini             EDU BarriosTugurios             ban 
##       0.2449321       0.4355344       0.4945847       0.6070800 
##            ENER            GAST 
##       0.9664973       0.9950000
# mientras mas grande peor (lo que mantiene)
sort(Calidad2$uniquenesses)
##            GAST            ENER             ban BarriosTugurios 
##      0.00227872      0.03348006      0.39290797      0.50540898 
##             EDU            Gini 
##      0.56449554      0.75505748
sort(Calidad2$complexity)
## BarriosTugurios            Gini            GAST             EDU 
##        1.088113        1.150353        1.293427        1.294300 
##             ban            ENER 
##        1.746668        1.765751
Calidad2$scores
##                                                               MR3
## Afghanistan                                          -0.993305602
## Albania                                               0.556809873
## Algeria                                               0.299975584
## Andorra                                               0.252986939
## Angola                                               -1.438560842
## Antigua and Barbuda                                   0.366987825
## Arab World                                            0.221388549
## Argentina                                             1.449641471
## Armenia                                               0.558001662
## Aruba                                                 0.338724444
## Australia                                             0.129894542
## Austria                                               0.019625590
## Azerbaijan                                            0.736531222
## Bahamas, The                                          0.503567519
## Bahrain                                               0.524838401
## Bangladesh                                           -1.160950879
## Barbados                                              0.362390275
## Belarus                                               0.315826637
## Belgium                                              -0.091418977
## Belize                                                0.380781036
## Benin                                                -1.843074939
## Bermuda                                              -0.113291382
## Bhutan                                               -0.062651701
## Bolivia                                               0.658008875
## Bosnia and Herzegovina                                0.566287612
## Botswana                                             -0.095999955
## Brazil                                                1.466063511
## British Virgin Islands                               -0.239280527
## Brunei Darussalam                                     0.678715761
## Bulgaria                                              0.505826784
## Burkina Faso                                         -1.417071793
## Burundi                                              -1.907279196
## Cabo Verde                                            0.168104606
## Cambodia                                             -1.051328345
## Cameroon                                             -0.589921625
## Canada                                                0.039924754
## Caribbean small states                                0.438466119
## Cayman Islands                                        0.188505250
## Central African Republic                             -2.830856878
## Central Europe and the Baltics                        0.415185142
## Chad                                                 -2.749890419
## Channel Islands                                       0.522521449
## Chile                                                 0.880136616
## China                                                 1.131437774
## Colombia                                              1.874162605
## Comoros                                              -0.496698005
## Congo, Dem. Rep.                                     -1.838395977
## Congo, Rep.                                          -0.693009279
## Costa Rica                                            0.930482904
## Cote d'Ivoire                                        -0.869622784
## Croatia                                               0.398081111
## Cuba                                                  0.805285926
## Curacao                                               0.344658284
## Cyprus                                                0.354216365
## Czech Republic                                        0.040394714
## Denmark                                              -0.283597989
## Djibouti                                             -0.373915005
## Dominica                                              0.363291655
## Dominican Republic                                    1.692675587
## Early-demographic dividend                            0.486193642
## East Asia & Pacific                                   0.873495612
## East Asia & Pacific (excluding high income)           0.947711801
## East Asia & Pacific (IDA & IBRD countries)            0.968542817
## Ecuador                                               0.874883217
## Egypt, Arab Rep.                                      1.339479705
## El Salvador                                           0.627613424
## Equatorial Guinea                                    -0.222626034
## Eritrea                                              -0.987722449
## Estonia                                               0.232281711
## Eswatini                                             -0.337674563
## Ethiopia                                             -2.128535629
## Euro area                                             0.309667609
## Europe & Central Asia                                 0.442869426
## Europe & Central Asia (excluding high income)         0.645011128
## Europe & Central Asia (IDA & IBRD countries)          0.638315085
## European Union                                        0.335229949
## Faroe Islands                                         0.200402288
## Fiji                                                  0.407275596
## Finland                                              -0.209670348
## Fragile and conflict affected situations             -0.949121485
## France                                               -0.022968843
## French Polynesia                                      0.479426657
## Gabon                                                 0.311505835
## Gambia, The                                          -0.672134790
## Georgia                                               0.579831546
## Germany                                              -0.101621673
## Ghana                                                 0.001456106
## Gibraltar                                             0.205927538
## Greece                                                0.418641738
## Greenland                                             0.357443979
## Grenada                                               0.212545396
## Guam                                                  0.625084092
## Guatemala                                             0.491550070
## Guinea                                               -1.723150699
## Guinea-Bissau                                        -1.366503654
## Guyana                                                0.510562956
## Haiti                                                -1.524380661
## Heavily indebted poor countries (HIPC)               -1.764245364
## High income                                           0.187355349
## Honduras                                              0.548356424
## Hong Kong SAR, China                                  0.244013511
## Hungary                                               0.119088882
## IBRD only                                             0.882198560
## Iceland                                              -0.179831114
## IDA & IBRD total                                      0.460780493
## IDA blend                                            -0.455510273
## IDA only                                             -1.535301480
## IDA total                                            -1.142803932
## India                                                 0.318408283
## Indonesia                                             1.254892139
## Iran, Islamic Rep.                                    0.744472277
## Iraq                                                  0.312552834
## Ireland                                               0.165250064
## Isle of Man                                           0.522521449
## Israel                                                0.166680931
## Italy                                                 0.366969411
## Jamaica                                               0.396231423
## Japan                                                -0.026389200
## Jordan                                                1.343718276
## Kazakhstan                                            0.513377302
## Kenya                                                -1.438600040
## Kiribati                                             -0.136556737
## Korea, Dem. People’s Rep.                            -1.160831840
## Korea, Rep.                                          -0.162558484
## Kosovo                                               -0.187126863
## Kuwait                                                0.781079184
## Kyrgyz Republic                                       0.599987225
## Lao PDR                                              -0.310078661
## Late-demographic dividend                             1.063823481
## Latin America & Caribbean                             0.540014087
## Latin America & Caribbean (excluding high income)     0.532743402
## Latin America & the Caribbean (IDA & IBRD countries)  0.534634556
## Latvia                                                0.453619845
## Least developed countries: UN classification         -1.721510883
## Lebanon                                               0.472772342
## Lesotho                                              -1.182849504
## Liberia                                              -2.348347542
## Libya                                                 0.599629859
## Liechtenstein                                         0.078099840
## Lithuania                                             0.402500680
## Low & middle income                                   0.440360974
## Low income                                           -1.858847293
## Lower middle income                                   0.268341483
## Luxembourg                                            0.027788484
## Macao SAR, China                                      0.472851143
## Madagascar                                           -2.187618184
## Malawi                                               -2.244658042
## Malaysia                                              0.757899375
## Maldives                                              0.537408905
## Mali                                                 -2.197177804
## Malta                                                 0.147922914
## Marshall Islands                                      0.244770233
## Mauritania                                           -1.112023043
## Mauritius                                             0.574643105
## Mexico                                                0.776953126
## Micronesia, Fed. Sts.                                -0.265861925
## Middle East & North Africa                            0.478335285
## Middle East & North Africa (excluding high income)    0.505280150
## Middle East & North Africa (IDA & IBRD countries)     0.502744220
## Middle income                                         0.661117949
## Moldova                                               0.565760045
## Monaco                                                0.111440230
## Mongolia                                              0.089499832
## Montenegro                                            0.490261142
## Morocco                                               1.193238998
## Mozambique                                           -2.348241930
## Myanmar                                              -0.583797097
## Namibia                                               0.262582928
## Nauru                                                 0.498431095
## Nepal                                                -0.686578970
## Netherlands                                          -0.169116510
## New Caledonia                                         0.445320164
## New Zealand                                           0.281653410
## Nicaragua                                             0.273569873
## Niger                                                -2.995522085
## Nigeria                                              -1.089503739
## North America                                         0.137662158
## North Macedonia                                       0.565436963
## Northern Mariana Islands                              0.522521449
## Norway                                               -0.173069668
## OECD members                                          0.201783467
## Oman                                                  0.714386655
## Other small states                                   -0.305156929
## Pacific island small states                          -0.164003040
## Pakistan                                              0.086119172
## Palau                                                 0.583399471
## Panama                                                0.713531238
## Papua New Guinea                                     -1.455381739
## Paraguay                                              0.991506609
## Peru                                                  0.624417696
## Philippines                                           0.637047559
## Poland                                                0.451122157
## Portugal                                              0.377399239
## Post-demographic dividend                             0.170133707
## Pre-demographic dividend                             -1.616796100
## Puerto Rico                                           0.565351121
## Qatar                                                 0.655600754
## Romania                                               0.543585092
## Russian Federation                                    0.662906718
## Rwanda                                               -1.978360800
## Samoa                                                 0.776339110
## San Marino                                            0.361253293
## Sao Tome and Principe                                -0.581297151
## Saudi Arabia                                          0.591031499
## Senegal                                              -0.413850975
## Serbia                                                0.382385707
## Seychelles                                            0.566501802
## Sierra Leone                                         -1.765810521
## Singapore                                             0.305212636
## Sint Maarten (Dutch part)                             0.522521449
## Slovak Republic                                       0.186512553
## Slovenia                                             -0.067180853
## Small states                                         -0.148307712
## Solomon Islands                                      -1.114750783
## Somalia                                              -2.089650043
## South Africa                                          1.534396398
## South Asia                                            0.204050215
## South Asia (IDA & IBRD)                               0.204050215
## South Sudan                                          -1.991113231
## Spain                                                 0.349783728
## Sri Lanka                                             0.382798518
## St. Kitts and Nevis                                   0.249692399
## St. Lucia                                             0.344042230
## St. Martin (French part)                             -0.369993714
## St. Vincent and the Grenadines                        0.327405838
## Sub-Saharan Africa                                   -1.458099943
## Sub-Saharan Africa (excluding high income)           -1.458283881
## Sub-Saharan Africa (IDA & IBRD countries)            -1.458099943
## Sudan                                                -1.269064654
## Suriname                                              0.460643116
## Sweden                                               -0.214220543
## Switzerland                                          -0.142890217
## Syrian Arab Republic                                  0.524541704
## Tajikistan                                            0.519095524
## Tanzania                                             -2.016430913
## Thailand                                              1.257290138
## Timor-Leste                                          -0.901660775
## Togo                                                 -0.918545795
## Tonga                                                 0.536819893
## Trinidad and Tobago                                   0.656836860
## Tunisia                                               0.526463449
## Turkey                                                1.544914394
## Turkmenistan                                          0.646424274
## Turks and Caicos Islands                              0.367305383
## Tuvalu                                                0.557480813
## Uganda                                               -1.811624312
## Ukraine                                               0.399455881
## United Arab Emirates                                  0.552132395
## United Kingdom                                        0.068890053
## United States                                         0.187433949
## Upper middle income                                   1.093940651
## Uruguay                                               0.741389302
## Uzbekistan                                            0.697015720
## Vanuatu                                              -0.972011451
## Venezuela, RB                                         0.690521782
## Vietnam                                               0.957084121
## Virgin Islands (U.S.)                                 0.540144513
## West Bank and Gaza                                    0.641702032
## World                                                 0.426631333
## Yemen, Rep.                                          -0.286498349
## Zambia                                               -1.104017100
## Zimbabwe                                             -0.179454559
##                                                               MR1
## Afghanistan                                          -0.591262933
## Albania                                               0.351893454
## Algeria                                               0.481970830
## Andorra                                               1.049147223
## Angola                                               -0.623255388
## Antigua and Barbuda                                   0.311058811
## Arab World                                           -0.035970831
## Argentina                                            -0.805512605
## Armenia                                               0.330053265
## Aruba                                                 0.485919986
## Australia                                             1.013366336
## Austria                                               1.094166481
## Azerbaijan                                            0.183476762
## Bahamas, The                                          0.401944542
## Bahrain                                               0.528200811
## Bangladesh                                            0.102265670
## Barbados                                              0.785648295
## Belarus                                               0.818143544
## Belgium                                               1.393793112
## Belize                                                0.008416537
## Benin                                                -0.165646191
## Bermuda                                               2.047504685
## Bhutan                                               -0.145072210
## Bolivia                                              -0.464157411
## Bosnia and Herzegovina                                0.435114481
## Botswana                                             -1.499395505
## Brazil                                               -0.885041175
## British Virgin Islands                                0.576309326
## Brunei Darussalam                                     0.173159892
## Bulgaria                                              0.577205724
## Burkina Faso                                         -1.605882980
## Burundi                                              -1.531695708
## Cabo Verde                                           -0.247174935
## Cambodia                                             -1.136093806
## Cameroon                                             -0.785753582
## Canada                                                1.274240665
## Caribbean small states                                0.119924619
## Cayman Islands                                        1.204451958
## Central African Republic                             -0.059554902
## Central Europe and the Baltics                        0.661879235
## Chad                                                 -0.306309344
## Channel Islands                                       0.399970906
## Chile                                                 0.048725291
## China                                                -0.461290705
## Colombia                                             -1.486466659
## Comoros                                              -0.410345071
## Congo, Dem. Rep.                                     -1.122314728
## Congo, Rep.                                          -1.222841493
## Costa Rica                                           -0.094725505
## Cote d'Ivoire                                        -0.246266867
## Croatia                                               0.735442339
## Cuba                                                 -0.028397660
## Curacao                                               0.828355955
## Cyprus                                                0.897308243
## Czech Republic                                        1.130642152
## Denmark                                               1.672979461
## Djibouti                                             -0.959683348
## Dominica                                              0.354677763
## Dominican Republic                                   -1.312356635
## Early-demographic dividend                           -0.802086975
## East Asia & Pacific                                  -0.409196669
## East Asia & Pacific (excluding high income)          -0.498324967
## East Asia & Pacific (IDA & IBRD countries)           -0.481591078
## Ecuador                                              -0.205406034
## Egypt, Arab Rep.                                     -0.842202061
## El Salvador                                          -0.153723666
## Equatorial Guinea                                    -0.571657335
## Eritrea                                              -0.967437043
## Estonia                                               0.974508415
## Eswatini                                             -1.270900389
## Ethiopia                                             -0.161823873
## Euro area                                             0.905453242
## Europe & Central Asia                                 0.612116190
## Europe & Central Asia (excluding high income)         0.267326050
## Europe & Central Asia (IDA & IBRD countries)          0.289862329
## European Union                                        0.858067380
## Faroe Islands                                         1.175797834
## Fiji                                                 -0.104461302
## Finland                                               1.399515937
## Fragile and conflict affected situations             -0.889958835
## France                                                1.355778873
## French Polynesia                                      0.503765103
## Gabon                                                -0.191368078
## Gambia, The                                          -1.219220864
## Georgia                                               0.246936709
## Germany                                               1.375680703
## Ghana                                                -0.897647106
## Gibraltar                                             1.162490219
## Greece                                                0.732386188
## Greenland                                             0.797561494
## Grenada                                               0.311749365
## Guam                                                  0.152947846
## Guatemala                                            -0.463518774
## Guinea                                               -0.870845085
## Guinea-Bissau                                        -2.012624099
## Guyana                                               -0.757110632
## Haiti                                                -0.373029819
## Heavily indebted poor countries (HIPC)               -0.575008964
## High income                                           0.952911046
## Honduras                                             -0.740341903
## Hong Kong SAR, China                                  1.101716693
## Hungary                                               1.062834308
## IBRD only                                            -0.636475994
## Iceland                                               1.523542708
## IDA & IBRD total                                     -0.649845215
## IDA blend                                            -0.233201001
## IDA only                                             -0.359912470
## IDA total                                            -0.365272091
## India                                                -0.873979768
## Indonesia                                            -0.914804923
## Iran, Islamic Rep.                                    0.019493015
## Iraq                                                  0.506948224
## Ireland                                               0.987710709
## Isle of Man                                           0.399970906
## Israel                                                0.823455899
## Italy                                                 0.795310030
## Jamaica                                               0.074236337
## Japan                                                 1.154275756
## Jordan                                               -0.755865970
## Kazakhstan                                            0.424489436
## Kenya                                                -1.066756422
## Kiribati                                             -0.476055464
## Korea, Dem. People’s Rep.                            -1.103210438
## Korea, Rep.                                           1.427828848
## Kosovo                                                0.207315661
## Kuwait                                                0.051030098
## Kyrgyz Republic                                       0.224318498
## Lao PDR                                              -0.288821029
## Late-demographic dividend                            -0.428277212
## Latin America & Caribbean                             0.172030392
## Latin America & Caribbean (excluding high income)     0.151205799
## Latin America & the Caribbean (IDA & IBRD countries)  0.173620653
## Latvia                                                0.739153812
## Least developed countries: UN classification         -0.358717092
## Lebanon                                               0.425043691
## Lesotho                                              -1.638076222
## Liberia                                              -0.976738266
## Libya                                                 0.099233047
## Liechtenstein                                         1.470364393
## Lithuania                                             0.792223316
## Low & middle income                                  -0.656002152
## Low income                                           -0.430520508
## Lower middle income                                  -0.726510583
## Luxembourg                                            1.317142963
## Macao SAR, China                                      0.810382289
## Madagascar                                           -0.490309104
## Malawi                                               -0.959483179
## Malaysia                                              0.073085555
## Maldives                                              0.194440231
## Mali                                                 -0.215774851
## Malta                                                 1.216886292
## Marshall Islands                                     -0.007249052
## Mauritania                                           -1.134535147
## Mauritius                                             0.324836588
## Mexico                                                0.101304748
## Micronesia, Fed. Sts.                                -0.566532637
## Middle East & North Africa                            0.143452450
## Middle East & North Africa (excluding high income)    0.107316453
## Middle East & North Africa (IDA & IBRD countries)     0.107491049
## Middle income                                        -0.612770694
## Moldova                                               0.367645548
## Monaco                                                1.390063760
## Mongolia                                             -0.252499549
## Montenegro                                            0.516176985
## Morocco                                              -1.146194878
## Mozambique                                           -0.292991260
## Myanmar                                              -0.850289620
## Namibia                                              -2.115041881
## Nauru                                                 0.390551480
## Nepal                                                 0.172879619
## Netherlands                                           1.628090383
## New Caledonia                                         0.585910903
## New Zealand                                           0.925724425
## Nicaragua                                            -0.449471106
## Niger                                                 0.188496139
## Nigeria                                              -0.198042289
## North America                                         1.031023916
## North Macedonia                                       0.430727410
## Northern Mariana Islands                              0.399970906
## Norway                                                1.602456262
## OECD members                                          0.915899348
## Oman                                                  0.119291066
## Other small states                                   -0.401373205
## Pacific island small states                          -0.481179872
## Pakistan                                              0.283043811
## Palau                                                 0.122346885
## Panama                                               -0.369067440
## Papua New Guinea                                     -1.452655641
## Paraguay                                             -0.323851933
## Peru                                                 -0.318598192
## Philippines                                          -0.571520910
## Poland                                                0.635974870
## Portugal                                              0.721730716
## Post-demographic dividend                             0.987861711
## Pre-demographic dividend                             -0.486083186
## Puerto Rico                                           0.483801966
## Qatar                                                 0.286175874
## Romania                                               0.533231454
## Russian Federation                                    0.277190290
## Rwanda                                               -1.115834012
## Samoa                                                -0.174810412
## San Marino                                            0.788386725
## Sao Tome and Principe                                -0.481630647
## Saudi Arabia                                          0.296762788
## Senegal                                              -0.934979564
## Serbia                                                0.616504036
## Seychelles                                            0.215088989
## Sierra Leone                                         -1.160545419
## Singapore                                             0.858763293
## Sint Maarten (Dutch part)                             0.399970906
## Slovak Republic                                       0.929322301
## Slovenia                                              1.234030951
## Small states                                         -0.304312453
## Solomon Islands                                      -1.240941318
## Somalia                                              -0.461274158
## South Africa                                         -1.815412757
## South Asia                                           -0.737978021
## South Asia (IDA & IBRD)                              -0.737978021
## South Sudan                                          -1.663700128
## Spain                                                 0.823208167
## Sri Lanka                                            -0.202607236
## St. Kitts and Nevis                                   0.878014068
## St. Lucia                                             0.367348772
## St. Martin (French part)                             -0.283216548
## St. Vincent and the Grenadines                        0.327261617
## Sub-Saharan Africa                                   -0.676698974
## Sub-Saharan Africa (excluding high income)           -0.676821470
## Sub-Saharan Africa (IDA & IBRD countries)            -0.676698974
## Sudan                                                -0.923127239
## Suriname                                             -0.062619783
## Sweden                                                1.460991887
## Switzerland                                           1.494547122
## Syrian Arab Republic                                  0.016678736
## Tajikistan                                            0.275847979
## Tanzania                                             -0.915373775
## Thailand                                             -0.635154952
## Timor-Leste                                          -0.826547346
## Togo                                                 -1.229092651
## Tonga                                                -0.121803923
## Trinidad and Tobago                                   0.333699857
## Tunisia                                               0.295701521
## Turkey                                               -0.946846947
## Turkmenistan                                          0.090332510
## Turks and Caicos Islands                              0.281158730
## Tuvalu                                                0.108542052
## Uganda                                               -1.155196713
## Ukraine                                               0.521739283
## United Arab Emirates                                  0.402313943
## United Kingdom                                        1.237145144
## United States                                         0.958407737
## Upper middle income                                  -0.448402996
## Uruguay                                               0.211183429
## Uzbekistan                                            0.099719546
## Vanuatu                                              -1.114037365
## Venezuela, RB                                         0.159171344
## Vietnam                                              -0.297938653
## Virgin Islands (U.S.)                                 0.357525596
## West Bank and Gaza                                    0.227442333
## World                                                -0.474578088
## Yemen, Rep.                                          -0.608442477
## Zambia                                               -1.498676888
## Zimbabwe                                             -2.089189133
##                                                              MR2
## Afghanistan                                           0.15655800
## Albania                                              -1.29724367
## Algeria                                              -0.16886720
## Andorra                                              -0.42797285
## Angola                                                0.23195033
## Antigua and Barbuda                                  -0.11688492
## Arab World                                           -0.55597791
## Argentina                                            -0.21942395
## Armenia                                              -1.12779718
## Aruba                                                -0.17342774
## Australia                                             1.83550252
## Austria                                               2.36603925
## Azerbaijan                                           -1.14990252
## Bahamas, The                                         -0.15003091
## Bahrain                                              -0.18717855
## Bangladesh                                           -0.06542994
## Barbados                                             -0.31455997
## Belarus                                              -0.66827818
## Belgium                                               1.26984333
## Belize                                                0.00954316
## Benin                                                -0.02120005
## Bermuda                                              -1.93805257
## Bhutan                                                0.02945341
## Bolivia                                              -1.00403376
## Bosnia and Herzegovina                               -1.42218929
## Botswana                                             -0.49138536
## Brazil                                                0.69027585
## British Virgin Islands                               -0.24804995
## Brunei Darussalam                                    -0.03243604
## Bulgaria                                             -0.81362678
## Burkina Faso                                         -0.53302491
## Burundi                                              -0.69872575
## Cabo Verde                                           -1.22589946
## Cambodia                                              0.43046464
## Cameroon                                              0.29400825
## Canada                                                0.92797080
## Caribbean small states                               -0.02462369
## Cayman Islands                                       -0.49481773
## Central African Republic                             -0.08244552
## Central Europe and the Baltics                       -0.29279454
## Chad                                                  0.09563859
## Channel Islands                                      -0.14856013
## Chile                                                -0.89338200
## China                                                 1.43099561
## Colombia                                             -0.53347648
## Comoros                                               0.11777139
## Congo, Dem. Rep.                                     -0.91362596
## Congo, Rep.                                           0.45956014
## Costa Rica                                           -0.63000796
## Cote d'Ivoire                                         0.03226354
## Croatia                                              -0.45689284
## Cuba                                                 -0.63531670
## Curacao                                              -0.33294182
## Cyprus                                               -1.09492378
## Czech Republic                                        0.38485263
## Denmark                                               2.50262409
## Djibouti                                              0.36817939
## Dominica                                             -0.13516515
## Dominican Republic                                    0.53091507
## Early-demographic dividend                           -0.02262031
## East Asia & Pacific                                   2.48797077
## East Asia & Pacific (excluding high income)           1.26842256
## East Asia & Pacific (IDA & IBRD countries)            1.26209538
## Ecuador                                              -0.81585144
## Egypt, Arab Rep.                                     -0.41999279
## El Salvador                                          -1.26268229
## Equatorial Guinea                                     0.23028840
## Eritrea                                               0.35007628
## Estonia                                               0.92144121
## Eswatini                                              0.48367224
## Ethiopia                                             -1.01183672
## Euro area                                             1.35949933
## Europe & Central Asia                                 1.15125094
## Europe & Central Asia (excluding high income)        -0.15620745
## Europe & Central Asia (IDA & IBRD countries)         -0.19920842
## European Union                                        1.27119368
## Faroe Islands                                        -0.48248468
## Fiji                                                  0.05160349
## Finland                                               3.69315578
## Fragile and conflict affected situations              0.31514396
## France                                                1.42667595
## French Polynesia                                     -0.19323431
## Gabon                                                -0.50190611
## Gambia, The                                          -0.89360890
## Georgia                                              -0.08487381
## Germany                                               2.31611246
## Ghana                                                -0.52005787
## Gibraltar                                            -0.47675693
## Greece                                               -0.68975422
## Greenland                                            -0.31968755
## Grenada                                              -0.12246369
## Guam                                                 -0.04223865
## Guatemala                                            -1.18203725
## Guinea                                                0.25284920
## Guinea-Bissau                                         0.75738925
## Guyana                                                0.31196831
## Haiti                                                 0.13686521
## Heavily indebted poor countries (HIPC)                0.17734179
## High income                                           1.90825260
## Honduras                                              0.28755261
## Hong Kong SAR, China                                 -0.73849001
## Hungary                                              -0.06588613
## IBRD only                                             0.51520626
## Iceland                                               1.95584895
## IDA & IBRD total                                      0.49483531
## IDA blend                                             0.08043269
## IDA only                                              0.10154647
## IDA total                                             0.11392352
## India                                                 0.21125914
## Indonesia                                            -0.92600551
## Iran, Islamic Rep.                                   -0.85251972
## Iraq                                                 -1.56011335
## Ireland                                               0.59074763
## Isle of Man                                          -0.14856013
## Israel                                                4.70174563
## Italy                                                 0.17956914
## Jamaica                                              -0.01732078
## Japan                                                 3.18294935
## Jordan                                               -0.42651384
## Kazakhstan                                           -1.27545847
## Kenya                                                 0.19536080
## Kiribati                                              0.19344907
## Korea, Dem. People’s Rep.                             0.44011626
## Korea, Rep.                                           3.53587989
## Kosovo                                               -0.07193001
## Kuwait                                               -1.27692202
## Kyrgyz Republic                                      -1.22124127
## Lao PDR                                               0.08863294
## Late-demographic dividend                             0.76659584
## Latin America & Caribbean                            -0.37100947
## Latin America & Caribbean (excluding high income)    -0.28892178
## Latin America & the Caribbean (IDA & IBRD countries) -0.36528984
## Latvia                                               -0.76967720
## Least developed countries: UN classification          0.09643968
## Lebanon                                              -0.13258305
## Lesotho                                              -0.81867448
## Liberia                                               0.36436394
## Libya                                                -0.02075539
## Liechtenstein                                        -0.60926941
## Lithuania                                            -0.41385395
## Low & middle income                                   0.55320728
## Low income                                            0.12074292
## Lower middle income                                  -0.27971513
## Luxembourg                                            0.39533401
## Macao SAR, China                                     -1.66441548
## Madagascar                                           -1.10107094
## Malawi                                                0.31986047
## Malaysia                                              0.10374786
## Maldives                                             -0.06297874
## Mali                                                 -0.52465934
## Malta                                                -0.92119861
## Marshall Islands                                      0.03021435
## Mauritania                                            0.44084404
## Mauritius                                            -1.27187215
## Mexico                                               -0.67894120
## Micronesia, Fed. Sts.                                 0.22667426
## Middle East & North Africa                           -0.03533436
## Middle East & North Africa (excluding high income)   -0.98633168
## Middle East & North Africa (IDA & IBRD countries)    -0.98785596
## Middle income                                         0.54722805
## Moldova                                              -0.81728958
## Monaco                                               -0.57470712
## Mongolia                                             -0.88628659
## Montenegro                                           -1.11543562
## Morocco                                               0.10981329
## Mozambique                                           -0.95190692
## Myanmar                                               0.33387713
## Namibia                                              -0.41814942
## Nauru                                                -0.14546526
## Nepal                                                -1.21478258
## Netherlands                                           0.69859449
## New Caledonia                                        -0.22859077
## New Zealand                                           0.13086289
## Nicaragua                                            -1.12399715
## Niger                                                -0.15752639
## Nigeria                                               0.02669046
## North America                                         2.33146965
## North Macedonia                                      -1.24404921
## Northern Mariana Islands                             -0.14856013
## Norway                                                0.48518411
## OECD members                                          1.92565125
## Oman                                                 -1.20059757
## Other small states                                    0.15633406
## Pacific island small states                           0.19464143
## Pakistan                                             -0.96347710
## Palau                                                -0.03093112
## Panama                                               -1.07184331
## Papua New Guinea                                      0.52273006
## Paraguay                                             -1.19790149
## Peru                                                 -1.19702793
## Philippines                                          -1.01666690
## Poland                                               -0.53092223
## Portugal                                              0.61337055
## Post-demographic dividend                             2.01878162
## Pre-demographic dividend                              0.14539089
## Puerto Rico                                          -0.91138804
## Qatar                                                -0.78029968
## Romania                                              -0.86269126
## Russian Federation                                    0.19424966
## Rwanda                                                0.38914564
## Samoa                                                 0.10884222
## San Marino                                           -0.31573862
## Sao Tome and Principe                                 0.19865752
## Saudi Arabia                                         -0.67885181
## Senegal                                              -0.41506886
## Serbia                                               -0.40433079
## Seychelles                                           -0.05611129
## Sierra Leone                                          0.43382385
## Singapore                                             1.66745824
## Sint Maarten (Dutch part)                            -0.14856013
## Slovak Republic                                      -0.84956907
## Slovenia                                              1.38016227
## Small states                                          0.12366034
## Solomon Islands                                       0.47826984
## Somalia                                               0.16820031
## South Africa                                          0.49819478
## South Asia                                            0.08533137
## South Asia (IDA & IBRD)                               0.08533137
## South Sudan                                           0.54159040
## Spain                                                 0.33581297
## Sri Lanka                                            -1.14608176
## St. Kitts and Nevis                                  -0.35686248
## St. Lucia                                            -0.14109816
## St. Martin (French part)                              0.10519437
## St. Vincent and the Grenadines                       -0.12498442
## Sub-Saharan Africa                                    0.22561122
## Sub-Saharan Africa (excluding high income)            0.22565029
## Sub-Saharan Africa (IDA & IBRD countries)             0.22561122
## Sudan                                                 0.31711736
## Suriname                                              0.05595306
## Sweden                                                3.22871390
## Switzerland                                           2.59284323
## Syrian Arab Republic                                  0.01102996
## Tajikistan                                           -1.37897589
## Tanzania                                             -0.52007600
## Thailand                                             -0.74719994
## Timor-Leste                                           0.28729210
## Togo                                                 -0.64307414
## Tonga                                                 0.09109121
## Trinidad and Tobago                                  -1.48138735
## Tunisia                                              -0.47282805
## Turkey                                                0.18423974
## Turkmenistan                                         -0.01544788
## Turks and Caicos Islands                             -0.10443004
## Tuvalu                                               -0.02841669
## Uganda                                               -0.42599633
## Ukraine                                              -0.33048447
## United Arab Emirates                                 -0.83459848
## United Kingdom                                        0.65604183
## United States                                         2.49967168
## Upper middle income                                   0.59479279
## Uruguay                                              -0.93996996
## Uzbekistan                                           -1.15895170
## Vanuatu                                               0.43202009
## Venezuela, RB                                        -1.14319770
## Vietnam                                              -0.99994752
## Virgin Islands (U.S.)                                -0.13029119
## West Bank and Gaza                                   -1.00085515
## World                                                 1.94014852
## Yemen, Rep.                                           0.24340952
## Zambia                                               -0.45471833
## Zimbabwe                                              0.81150227
promedio2=as.data.frame(Calidad2$scores)
names(promedio2) = c("Densidad", "Desigualdad", "Informacion")
head(promedio2)
##                       Densidad Desigualdad Informacion
## Afghanistan         -0.9933056  -0.5912629   0.1565580
## Albania              0.5568099   0.3518935  -1.2972437
## Algeria              0.2999756   0.4819708  -0.1688672
## Andorra              0.2529869   1.0491472  -0.4279728
## Angola              -1.4385608  -0.6232554   0.2319503
## Antigua and Barbuda  0.3669878   0.3110588  -0.1168849
promedio2$Pais=row.names(promedio2)
row.names(promedio2) = NULL

Análisis factorial de salud

salud2_X=salud2
row.names(salud2) = salud2$Pais
salud2$Pais = NULL
head(salud2)
##                        VidaM CobARet
## Afghanistan         62.44780      NA
## Albania             79.21420    18.0
## Algeria             75.89040    28.8
## Angola              60.80120     9.8
## Antigua and Barbuda 77.79520      NA
## Arab World          71.90649      NA
salud2[is.na(salud2$VidaM), "VidaM"]=mean(salud2$VidaM, na.rm=T)
salud2[is.na(salud2$CobARet), "CobARet"]=mean(salud2$CobARet, na.rm=T)
salud2=as.data.frame(scale(salud2[,c(1,2)]))
head(salud2)
##                          VidaM    CobARet
## Afghanistan         -1.1656446  0.0000000
## Albania              0.7174271 -0.7262289
## Algeria              0.3441237  0.0631689
## Angola              -1.3505779 -1.3255865
## Antigua and Barbuda  0.5580561  0.0000000
## Arab World          -0.1033177  0.0000000
library(psych)
puntaje2 = cor(salud2) #sacar la correlación de los puntajes estandarizadas
puntaje2
##             VidaM   CobARet
## VidaM   1.0000000 0.3953312
## CobARet 0.3953312 1.0000000
cor.plot(puntaje2, 
         numbers=T, 
         upper=FALSE, 
         main = "Correlation", 
         show.legend = FALSE) #verlo en un gráfico

KMO(salud2) #nos indica que mientras más cercano a uno hay una división subyacente, a partir de 0.7. Que tan buena idea es juntarlos en un indice. ver el Overall MSA(más cercano a 1)
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = salud2)
## Overall MSA =  0.5
## MSA for each item = 
##   VidaM CobARet 
##     0.5     0.5
fa.parallel(puntaje2, fm="pa", fa="fa", main = "Scree Plot",n.obs = nrow(salud2)) #cuantos indices deberia formar

## Parallel analysis suggests that the number of factors =  1  and the number of components =  NA
salud2 = fa(salud2, 
                     nfactors=1, 
                     rotate="varimax") #codigo para el analisis factorial solo cambiar la data y el numero de factores
salud2$loadings
## 
## Loadings:
##         MR1  
## VidaM   0.629
## CobARet 0.629
## 
##                  MR1
## SS loadings    0.791
## Proportion Var 0.395
fa.diagram(salud2)

#Para ver el tipo de análisis factorial:
# mientras mas grande mejor (lo que aporta)
sort(salud2$communalities)
##     VidaM   CobARet 
## 0.3953312 0.3953312
# mientras mas grande peor (lo que mantiene)
sort(salud2$uniquenesses)
##     VidaM   CobARet 
## 0.6046688 0.6046688
sort(salud2$complexity)
##   VidaM CobARet 
##       1       1
salud2$scores
##                                                               MR1
## Afghanistan                                          -0.525254033
## Albania                                              -0.003966211
## Algeria                                               0.183531157
## Angola                                               -1.205913178
## Antigua and Barbuda                                   0.251467044
## Arab World                                           -0.046556236
## Argentina                                             1.113839189
## Armenia                                              -0.493835927
## Aruba                                                 0.232539168
## Australia                                             1.668689360
## Austria                                               1.766518457
## Azerbaijan                                           -0.489522683
## Bahamas, The                                          0.242197633
## Bahrain                                               0.164941789
## Bangladesh                                           -0.835551393
## Barbados                                              0.702308356
## Belarus                                               0.114545236
## Belgium                                               0.512853925
## Belize                                               -0.150894145
## Benin                                                -0.440830430
## Bermuda                                               0.531680583
## Bhutan                                               -0.249382772
## Bolivia                                              -0.873357083
## Bosnia and Herzegovina                                0.284150526
## Botswana                                              0.171549232
## Brazil                                                0.565174203
## Brunei Darussalam                                     0.284201136
## Bulgaria                                              0.091200473
## Burkina Faso                                         -0.670685296
## Burundi                                              -0.847462831
## Cabo Verde                                            0.012044930
## Cambodia                                              0.623487436
## Cameroon                                             -1.171192539
## Canada                                                0.537146387
## Caribbean small states                                0.113243573
## Cayman Islands                                        0.600914097
## Central African Republic                             -1.759328051
## Central Europe and the Baltics                        0.329657888
## Chad                                                 -1.111819538
## Channel Islands                                       0.468186163
## Chile                                                 1.696529561
## China                                                 0.202021764
## Colombia                                             -0.154708810
## Comoros                                              -1.108943528
## Congo, Dem. Rep.                                     -1.346127167
## Congo, Rep.                                          -0.932693059
## Costa Rica                                            0.804023461
## Cote d'Ivoire                                        -1.358032295
## Croatia                                               0.350904185
## Cuba                                                  0.688019445
## Curacao                                               0.370641810
## Cyprus                                                0.698208218
## Czech Republic                                        1.187016106
## Denmark                                               1.579167337
## Djibouti                                             -1.136876101
## Dominican Republic                                   -0.175246244
## Early-demographic dividend                           -0.156507262
## East Asia & Pacific                                   0.188080249
## East Asia & Pacific (excluding high income)           0.133967444
## East Asia & Pacific (IDA & IBRD countries)            0.135679689
## Ecuador                                               0.103322520
## Egypt, Arab Rep.                                     -0.686768677
## El Salvador                                           0.511151781
## Equatorial Guinea                                    -1.369142395
## Eritrea                                              -0.315059970
## Estonia                                               0.681322714
## Eswatini                                             -0.748431840
## Ethiopia                                             -0.359709550
## Euro area                                             0.553190188
## Europe & Central Asia                                 0.344983535
## Europe & Central Asia (excluding high income)         0.135216023
## Europe & Central Asia (IDA & IBRD countries)          0.159348217
## European Union                                        0.502147007
## Faroe Islands                                         0.523987970
## Fiji                                                 -0.020962785
## Finland                                               0.533097643
## Fragile and conflict affected situations             -0.539849697
## France                                                2.000510738
## French Polynesia                                      0.263299497
## Gabon                                                -0.508556573
## Gambia, The                                          -1.152878942
## Georgia                                              -0.228357151
## Germany                                               1.715893041
## Ghana                                                -1.005406067
## Greece                                                1.251217360
## Greenland                                             0.021943774
## Grenada                                               0.110854182
## Guam                                                  0.410400471
## Guatemala                                             0.181174461
## Guinea                                               -1.100175699
## Guinea-Bissau                                        -1.385799035
## Guyana                                                0.393568629
## Haiti                                                -0.628226762
## Heavily indebted poor countries (HIPC)               -0.626624262
## High income                                           0.491239739
## Honduras                                              0.181340532
## Hong Kong SAR, China                                  0.671767108
## Hungary                                               0.658155294
## IBRD only                                             0.037009168
## Iceland                                               0.561438848
## IDA & IBRD total                                     -0.094607364
## IDA blend                                            -0.619924032
## IDA only                                             -0.464057657
## IDA total                                            -0.514983179
## India                                                -0.573839043
## Indonesia                                            -0.924028440
## Iran, Islamic Rep.                                   -0.648707880
## Iraq                                                 -0.079102742
## Ireland                                               1.544109887
## Israel                                                0.535122015
## Italy                                                 1.636732956
## Jamaica                                              -0.123547729
## Japan                                                 1.687808037
## Jordan                                                0.114052689
## Kazakhstan                                           -0.551478399
## Kenya                                                -0.302403525
## Kiribati                                             -0.217782329
## Korea, Dem. People’s Rep.                             0.004493690
## Korea, Rep.                                           0.547268245
## Kosovo                                               -0.037775192
## Kuwait                                                1.236783463
## Kyrgyz Republic                                      -0.699030005
## Lao PDR                                              -0.719986319
## Late-demographic dividend                             0.209792546
## Latin America & Caribbean                             0.235081499
## Latin America & Caribbean (excluding high income)     0.218152799
## Latin America & the Caribbean (IDA & IBRD countries)  0.229846952
## Latvia                                                0.283087731
## Least developed countries: UN classification         -0.484638836
## Lebanon                                               0.562233592
## Lesotho                                              -0.844990251
## Liberia                                              -1.246536137
## Libya                                                 0.081763960
## Liechtenstein                                         0.593828796
## Lithuania                                            -0.236733382
## Low & middle income                                  -0.102124406
## Low income                                           -0.565529443
## Lower middle income                                  -0.250244406
## Luxembourg                                            1.653522694
## Macao SAR, China                                      0.644539308
## Madagascar                                           -1.277307191
## Malawi                                               -0.640374086
## Malaysia                                             -0.200674050
## Maldives                                              0.222275604
## Mali                                                 -1.082199825
## Malta                                                 0.510829554
## Mauritania                                           -0.992083276
## Mauritius                                             0.198975085
## Mexico                                                0.633065449
## Micronesia, Fed. Sts.                                -0.169045579
## Middle East & North Africa                            0.068101592
## Middle East & North Africa (excluding high income)    0.047793570
## Middle East & North Africa (IDA & IBRD countries)     0.047466511
## Middle income                                        -0.045670142
## Moldova                                              -0.489751547
## Mongolia                                             -0.746627289
## Montenegro                                            0.394644098
## Morocco                                              -0.164814912
## Mozambique                                           -1.334538185
## Myanmar                                              -0.706189861
## Namibia                                               0.116469833
## Nepal                                                -0.614896695
## Netherlands                                           1.664207073
## New Caledonia                                         0.356477122
## New Zealand                                           1.550199124
## Nicaragua                                            -0.209627773
## Niger                                                -1.043872103
## Nigeria                                              -1.595619350
## North America                                         0.424023693
## North Macedonia                                      -0.032712836
## Norway                                                2.487583484
## OECD members                                          0.473009210
## Oman                                                  0.269514318
## Other small states                                   -0.330597205
## Pacific island small states                          -0.041122400
## Pakistan                                             -1.168774803
## Panama                                                0.389814639
## Papua New Guinea                                     -0.532040252
## Paraguay                                             -0.278430351
## Peru                                                  0.155803629
## Philippines                                          -0.642988063
## Poland                                                0.392403806
## Portugal                                              1.320158854
## Post-demographic dividend                             0.493120513
## Pre-demographic dividend                             -0.735041435
## Puerto Rico                                           0.489249751
## Qatar                                                 1.091449637
## Romania                                               1.259171501
## Russian Federation                                   -0.351325370
## Rwanda                                                0.075983856
## Samoa                                                 0.182041215
## San Marino                                            0.707193614
## Sao Tome and Principe                                -0.253927487
## Saudi Arabia                                          0.120621776
## Senegal                                              -0.490444081
## Serbia                                                1.030159539
## Seychelles                                            0.281063359
## Sierra Leone                                         -1.811352162
## Singapore                                             0.330975672
## Sint Maarten (Dutch part)                             0.236527181
## Slovak Republic                                       0.685966222
## Slovenia                                              0.802286988
## Small states                                         -0.222874152
## Solomon Islands                                      -0.142222653
## Somalia                                              -1.599207394
## South Africa                                         -0.809724055
## South Asia                                           -0.241342515
## South Asia (IDA & IBRD)                              -0.241342515
## South Sudan                                          -1.794605027
## Spain                                                 1.794297141
## Sri Lanka                                            -0.452913069
## St. Lucia                                             0.219411117
## St. Martin (French part)                              0.465281189
## St. Vincent and the Grenadines                        0.081794325
## Sub-Saharan Africa                                   -0.730856374
## Sub-Saharan Africa (excluding high income)           -0.730954905
## Sub-Saharan Africa (IDA & IBRD countries)            -0.730856374
## Sudan                                                -1.177303955
## Suriname                                              0.084241723
## Sweden                                                0.540182944
## Switzerland                                           0.597877539
## Syrian Arab Republic                                  0.199977149
## Tajikistan                                           -0.798790681
## Tanzania                                             -0.796048513
## Thailand                                              0.642156574
## Timor-Leste                                          -0.207771811
## Togo                                                 -1.078055316
## Tonga                                                 0.117807899
## Trinidad and Tobago                                   0.438948077
## Tunisia                                               0.039449652
## Turkey                                                0.239573860
## Turkmenistan                                         -0.132809324
## Uganda                                               -0.923976989
## Ukraine                                              -0.484908812
## United Arab Emirates                                  0.251021682
## United Kingdom                                        0.484512721
## United States                                         0.411635338
## Upper middle income                                   0.176679969
## Uruguay                                               0.264041151
## Uzbekistan                                           -0.751807255
## Vanuatu                                               0.001912616
## Venezuela, RB                                         0.259250754
## Vietnam                                               0.140702909
## Virgin Islands (U.S.)                                 0.439976542
## West Bank and Gaza                                    0.076449984
## World                                                -0.101237568
## Yemen, Rep.                                          -0.402303815
## Zambia                                               -0.423634121
## Zimbabwe                                             -0.911656024
puntaje2=as.data.frame(salud2$scores)
names(puntaje2) = c("Salud")
head(puntaje2)
##                            Salud
## Afghanistan         -0.525254033
## Albania             -0.003966211
## Algeria              0.183531157
## Angola              -1.205913178
## Antigua and Barbuda  0.251467044
## Arab World          -0.046556236
puntaje2$Pais=row.names(puntaje2)
row.names(puntaje2) = NULL

Merge final e imputación a las variables faltantes

responsabilidad2 = merge(scores2, DataMetodos2, by= "Pais")
dendes2 = merge(responsabilidad2, promedio2, by= "Pais")
sal2 = merge(dendes2, puntaje2, by= "Pais")
movilidad2 = merge(sal2, migra2, by= "Pais")
movi2 = merge(movilidad2, ODA2, by= "Pais")
control2 = merge(movi2, women2, by= "Pais")
final2 = merge(control2, AFRICA, by= "Pais")
VIH2 = merge(final2, DataVIH2,by= "Pais")
VIH2$Metodos=scale(VIH2$Metodos)
VIH2$Migracion=scale(VIH2$Migracion)
VIH2$ODA=scale(VIH2$ODA)
VIH2$Women=scale(VIH2$Women)
VIH2=VIH2[-grep("San|high|Pacific|French|Caribbean|Early|Late|Island|Small|West|Sint|Other|OECD|North|World|Euro|Latin|Upper|High|Heavily|IBR|IDA|Least|Low|Middle|East|Central|Fragile|Post|Pre",VIH2$Pais),] #Eliminamos los casos que no son países
row.names(VIH2)=NULL

Regresión

VIH2$VIH=VIH2$VIH/100
summary(VIH2)
##      Pais           Empoderamiento         Metodos.V1     
##  Length:88          Min.   :-2.4526   Min.   :-1.7383877  
##  Class :character   1st Qu.:-0.4512   1st Qu.:-0.9363038  
##  Mode  :character   Median : 0.2362   Median : 0.2352182  
##                     Mean   : 0.1914   Mean   : 0.0160288  
##                     3rd Qu.: 1.0337   3rd Qu.: 0.7278023  
##                     Max.   : 2.2077   Max.   : 1.5920042  
##     Densidad         Desigualdad        Informacion     
##  Min.   :-2.99552   Min.   :-2.08919   Min.   :-1.4814  
##  1st Qu.:-1.20440   1st Qu.:-0.96147   1st Qu.:-0.9167  
##  Median : 0.08781   Median :-0.42991   Median :-0.4494  
##  Mean   :-0.28312   Mean   :-0.49460   Mean   :-0.3844  
##  3rd Qu.: 0.58487   3rd Qu.: 0.01119   3rd Qu.: 0.1515  
##  Max.   : 1.87416   Max.   : 0.81814   Max.   : 0.8115  
##      Salud             Migracion.V1           ODA.V1       
##  Min.   :-1.81135   Min.   :-5.464267   Min.   :-0.922033  
##  1st Qu.:-0.94754   1st Qu.:-0.065585   1st Qu.:-0.826862  
##  Median :-0.59437   Median : 0.211923   Median :-0.271479  
##  Mean   :-0.47062   Mean   : 0.002483   Mean   :-0.008051  
##  3rd Qu.: 0.07805   3rd Qu.: 0.331108   3rd Qu.: 0.436841  
##  Max.   : 1.11384   Max.   : 3.164738   Max.   : 4.243441  
##       Women.V1          Africa               VIH         
##  Min.   :-4.301060   Length:88          Min.   :0.00100  
##  1st Qu.:-0.449604   Class :character   1st Qu.:0.00100  
##  Median :-0.107809   Mode  :character   Median :0.00200  
##  Mean   : 0.000852                      Mean   :0.01207  
##  3rd Qu.: 0.475179                      3rd Qu.:0.00940  
##  Max.   : 3.155620                      Max.   :0.19240
table(VIH2$Africa)
## 
## NO SI 
## 49 39
library(betareg)
modelo2=betareg(VIH ~ Empoderamiento + Metodos + Densidad + Desigualdad + Salud + Informacion + Migracion + ODA + Women + Africa,data=VIH2)
summary(modelo2)
## 
## Call:
## betareg(formula = VIH ~ Empoderamiento + Metodos + Densidad + Desigualdad + 
##     Salud + Informacion + Migracion + ODA + Women + Africa, data = VIH2)
## 
## Standardized weighted residuals 2:
##     Min      1Q  Median      3Q     Max 
## -2.8137 -0.4102 -0.0515  0.4928  3.1127 
## 
## Coefficients (mean model with logit link):
##                Estimate Std. Error z value Pr(>|z|)    
## (Intercept)    -5.00737    0.24032 -20.836  < 2e-16 ***
## Empoderamiento -0.03791    0.10616  -0.357  0.72104    
## Metodos         0.34909    0.17049   2.048  0.04061 *  
## Densidad       -0.41825    0.16082  -2.601  0.00930 ** 
## Desigualdad    -0.57193    0.18364  -3.114  0.00184 ** 
## Salud          -0.21155    0.20413  -1.036  0.30005    
## Informacion     0.13282    0.17979   0.739  0.46007    
## Migracion       0.16478    0.10889   1.513  0.13024    
## ODA            -0.16588    0.13155  -1.261  0.20733    
## Women           0.14116    0.10789   1.308  0.19074    
## AfricaSI        0.02626    0.28660   0.092  0.92699    
## 
## Phi coefficients (precision model with identity link):
##       Estimate Std. Error z value Pr(>|z|)    
## (phi)    59.02      10.96   5.383 7.33e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
## 
## Type of estimator: ML (maximum likelihood)
## Log-likelihood: 328.3 on 12 Df
## Pseudo R-squared: 0.3601
## Number of iterations: 51 (BFGS) + 16 (Fisher scoring)
library(margins)
(modelo2M = margins(modelo2))
## Average marginal effects
## betareg(formula = VIH ~ Empoderamiento + Metodos + Densidad +     Desigualdad + Salud + Informacion + Migracion + ODA + Women +     Africa, data = VIH2)
##  Empoderamiento  Metodos  Densidad Desigualdad     Salud Informacion
##      -0.0004601 0.004237 -0.005076   -0.006941 -0.002567    0.001612
##  Migracion       ODA    Women  AfricaSI
##      0.002 -0.002013 0.001713 0.0003181
resultado = summary(modelo2M)
#salen los limites de su error 
bet=summary(modelo2M) 

library(ggplot2)
## 
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
## 
##     %+%, alpha
ggplot(bet,aes(x=factor, y=AME)) + geom_point() + geom_errorbar(aes(ymin=lower, ymax=upper))

Analísis de conglomerados

Mapa de todas las variables significativas y la dependiente

VIH2_x=VIH2
row.names(VIH2_x) = VIH2_x$Pais
VIH2_x$Pais=NULL
VIH2_x$Africa=NULL
VIH2_x$Woman=NULL
VIH2_x$ODA=NULL
head(VIH2_x) #resultado final
##            Empoderamiento    Metodos   Densidad Desigualdad Informacion
## Albania      -0.206127451  1.1081383  0.5568099   0.3518935  -1.2972437
## Algeria      -2.452558785  0.5240120  0.2999756   0.4819708  -0.1688672
## Angola        1.910842948 -1.1411839 -1.4385608  -0.6232554   0.2319503
## Argentina    -0.134724627  0.5022162  1.4496415  -0.8055126  -0.2194240
## Armenia      -0.003203348  0.4804205  0.5580017   0.3300533  -1.1277972
## Azerbaijan    0.724065533  0.4804205  0.7365312   0.1834768  -1.1499025
##                   Salud  Migracion       Women    VIH
## Albania    -0.003966211 0.13658302 -0.53518863 0.0010
## Algeria     0.183531157 0.02423413 -0.80647133 0.0010
## Angola     -1.205913178 0.54399679  0.62464746 0.0096
## Argentina   1.113839189 0.41478982  0.63572400 0.0010
## Armenia    -0.493835927 0.27834057  2.55751915 0.0010
## Azerbaijan -0.489522683 0.34716815  0.05606804 0.0010

Solo consideraremos las variables independientes, no las vairbles de control

VIH2_d = as.data.frame(scale(VIH2_x)) #Estandarizamos y eliminamos la variable no significativa y la categórica
set.seed(15) #Para que todos los grupos tengan el mismo punto de inicio, el 15 es inventado

Pedimos las distancias como un criterio de agrupamiento

#Para pedir la distancia 
VIH2_d=dist(VIH2_d[c(1:9)]) 
#Pedimos el numero de grupos:
VIH2_clus=kmeans(VIH2_d,centers = 5) #El 5 hace referencia al numero de grupos que se piden
VIH2_clus$cluster
##             Albania             Algeria              Angola 
##                   4                   2                   1 
##           Argentina             Armenia          Azerbaijan 
##                   3                   3                   4 
##          Bangladesh            Barbados             Belarus 
##                   5                   3                   3 
##              Belize               Benin             Bolivia 
##                   4                   1                   4 
##            Botswana        Burkina Faso             Burundi 
##                   5                   1                   1 
##            Cambodia            Cameroon                Chad 
##                   1                   1                   1 
##            Colombia             Comoros    Congo, Dem. Rep. 
##                   3                   1                   1 
##         Congo, Rep.          Costa Rica       Cote d'Ivoire 
##                   1                   3                   1 
##                Cuba  Dominican Republic             Ecuador 
##                   3                   2                   4 
##    Egypt, Arab Rep.         El Salvador   Equatorial Guinea 
##                   2                   3                   5 
##             Eritrea            Eswatini            Ethiopia 
##                   1                   5                   1 
##               Gabon         Gambia, The             Georgia 
##                   4                   1                   3 
##               Ghana           Guatemala              Guinea 
##                   1                   4                   1 
##       Guinea-Bissau              Guyana               Haiti 
##                   1                   4                   1 
##            Honduras               India           Indonesia 
##                   4                   5                   4 
##  Iran, Islamic Rep.          Kazakhstan               Kenya 
##                   2                   3                   1 
##     Kyrgyz Republic             Lao PDR             Lebanon 
##                   4                   1                   2 
##             Lesotho          Madagascar              Malawi 
##                   5                   1                   1 
##                Mali          Mauritania              Mexico 
##                   1                   1                   3 
##             Moldova            Mongolia             Morocco 
##                   3                   4                   2 
##          Mozambique             Myanmar               Nepal 
##                   1                   1                   4 
##           Nicaragua               Niger             Nigeria 
##                   4                   1                   1 
##            Pakistan              Panama            Paraguay 
##                   2                   4                   4 
##                Peru         Philippines              Rwanda 
##                   4                   4                   1 
##             Senegal              Serbia        Sierra Leone 
##                   1                   3                   1 
##         South Sudan               Sudan            Suriname 
##                   1                   1                   4 
##          Tajikistan            Tanzania            Thailand 
##                   2                   1                   3 
##                Togo Trinidad and Tobago             Tunisia 
##                   1                   3                   4 
##              Uganda             Ukraine             Vietnam 
##                   1                   3                   3 
##            Zimbabwe 
##                   5
#Para ver la cantidad de paises en cada grupo:
table(VIH2_clus$cluster)
## 
##  1  2  3  4  5 
## 36  8 17 20  7
#Graficamos el mapa:
library(rgdal)
## Loading required package: sp
## rgdal: version: 1.4-4, (SVN revision 833)
##  Geospatial Data Abstraction Library extensions to R successfully loaded
##  Loaded GDAL runtime: GDAL 2.1.3, released 2017/20/01
##  Path to GDAL shared files: /usr/share/gdal/2.1
##  GDAL binary built with GEOS: TRUE 
##  Loaded PROJ.4 runtime: Rel. 4.9.2, 08 September 2015, [PJ_VERSION: 492]
##  Path to PROJ.4 shared files: (autodetected)
##  Linking to sp version: 1.3-1
folderMap='MapaMundo' #Nombre del archivo que contiene al mapa
fileName='world_map.shp' 
fileToRead=file.path(folderMap,fileName)

mapamundo = readOGR(fileToRead,stringsAsFactors=FALSE)
## OGR data source with driver: ESRI Shapefile 
## Source: "/cloud/project/MapaMundo/world_map.shp", layer: "world_map"
## with 246 features
## It has 11 fields
## Integer64 fields read as strings:  POP2005
plot(mapamundo, border='grey')

#Creamos un objeto (cluster) que mezcla la informacion de los grupos con el mapa:
grupos2=as.data.frame(VIH2_clus$cluster)
grupos2
##                     VIH2_clus$cluster
## Albania                             4
## Algeria                             2
## Angola                              1
## Argentina                           3
## Armenia                             3
## Azerbaijan                          4
## Bangladesh                          5
## Barbados                            3
## Belarus                             3
## Belize                              4
## Benin                               1
## Bolivia                             4
## Botswana                            5
## Burkina Faso                        1
## Burundi                             1
## Cambodia                            1
## Cameroon                            1
## Chad                                1
## Colombia                            3
## Comoros                             1
## Congo, Dem. Rep.                    1
## Congo, Rep.                         1
## Costa Rica                          3
## Cote d'Ivoire                       1
## Cuba                                3
## Dominican Republic                  2
## Ecuador                             4
## Egypt, Arab Rep.                    2
## El Salvador                         3
## Equatorial Guinea                   5
## Eritrea                             1
## Eswatini                            5
## Ethiopia                            1
## Gabon                               4
## Gambia, The                         1
## Georgia                             3
## Ghana                               1
## Guatemala                           4
## Guinea                              1
## Guinea-Bissau                       1
## Guyana                              4
## Haiti                               1
## Honduras                            4
## India                               5
## Indonesia                           4
## Iran, Islamic Rep.                  2
## Kazakhstan                          3
## Kenya                               1
## Kyrgyz Republic                     4
## Lao PDR                             1
## Lebanon                             2
## Lesotho                             5
## Madagascar                          1
## Malawi                              1
## Mali                                1
## Mauritania                          1
## Mexico                              3
## Moldova                             3
## Mongolia                            4
## Morocco                             2
## Mozambique                          1
## Myanmar                             1
## Nepal                               4
## Nicaragua                           4
## Niger                               1
## Nigeria                             1
## Pakistan                            2
## Panama                              4
## Paraguay                            4
## Peru                                4
## Philippines                         4
## Rwanda                              1
## Senegal                             1
## Serbia                              3
## Sierra Leone                        1
## South Sudan                         1
## Sudan                               1
## Suriname                            4
## Tajikistan                          2
## Tanzania                            1
## Thailand                            3
## Togo                                1
## Trinidad and Tobago                 3
## Tunisia                             4
## Uganda                              1
## Ukraine                             3
## Vietnam                             3
## Zimbabwe                            5
names(grupos2)='cluster'
grupos2$NAME=row.names(grupos2)
head(grupos2)
##            cluster       NAME
## Albania          4    Albania
## Algeria          2    Algeria
## Angola           1     Angola
## Argentina        3  Argentina
## Armenia          3    Armenia
## Azerbaijan       4 Azerbaijan
#Creamos el objeto final:
mapamundo_VIH2=merge(mapamundo,grupos2)
library("RColorBrewer")
plot(mapamundo,col='gray',border=NA) 
plot(mapamundo,
     col=brewer.pal(n = 5, name = "Set2")[mapamundo_VIH2$cluster],
     border='gray',add=T)

#Para tener un mapa interactivo asignando colores a cada grupo:
library(leaflet)

#newMaps!
c1=mapamundo_VIH2[!is.na(mapamundo_VIH2$cluster) & mapamundo_VIH2$cluster==1,]
c2=mapamundo_VIH2[!is.na(mapamundo_VIH2$cluster) & mapamundo_VIH2$cluster==2,]
c3=mapamundo_VIH2[!is.na(mapamundo_VIH2$cluster) & mapamundo_VIH2$cluster==3,]
c4=mapamundo_VIH2[!is.na(mapamundo_VIH2$cluster) & mapamundo_VIH2$cluster==4,]
c5=mapamundo_VIH2[!is.na(mapamundo_VIH2$cluster) & mapamundo_VIH2$cluster==5,]


title="Clusters"

# base Layer
base= leaflet() %>% addProviderTiles("CartoDB.Positron") 

layer1= base %>%
        addPolygons(data=c1,color="yellow"
,fillOpacity = 1,stroke = F,
                    group = "1")
layer_12= layer1%>%addPolygons(data=c2,color="lightcoral",fillOpacity = 1,stroke = F,
                              group = "2")

layer_123= layer_12%>%addPolygons(data=c3,color="red",fillOpacity = 1,stroke = F,
                              group = "3")

layer_1234= layer_123%>%addPolygons(data=c4,color="sandybrown",fillOpacity = 1,stroke = F,
                              group = "4")

layer_12345= layer_1234%>%addPolygons(data=c5,color="powderblue",fillOpacity = 1,stroke = F,
                              group = "5")
layer_12345
#Pedimos el mapa interactivo graficado:
layer_12345%>% addLayersControl(
        overlayGroups = c("1", "2","3", "4", "5"),
        options = layersControlOptions(collapsed = TRUE)) #No quedarse solo con el mapa, preguntarse cu?les son las caracter?sticas de los grupos formados (en que se asemejan y en qu? se diferencian).

Mapa de las variables significativas

Hacemos una data aparte donde solo se encuentren las variables significativas.

VIH2_Sig=VIH2_x
VIH2_Sig=VIH2_Sig[c(2:4)]
VIH2_dS = as.data.frame(scale(VIH2_Sig)) #Estandarizamos y eliminamos la variable no significativa y la categórica
set.seed(15) #Para que todos los grupos tengan el mismo punto de inicio, el 15 es inventado

Pedimos las distancias como un criterio de agrupamiento

#Para pedir la distancia 
VIH2_dS=dist(VIH2_dS[c(1:3)]) 
#Pedimos el numero de grupos:
VIH2s_clus=kmeans(VIH2_dS,centers = 5) #El 5 hace referencia al numero de grupos que se piden
VIH2s_clus$cluster
##             Albania             Algeria              Angola 
##                   5                   5                   2 
##           Argentina             Armenia          Azerbaijan 
##                   3                   5                   5 
##          Bangladesh            Barbados             Belarus 
##                   4                   5                   5 
##              Belize               Benin             Bolivia 
##                   4                   1                   4 
##            Botswana        Burkina Faso             Burundi 
##                   3                   1                   1 
##            Cambodia            Cameroon                Chad 
##                   2                   2                   1 
##            Colombia             Comoros    Congo, Dem. Rep. 
##                   3                   2                   1 
##         Congo, Rep.          Costa Rica       Cote d'Ivoire 
##                   2                   5                   2 
##                Cuba  Dominican Republic             Ecuador 
##                   5                   3                   5 
##    Egypt, Arab Rep.         El Salvador   Equatorial Guinea 
##                   3                   5                   2 
##             Eritrea            Eswatini            Ethiopia 
##                   1                   3                   2 
##               Gabon         Gambia, The             Georgia 
##                   4                   1                   4 
##               Ghana           Guatemala              Guinea 
##                   2                   4                   1 
##       Guinea-Bissau              Guyana               Haiti 
##                   1                   4                   2 
##            Honduras               India           Indonesia 
##                   3                   4                   3 
##  Iran, Islamic Rep.          Kazakhstan               Kenya 
##                   5                   5                   2 
##     Kyrgyz Republic             Lao PDR             Lebanon 
##                   4                   4                   5 
##             Lesotho          Madagascar              Malawi 
##                   2                   2                   2 
##                Mali          Mauritania              Mexico 
##                   1                   1                   5 
##             Moldova            Mongolia             Morocco 
##                   5                   4                   3 
##          Mozambique             Myanmar               Nepal 
##                   1                   2                   4 
##           Nicaragua               Niger             Nigeria 
##                   5                   1                   2 
##            Pakistan              Panama            Paraguay 
##                   4                   4                   5 
##                Peru         Philippines              Rwanda 
##                   5                   4                   2 
##             Senegal              Serbia        Sierra Leone 
##                   2                   5                   1 
##         South Sudan               Sudan            Suriname 
##                   1                   1                   4 
##          Tajikistan            Tanzania            Thailand 
##                   4                   2                   3 
##                Togo Trinidad and Tobago             Tunisia 
##                   1                   4                   5 
##              Uganda             Ukraine             Vietnam 
##                   1                   5                   5 
##            Zimbabwe 
##                   3
#Para ver la cantidad de paises en cada grupo:
table(VIH2s_clus$cluster)
## 
##  1  2  3  4  5 
## 18 19 11 18 22
#Creamos un objeto (cluster) que mezcla la informacion de los grupos con el mapa:
grupos2s=as.data.frame(VIH2s_clus$cluster)
grupos2s
##                     VIH2s_clus$cluster
## Albania                              5
## Algeria                              5
## Angola                               2
## Argentina                            3
## Armenia                              5
## Azerbaijan                           5
## Bangladesh                           4
## Barbados                             5
## Belarus                              5
## Belize                               4
## Benin                                1
## Bolivia                              4
## Botswana                             3
## Burkina Faso                         1
## Burundi                              1
## Cambodia                             2
## Cameroon                             2
## Chad                                 1
## Colombia                             3
## Comoros                              2
## Congo, Dem. Rep.                     1
## Congo, Rep.                          2
## Costa Rica                           5
## Cote d'Ivoire                        2
## Cuba                                 5
## Dominican Republic                   3
## Ecuador                              5
## Egypt, Arab Rep.                     3
## El Salvador                          5
## Equatorial Guinea                    2
## Eritrea                              1
## Eswatini                             3
## Ethiopia                             2
## Gabon                                4
## Gambia, The                          1
## Georgia                              4
## Ghana                                2
## Guatemala                            4
## Guinea                               1
## Guinea-Bissau                        1
## Guyana                               4
## Haiti                                2
## Honduras                             3
## India                                4
## Indonesia                            3
## Iran, Islamic Rep.                   5
## Kazakhstan                           5
## Kenya                                2
## Kyrgyz Republic                      4
## Lao PDR                              4
## Lebanon                              5
## Lesotho                              2
## Madagascar                           2
## Malawi                               2
## Mali                                 1
## Mauritania                           1
## Mexico                               5
## Moldova                              5
## Mongolia                             4
## Morocco                              3
## Mozambique                           1
## Myanmar                              2
## Nepal                                4
## Nicaragua                            5
## Niger                                1
## Nigeria                              2
## Pakistan                             4
## Panama                               4
## Paraguay                             5
## Peru                                 5
## Philippines                          4
## Rwanda                               2
## Senegal                              2
## Serbia                               5
## Sierra Leone                         1
## South Sudan                          1
## Sudan                                1
## Suriname                             4
## Tajikistan                           4
## Tanzania                             2
## Thailand                             3
## Togo                                 1
## Trinidad and Tobago                  4
## Tunisia                              5
## Uganda                               1
## Ukraine                              5
## Vietnam                              5
## Zimbabwe                             3
names(grupos2s)='cluster'
grupos2s$NAME=row.names(grupos2s)
head(grupos2s)
##            cluster       NAME
## Albania          5    Albania
## Algeria          5    Algeria
## Angola           2     Angola
## Argentina        3  Argentina
## Armenia          5    Armenia
## Azerbaijan       5 Azerbaijan
#Creamos el objeto final:
mapamundo_VIH2s=merge(mapamundo,grupos2s)
library("RColorBrewer")
plot(mapamundo,col='gray',border=NA) 
plot(mapamundo,
     col=brewer.pal(n = 5, name = "Accent")[mapamundo_VIH2s$cluster],
     border='gray',add=T)

Mapa de las hipotesis

Hacemos una data aparte donde solo se encuentre la relación entre las hipotesis

Reforzamiento de las capacidades femeninas

En esta hipotesis encontraremos las varibales de Empoderamiento y acceso a metodos anticonceptivos

VIH2_H1=VIH2_x[c(1,2)]
VIH2_dH1 = as.data.frame(scale(VIH2_H1)) #Estandarizamos y eliminamos la variable no significativa y la categórica
set.seed(15) #Para que todos los grupos tengan el mismo punto de inicio, el 15 es inventado

#Para pedir la distancia 
VIH2_dH1=dist(VIH2_dH1[c(1,2)])
#Pedimos las distancias como un criterio de agrupamiento
#Pedimos el numero de grupos:
VIH2H_clus=kmeans(VIH2_dH1,centers = 5) #El 5 hace referencia al numero de grupos que se piden
VIH2H_clus$cluster
##             Albania             Algeria              Angola 
##                   5                   3                   1 
##           Argentina             Armenia          Azerbaijan 
##                   4                   4                   4 
##          Bangladesh            Barbados             Belarus 
##                   3                   4                   4 
##              Belize               Benin             Bolivia 
##                   4                   1                   4 
##            Botswana        Burkina Faso             Burundi 
##                   4                   1                   1 
##            Cambodia            Cameroon                Chad 
##                   1                   1                   1 
##            Colombia             Comoros    Congo, Dem. Rep. 
##                   5                   2                   1 
##         Congo, Rep.          Costa Rica       Cote d'Ivoire 
##                   4                   5                   1 
##                Cuba  Dominican Republic             Ecuador 
##                   5                   5                   5 
##    Egypt, Arab Rep.         El Salvador   Equatorial Guinea 
##                   3                   5                   1 
##             Eritrea            Eswatini            Ethiopia 
##                   1                   5                   1 
##               Gabon         Gambia, The             Georgia 
##                   2                   1                   4 
##               Ghana           Guatemala              Guinea 
##                   1                   4                   1 
##       Guinea-Bissau              Guyana               Haiti 
##                   1                   4                   4 
##            Honduras               India           Indonesia 
##                   5                   3                   4 
##  Iran, Islamic Rep.          Kazakhstan               Kenya 
##                   3                   4                   4 
##     Kyrgyz Republic             Lao PDR             Lebanon 
##                   4                   1                   3 
##             Lesotho          Madagascar              Malawi 
##                   4                   1                   4 
##                Mali          Mauritania              Mexico 
##                   1                   2                   5 
##             Moldova            Mongolia             Morocco 
##                   5                   4                   3 
##          Mozambique             Myanmar               Nepal 
##                   1                   4                   1 
##           Nicaragua               Niger             Nigeria 
##                   5                   1                   1 
##            Pakistan              Panama            Paraguay 
##                   2                   4                   5 
##                Peru         Philippines              Rwanda 
##                   5                   4                   1 
##             Senegal              Serbia        Sierra Leone 
##                   2                   5                   1 
##         South Sudan               Sudan            Suriname 
##                   1                   2                   4 
##          Tajikistan            Tanzania            Thailand 
##                   2                   1                   5 
##                Togo Trinidad and Tobago             Tunisia 
##                   1                   4                   3 
##              Uganda             Ukraine             Vietnam 
##                   1                   5                   5 
##            Zimbabwe 
##                   4
#Para ver la cantidad de paises en cada grupo:
table(VIH2H_clus$cluster)
## 
##  1  2  3  4  5 
## 29  7  8 26 18
#Creamos un objeto (cluster) que mezcla la informacion de los grupos con el mapa:
grupos2H=as.data.frame(VIH2H_clus$cluster)
grupos2H
##                     VIH2H_clus$cluster
## Albania                              5
## Algeria                              3
## Angola                               1
## Argentina                            4
## Armenia                              4
## Azerbaijan                           4
## Bangladesh                           3
## Barbados                             4
## Belarus                              4
## Belize                               4
## Benin                                1
## Bolivia                              4
## Botswana                             4
## Burkina Faso                         1
## Burundi                              1
## Cambodia                             1
## Cameroon                             1
## Chad                                 1
## Colombia                             5
## Comoros                              2
## Congo, Dem. Rep.                     1
## Congo, Rep.                          4
## Costa Rica                           5
## Cote d'Ivoire                        1
## Cuba                                 5
## Dominican Republic                   5
## Ecuador                              5
## Egypt, Arab Rep.                     3
## El Salvador                          5
## Equatorial Guinea                    1
## Eritrea                              1
## Eswatini                             5
## Ethiopia                             1
## Gabon                                2
## Gambia, The                          1
## Georgia                              4
## Ghana                                1
## Guatemala                            4
## Guinea                               1
## Guinea-Bissau                        1
## Guyana                               4
## Haiti                                4
## Honduras                             5
## India                                3
## Indonesia                            4
## Iran, Islamic Rep.                   3
## Kazakhstan                           4
## Kenya                                4
## Kyrgyz Republic                      4
## Lao PDR                              1
## Lebanon                              3
## Lesotho                              4
## Madagascar                           1
## Malawi                               4
## Mali                                 1
## Mauritania                           2
## Mexico                               5
## Moldova                              5
## Mongolia                             4
## Morocco                              3
## Mozambique                           1
## Myanmar                              4
## Nepal                                1
## Nicaragua                            5
## Niger                                1
## Nigeria                              1
## Pakistan                             2
## Panama                               4
## Paraguay                             5
## Peru                                 5
## Philippines                          4
## Rwanda                               1
## Senegal                              2
## Serbia                               5
## Sierra Leone                         1
## South Sudan                          1
## Sudan                                2
## Suriname                             4
## Tajikistan                           2
## Tanzania                             1
## Thailand                             5
## Togo                                 1
## Trinidad and Tobago                  4
## Tunisia                              3
## Uganda                               1
## Ukraine                              5
## Vietnam                              5
## Zimbabwe                             4
names(grupos2H)='cluster'
grupos2H$NAME=row.names(grupos2H)
head(grupos2H)
##            cluster       NAME
## Albania          5    Albania
## Algeria          3    Algeria
## Angola           1     Angola
## Argentina        4  Argentina
## Armenia          4    Armenia
## Azerbaijan       4 Azerbaijan
#Creamos el objeto final:
mapamundo_VIH2H=merge(mapamundo,grupos2H)
library("RColorBrewer")
plot(mapamundo,col='gray',border=NA) 
plot(mapamundo,
     col=brewer.pal(n = 5, name = "PiYG")[mapamundo_VIH2H$cluster],
     border='gray',add=T)

Calidad de vida

En esta hipotesis encontraremos las varibales de Densidad Estatal, Salud y Desigualdad.

VIH2_H2=VIH2_x[c(3,4,6)]
VIH2_dH2 = as.data.frame(scale(VIH2_H2)) #Estandarizamos y eliminamos la variable no significativa y la categórica
set.seed(15) #Para que todos los grupos tengan el mismo punto de inicio, el 15 es inventado

#Para pedir la distancia 
VIH2_dH2=dist(VIH2_dH2[c(1,2,3)])
#Pedimos las distancias como un criterio de agrupamiento
#Pedimos el numero de grupos:
VIH2H2_clus=kmeans(VIH2_dH2,centers = 5) #El 5 hace referencia al numero de grupos que se piden
VIH2H2_clus$cluster
##             Albania             Algeria              Angola 
##                   4                   5                   1 
##           Argentina             Armenia          Azerbaijan 
##                   5                   4                   4 
##          Bangladesh            Barbados             Belarus 
##                   2                   5                   5 
##              Belize               Benin             Bolivia 
##                   4                   2                   2 
##            Botswana        Burkina Faso             Burundi 
##                   3                   1                   1 
##            Cambodia            Cameroon                Chad 
##                   3                   2                   1 
##            Colombia             Comoros    Congo, Dem. Rep. 
##                   3                   2                   1 
##         Congo, Rep.          Costa Rica       Cote d'Ivoire 
##                   2                   5                   2 
##                Cuba  Dominican Republic             Ecuador 
##                   5                   3                   4 
##    Egypt, Arab Rep.         El Salvador   Equatorial Guinea 
##                   3                   5                   2 
##             Eritrea            Eswatini            Ethiopia 
##                   2                   2                   2 
##               Gabon         Gambia, The             Georgia 
##                   4                   1                   4 
##               Ghana           Guatemala              Guinea 
##                   2                   4                   1 
##       Guinea-Bissau              Guyana               Haiti 
##                   1                   3                   2 
##            Honduras               India           Indonesia 
##                   3                   2                   3 
##  Iran, Islamic Rep.          Kazakhstan               Kenya 
##                   4                   4                   2 
##     Kyrgyz Republic             Lao PDR             Lebanon 
##                   4                   2                   5 
##             Lesotho          Madagascar              Malawi 
##                   1                   1                   1 
##                Mali          Mauritania              Mexico 
##                   1                   1                   5 
##             Moldova            Mongolia             Morocco 
##                   4                   2                   3 
##          Mozambique             Myanmar               Nepal 
##                   1                   2                   2 
##           Nicaragua               Niger             Nigeria 
##                   4                   1                   1 
##            Pakistan              Panama            Paraguay 
##                   2                   4                   4 
##                Peru         Philippines              Rwanda 
##                   4                   2                   1 
##             Senegal              Serbia        Sierra Leone 
##                   2                   5                   1 
##         South Sudan               Sudan            Suriname 
##                   1                   1                   4 
##          Tajikistan            Tanzania            Thailand 
##                   4                   1                   5 
##                Togo Trinidad and Tobago             Tunisia 
##                   1                   5                   4 
##              Uganda             Ukraine             Vietnam 
##                   1                   4                   4 
##            Zimbabwe 
##                   1
#Para ver la cantidad de paises en cada grupo:
table(VIH2H2_clus$cluster)
## 
##  1  2  3  4  5 
## 24 22  9 21 12
#Creamos un objeto (cluster) que mezcla la informacion de los grupos con el mapa:
grupos2H2=as.data.frame(VIH2H2_clus$cluster)
grupos2H2
##                     VIH2H2_clus$cluster
## Albania                               4
## Algeria                               5
## Angola                                1
## Argentina                             5
## Armenia                               4
## Azerbaijan                            4
## Bangladesh                            2
## Barbados                              5
## Belarus                               5
## Belize                                4
## Benin                                 2
## Bolivia                               2
## Botswana                              3
## Burkina Faso                          1
## Burundi                               1
## Cambodia                              3
## Cameroon                              2
## Chad                                  1
## Colombia                              3
## Comoros                               2
## Congo, Dem. Rep.                      1
## Congo, Rep.                           2
## Costa Rica                            5
## Cote d'Ivoire                         2
## Cuba                                  5
## Dominican Republic                    3
## Ecuador                               4
## Egypt, Arab Rep.                      3
## El Salvador                           5
## Equatorial Guinea                     2
## Eritrea                               2
## Eswatini                              2
## Ethiopia                              2
## Gabon                                 4
## Gambia, The                           1
## Georgia                               4
## Ghana                                 2
## Guatemala                             4
## Guinea                                1
## Guinea-Bissau                         1
## Guyana                                3
## Haiti                                 2
## Honduras                              3
## India                                 2
## Indonesia                             3
## Iran, Islamic Rep.                    4
## Kazakhstan                            4
## Kenya                                 2
## Kyrgyz Republic                       4
## Lao PDR                               2
## Lebanon                               5
## Lesotho                               1
## Madagascar                            1
## Malawi                                1
## Mali                                  1
## Mauritania                            1
## Mexico                                5
## Moldova                               4
## Mongolia                              2
## Morocco                               3
## Mozambique                            1
## Myanmar                               2
## Nepal                                 2
## Nicaragua                             4
## Niger                                 1
## Nigeria                               1
## Pakistan                              2
## Panama                                4
## Paraguay                              4
## Peru                                  4
## Philippines                           2
## Rwanda                                1
## Senegal                               2
## Serbia                                5
## Sierra Leone                          1
## South Sudan                           1
## Sudan                                 1
## Suriname                              4
## Tajikistan                            4
## Tanzania                              1
## Thailand                              5
## Togo                                  1
## Trinidad and Tobago                   5
## Tunisia                               4
## Uganda                                1
## Ukraine                               4
## Vietnam                               4
## Zimbabwe                              1
names(grupos2H2)='cluster'
grupos2H2$NAME=row.names(grupos2H2)
head(grupos2H2)
##            cluster       NAME
## Albania          4    Albania
## Algeria          5    Algeria
## Angola           1     Angola
## Argentina        5  Argentina
## Armenia          4    Armenia
## Azerbaijan       4 Azerbaijan
#Creamos el objeto final:
mapamundo_VIH2H2=merge(mapamundo,grupos2H2)
library("RColorBrewer")
plot(mapamundo,col='gray',border=NA) 
plot(mapamundo,
     col=brewer.pal(n = 5, name = "BrBG")[mapamundo_VIH2H2$cluster],
     border='gray',add=T)

Movilidazación para el desarrollo en la población

En este analisis de conglomerados pondremos los componentes la hipoteisis tres que son el indice de Desarrollo tecnológico y migración

VIH2_H3=VIH2_x[c(5,7)]
VIH2_dH3 = as.data.frame(scale(VIH2_H3)) #Estandarizamos y eliminamos la variable no significativa y la categórica
set.seed(15) #Para que todos los grupos tengan el mismo punto de inicio, el 15 es inventado

#Para pedir la distancia 
VIH2_dH3=dist(VIH2_dH3[c(1,2)])
#Pedimos las distancias como un criterio de agrupamiento
#Pedimos el numero de grupos:
VIH2H3_clus=kmeans(VIH2_dH3,centers = 5) #El 5 hace referencia al numero de grupos que se piden
VIH2H3_clus$cluster
##             Albania             Algeria              Angola 
##                   5                   1                   2 
##           Argentina             Armenia          Azerbaijan 
##                   1                   5                   5 
##          Bangladesh            Barbados             Belarus 
##                   4                   1                   1 
##              Belize               Benin             Bolivia 
##                   2                   2                   5 
##            Botswana        Burkina Faso             Burundi 
##                   1                   1                   1 
##            Cambodia            Cameroon                Chad 
##                   2                   2                   2 
##            Colombia             Comoros    Congo, Dem. Rep. 
##                   1                   2                   5 
##         Congo, Rep.          Costa Rica       Cote d'Ivoire 
##                   2                   1                   2 
##                Cuba  Dominican Republic             Ecuador 
##                   1                   2                   5 
##    Egypt, Arab Rep.         El Salvador   Equatorial Guinea 
##                   1                   5                   2 
##             Eritrea            Eswatini            Ethiopia 
##                   2                   2                   5 
##               Gabon         Gambia, The             Georgia 
##                   1                   5                   2 
##               Ghana           Guatemala              Guinea 
##                   1                   5                   2 
##       Guinea-Bissau              Guyana               Haiti 
##                   2                   2                   2 
##            Honduras               India           Indonesia 
##                   2                   4                   3 
##  Iran, Islamic Rep.          Kazakhstan               Kenya 
##                   5                   5                   2 
##     Kyrgyz Republic             Lao PDR             Lebanon 
##                   5                   2                   3 
##             Lesotho          Madagascar              Malawi 
##                   5                   5                   2 
##                Mali          Mauritania              Mexico 
##                   1                   2                   1 
##             Moldova            Mongolia             Morocco 
##                   5                   5                   2 
##          Mozambique             Myanmar               Nepal 
##                   5                   2                   5 
##           Nicaragua               Niger             Nigeria 
##                   5                   1                   2 
##            Pakistan              Panama            Paraguay 
##                   3                   5                   5 
##                Peru         Philippines              Rwanda 
##                   5                   5                   2 
##             Senegal              Serbia        Sierra Leone 
##                   1                   1                   2 
##         South Sudan               Sudan            Suriname 
##                   2                   2                   2 
##          Tajikistan            Tanzania            Thailand 
##                   5                   1                   1 
##                Togo Trinidad and Tobago             Tunisia 
##                   1                   5                   1 
##              Uganda             Ukraine             Vietnam 
##                   1                   1                   5 
##            Zimbabwe 
##                   2
#Para ver la cantidad de paises en cada grupo:
table(VIH2H3_clus$cluster)
## 
##  1  2  3  4  5 
## 24 32  3  2 27
#Creamos un objeto (cluster) que mezcla la informacion de los grupos con el mapa:
grupos2H3=as.data.frame(VIH2H3_clus$cluster)
grupos2H3
##                     VIH2H3_clus$cluster
## Albania                               5
## Algeria                               1
## Angola                                2
## Argentina                             1
## Armenia                               5
## Azerbaijan                            5
## Bangladesh                            4
## Barbados                              1
## Belarus                               1
## Belize                                2
## Benin                                 2
## Bolivia                               5
## Botswana                              1
## Burkina Faso                          1
## Burundi                               1
## Cambodia                              2
## Cameroon                              2
## Chad                                  2
## Colombia                              1
## Comoros                               2
## Congo, Dem. Rep.                      5
## Congo, Rep.                           2
## Costa Rica                            1
## Cote d'Ivoire                         2
## Cuba                                  1
## Dominican Republic                    2
## Ecuador                               5
## Egypt, Arab Rep.                      1
## El Salvador                           5
## Equatorial Guinea                     2
## Eritrea                               2
## Eswatini                              2
## Ethiopia                              5
## Gabon                                 1
## Gambia, The                           5
## Georgia                               2
## Ghana                                 1
## Guatemala                             5
## Guinea                                2
## Guinea-Bissau                         2
## Guyana                                2
## Haiti                                 2
## Honduras                              2
## India                                 4
## Indonesia                             3
## Iran, Islamic Rep.                    5
## Kazakhstan                            5
## Kenya                                 2
## Kyrgyz Republic                       5
## Lao PDR                               2
## Lebanon                               3
## Lesotho                               5
## Madagascar                            5
## Malawi                                2
## Mali                                  1
## Mauritania                            2
## Mexico                                1
## Moldova                               5
## Mongolia                              5
## Morocco                               2
## Mozambique                            5
## Myanmar                               2
## Nepal                                 5
## Nicaragua                             5
## Niger                                 1
## Nigeria                               2
## Pakistan                              3
## Panama                                5
## Paraguay                              5
## Peru                                  5
## Philippines                           5
## Rwanda                                2
## Senegal                               1
## Serbia                                1
## Sierra Leone                          2
## South Sudan                           2
## Sudan                                 2
## Suriname                              2
## Tajikistan                            5
## Tanzania                              1
## Thailand                              1
## Togo                                  1
## Trinidad and Tobago                   5
## Tunisia                               1
## Uganda                                1
## Ukraine                               1
## Vietnam                               5
## Zimbabwe                              2
names(grupos2H3)='cluster'
grupos2H3$NAME=row.names(grupos2H3)
head(grupos2H3)
##            cluster       NAME
## Albania          5    Albania
## Algeria          1    Algeria
## Angola           2     Angola
## Argentina        1  Argentina
## Armenia          5    Armenia
## Azerbaijan       5 Azerbaijan
#Creamos el objeto final:
mapamundo_VIH2H3=merge(mapamundo,grupos2H3)
library("RColorBrewer")
plot(mapamundo,col='gray',border=NA) 
plot(mapamundo,
     col=brewer.pal(n = 5, name = "Greens")[mapamundo_VIH2H$cluster],
     border='gray',add=T)