Prevalencia del VIH en mujeres a nivel mundial

Limpieza de datas

Data Prevalencia VIH (2008-2012)

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

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

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

DataVIH1$VIH = rowMeans(DataVIH1[,2:6])
DataVIH1 = DataVIH1[,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)
DataAct1 = DataAct[,c(1,48:52)]
names(DataAct1) = c("Pais","2003","2004","2005", "2006", "2007")

DataAct1$`2003` =   gsub("\\,", ".", DataAct1$`2003`) 
DataAct1$`2004` =   gsub("\\,", ".", DataAct1$`2004`) 
DataAct1$`2005` =   gsub("\\,", ".", DataAct1$`2005`) 
DataAct1$`2006` =   gsub("\\,", ".", DataAct1$`2006`) 
DataAct1$`2007` =   gsub("\\,", ".", DataAct1$`2007`) 
DataAct1[,c(2:6)]=lapply(DataAct1[,c(2:6)],as.numeric) #volver numerico en grupo

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

DataAct1$PoblacionActiva = rowMeans(DataAct1[,2:6])
DataAct1= DataAct1[,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)
DataFLM1 = DataFLM[,c(1,48:52)]
names(DataFLM1) = c("Pais","2003","2004","2005", "2006", "2007")

DataFLM1$`2003` =   gsub("\\,", ".", DataFLM1$`2003`) 
DataFLM1$`2004` =   gsub("\\,", ".", DataFLM1$`2004`) 
DataFLM1$`2005` =   gsub("\\,", ".", DataFLM1$`2005`) 
DataFLM1$`2006` =   gsub("\\,", ".", DataFLM1$`2006`) 
DataFLM1$`2007` =   gsub("\\,", ".", DataFLM1$`2007`)
DataFLM1[,c(2:6)]=lapply(DataFLM1[,c(2:6)],as.numeric)

DataFLM1$FLM = rowMeans(DataFLM1[,2:6],na.rm = TRUE)
DataFLM1= DataFLM1[,c (1,7)]
DataFLM1 = DataFLM1[complete.cases(DataFLM1),]
row.names(DataFLM1) = 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)
DataMetodos1 = DataMetodos[,c(1,48:52)]
names(DataMetodos1) = c("Pais","2003","2004","2005", "2006", "2007")

DataMetodos1$`2003` =   gsub("\\,", ".", DataMetodos1$`2003`) 
DataMetodos1$`2004` =   gsub("\\,", ".", DataMetodos1$`2004`) 
DataMetodos1$`2005` =   gsub("\\,", ".", DataMetodos1$`2005`) 
DataMetodos1$`2006` =   gsub("\\,", ".", DataMetodos1$`2006`) 
DataMetodos1$`2007` =   gsub("\\,", ".", DataMetodos1$`2007`)
DataMetodos1[,c(2:6)]=lapply(DataMetodos1[,c(2:6)],as.numeric)

DataMetodos1$Metodos = rowMeans(DataMetodos1[,2:6],na.rm = TRUE)
DataMetodos1= DataMetodos1[,c (1,7)]
DataMetodos1 = DataMetodos1[complete.cases(DataMetodos1),]
row.names(DataMetodos1) = 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)
DataTugurios1 = DataTugurios[,c(1,48:52)]
names(DataTugurios1) = c("Pais","2003","2004","2005", "2006", "2007")

DataTugurios1$`2003` =   gsub("\\,", ".", DataTugurios1$`2003`) 
DataTugurios1$`2004` =   gsub("\\,", ".", DataTugurios1$`2004`) 
DataTugurios1$`2005` =   gsub("\\,", ".", DataTugurios1$`2005`) 
DataTugurios1$`2006` =   gsub("\\,", ".", DataTugurios1$`2006`) 
DataTugurios1$`2007` =   gsub("\\,", ".", DataTugurios1$`2007`)
DataTugurios1[,c(2:6)]=lapply(DataTugurios1[,c(2:6)],as.numeric)

DataTugurios1$BarriosTugurios = rowMeans(DataTugurios1[,2:6],na.rm = TRUE)
DataTugurios1= DataTugurios1[,c (1,7)]
DataTugurios1 = DataTugurios1[complete.cases(DataTugurios1),]
row.names(DataTugurios1) = 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)
DataGini1 = DataGini[,c(1,48:52)]
names(DataGini1) = c("Pais","2003","2004","2005", "2006", "2007")

DataGini1$`2003` =   gsub("\\,", ".", DataGini1$`2003`) 
DataGini1$`2004` =   gsub("\\,", ".", DataGini1$`2004`) 
DataGini1$`2005` =   gsub("\\,", ".", DataGini1$`2005`) 
DataGini1$`2006` =   gsub("\\,", ".", DataGini1$`2006`) 
DataGini1$`2007` =   gsub("\\,", ".", DataGini1$`2007`)
DataGini1[,c(2:6)]=lapply(DataGini1[,c(2:6)],as.numeric)

DataGini1$Gini = rowMeans(DataGini1[,2:6],na.rm = TRUE)
DataGini1= DataGini1[,c (1,7)]
DataGini1= DataGini1[complete.cases(DataGini1),]
row.names(DataGini1) = 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)

EDU1=EDU[,c(1,48:52)]
names(EDU1)=c("Pais","2003","2004","2005","2006","2007")

EDU1$`2003`= gsub("\\,", ".",EDU1$`2003`)
EDU1$`2004`= gsub("\\,", ".",EDU1$`2004`)
EDU1$`2005`= gsub("\\,", ".",EDU1$`2005`)
EDU1$`2006`= gsub("\\,", ".",EDU1$`2006`)
EDU1$`2007`= gsub("\\,", ".",EDU1$`2007`)
EDU1[c(2:6)] = lapply(EDU1[c(2:6)], as.numeric)

EDU1$EDU = rowMeans(EDU1[,2:6],na.rm = TRUE)
EDU1= EDU1[,c (1,7)]
EDU1= EDU1[complete.cases(EDU1),]
row.names(EDU1) = 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)

ENER1=ENER[,c(1,48:52)]
names(ENER1)=c("Pais","2003","2004","2005","2006","2007") 

ENER1$`2003`= gsub("\\,", ".",ENER1$`2003`)
ENER1$`2004`= gsub("\\,", ".",ENER1$`2004`)
ENER1$`2005`= gsub("\\,", ".",ENER1$`2005`)
ENER1$`2006`= gsub("\\,", ".",ENER1$`2006`)
ENER1$`2007`= gsub("\\,", ".",ENER1$`2007`)
ENER1[c(2:6)] = lapply(ENER1[c(2:6)], as.numeric)

ENER1$ENER = rowMeans(ENER1[,2:6],na.rm = TRUE)
ENER1= ENER1[,c (1,7)]
ENER1= ENER1[complete.cases(ENER1),]
row.names(ENER1) = 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)

GAST1=GAST[,c(1,48:52)]
names(GAST1)=c("Pais","2003","2004","2005","2006","2007") 

GAST1$`2003`= gsub("\\,", ".",GAST1$`2003`)
GAST1$`2004`= gsub("\\,", ".",GAST1$`2004`)
GAST1$`2005`= gsub("\\,", ".",GAST1$`2005`)
GAST1$`2006`= gsub("\\,", ".",GAST1$`2006`)
GAST1$`2007`= gsub("\\,", ".",GAST1$`2007`)
GAST1[c(2:6)] = lapply(GAST1[c(2:6)], as.numeric)

GAST1$GAST = rowMeans(GAST1[,2:6],na.rm = TRUE)
GAST1= GAST1[,c (1,7)]
GAST1= GAST1[complete.cases(GAST1),]
row.names(GAST1) = 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)

ban1=ban[,c(1,48:52)]
names(ban1)=c("Pais","2003","2004","2005","2006","2007") 

ban1$`2003`= gsub("\\,", ".",ban1$`2003`)
ban1$`2004`= gsub("\\,", ".",ban1$`2004`)
ban1$`2005`= gsub("\\,", ".",ban1$`2005`)
ban1$`2006`= gsub("\\,", ".",ban1$`2006`)
ban1$`2007`= gsub("\\,", ".",ban1$`2007`)
ban1[c(2:6)] = lapply(ban1[c(2:6)], as.numeric)

ban1$ban = rowMeans(ban1[,2:6],na.rm = TRUE)
ban1= ban1[,c (1,7)]
ban1= ban1[complete.cases(ban1),]
row.names(ban1) = 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)

antiRetrov1=antiRetrov[,c(1,48:52)]
names(antiRetrov1) = c("Pais","2003","2004","2005", "2006", "2007")
antiRetrov1[,c(2:6)]=lapply(antiRetrov1[,c(2:6)],as.numeric) #volver numerico en grupo
## Warning in lapply(antiRetrov1[, c(2:6)], as.numeric): NAs introduced by
## coercion

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

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

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

## Warning in lapply(antiRetrov1[, c(2:6)], as.numeric): NAs introduced by
## coercion
antiRetrov1$CobARet = rowMeans(antiRetrov1[,2:6], na.rm = TRUE)
antiRetrov1= antiRetrov1[,c (1,7)]
antiRetrov1 = antiRetrov1[complete.cases(antiRetrov1),]
row.names(antiRetrov1) = 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)

EspVida1=EspVida[,c(1,48:52)]
names(EspVida1) = c("Pais","2003","2004","2005", "2006", "2007")
EspVida1$`2003` =   gsub("\\,", ".", EspVida1$`2003`) 
EspVida1$`2004` =   gsub("\\,", ".", EspVida1$`2004`) 
EspVida1$`2005` =   gsub("\\,", ".", EspVida1$`2005`) 
EspVida1$`2006` =   gsub("\\,", ".", EspVida1$`2006`) 
EspVida1$`2007` =   gsub("\\,", ".", EspVida1$`2007`)
EspVida1[,c(2:6)]=lapply(EspVida1[,c(2:6)],as.numeric) #volver numerico en grupo

EspVida1$VidaM = rowMeans(EspVida1[,2:6], na.rm = TRUE)
EspVida1= EspVida1[,c (1,7)]
EspVida1 = EspVida1[complete.cases(EspVida1),]
row.names(EspVida1) = 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)

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

migra1[,c(2)]=as.numeric(migra1[,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)

ODA1=ODA[,c(1,48:52)]
names(ODA1) = c("Pais","2003","2004","2005", "2006", "2007")

ODA1$`2003` =   gsub("\\,", ".", ODA1$`2003`) 
ODA1$`2004` =   gsub("\\,", ".", ODA1$`2004`) 
ODA1$`2005` =   gsub("\\,", ".", ODA1$`2005`) 
ODA1$`2006` =   gsub("\\,", ".", ODA1$`2006`) 
ODA1$`2007` =   gsub("\\,", ".", ODA1$`2007`) 
ODA1[,c(2:6)]=lapply(ODA1[,c(2:6)],as.numeric) #volver numerico en grupo

ODA1$ODA = rowMeans(ODA1[,2:6], na.rm = TRUE)
ODA1= ODA1[,c (1,7)]
ODA1 = ODA1[complete.cases(ODA1),]
row.names(ODA1) = 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)

women1=women[,c(1,48:52)]
names(women1) = c("Pais","2003","2004","2005", "2006", "2007")

women1$`2003` =   gsub("\\,", ".", women1$`2003`) 
women1$`2004` =   gsub("\\,", ".", women1$`2004`) 
women1$`2005` =   gsub("\\,", ".", women1$`2005`) 
women1$`2006` =   gsub("\\,", ".", women1$`2006`) 
women1$`2007` =   gsub("\\,", ".", women1$`2007`) 
women1[,c(2:6)]=lapply(women1[,c(2:6)],as.numeric) #volver numerico en grupo

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

Merge

Act1FLM1=merge(DataAct1,DataFLM1,all.x=T,all.y=T)

desigualdad1=merge(DataTugurios1,DataGini1,all.x=T,all.y=T)
est1=merge(EDU1,ENER1,all.x=T,all.y=T)
estado1=merge(est1,GAST1,all.x=T,all.y=T)
densidad1=merge(estado1,ban1,all.x=T,all.y=T)
Calidad1=merge(desigualdad1,densidad1,all.x=T,all.y=T)

salud1=merge(EspVida1,antiRetrov1, all.x=T,all.y=T)

Análisis Factorial

Análisis factorial empoderamiento

Act1FLM1_x=Act1FLM1
row.names(Act1FLM1) = Act1FLM1$Pais
Act1FLM1$Pais = NULL
head(Act1FLM1)
##             PoblacionActiva      FLM
## Afghanistan        43.55220       NA
## Albania            48.17600 29.15748
## Algeria            12.87380       NA
## Angola             75.08880 62.67960
## Arab World         19.62438 20.61435
## Argentina          49.57260 49.55246
Act1FLM1[is.na(Act1FLM1$PoblacionActiva), "PoblacionActiva"]=mean(Act1FLM1$PoblacionActiva, na.rm=T)
Act1FLM1[is.na(Act1FLM1$FLM), "FLM"]=mean(Act1FLM1$FLM, na.rm=T)
Act1FLM1=as.data.frame(scale(Act1FLM1[,c(1,2)]))
head(Act1FLM1)
##             PoblacionActiva         FLM
## Afghanistan     -0.43930039  0.00000000
## Albania         -0.13370714 -1.37188100
## Algeria         -2.46687804  0.00000000
## Angola           1.64499686  0.96623135
## Arab World      -2.02072269 -1.96774987
## Argentina       -0.04140391  0.05063512
library(psych)
pearson1 = cor(Act1FLM1) #sacar la correlación de los puntajes estandarizadas
pearson1
##                 PoblacionActiva       FLM
## PoblacionActiva       1.0000000 0.7868555
## FLM                   0.7868555 1.0000000
cor.plot(pearson1, 
         numbers=T, 
         upper=FALSE, 
         main = "Correlation", 
         show.legend = FALSE) #verlo en un gráfico

KMO(Act1FLM1) #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 = Act1FLM1)
## Overall MSA =  0.5
## MSA for each item = 
## PoblacionActiva             FLM 
##             0.5             0.5
#Prueba de esfericidad de bartlett
library(psych)
cortest.bartlett(Act1FLM1, n=nrow(Act1FLM1)) 
## R was not square, finding R from data
## $chisq
## [1] 231.196
## 
## $p.value
## [1] 3.2698e-52
## 
## $df
## [1] 1
fa.parallel(pearson1, fm="pa", fa="fa", main = "Scree Plot",n.obs = nrow(Act1FLM1)) #cuantos indices deberia formar

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

#Para ver el tipo de análisis factorial:
# mientras mas grande mejor (lo que aporta)
sort(Act1FLM1$communalities)
## PoblacionActiva             FLM 
##       0.7868555       0.7868555
# mientras mas grande peor (lo que mantiene)
sort(Act1FLM1$uniquenesses)
## PoblacionActiva             FLM 
##       0.2131445       0.2131445
sort(Act1FLM1$complexity)
## PoblacionActiva             FLM 
##               1               1
Act1FLM1$scores
##                                                               MR1
## Afghanistan                                          -0.218081911
## Albania                                              -0.747419191
## Algeria                                              -1.224632385
## Angola                                                1.296292143
## Arab World                                           -1.979997621
## Argentina                                             0.004582650
## Armenia                                              -0.310238745
## Aruba                                                 0.367840847
## Australia                                             0.498514225
## Austria                                               0.105783795
## Azerbaijan                                            0.302854548
## Bahamas, The                                          0.623402726
## Bahrain                                              -0.853641697
## Bangladesh                                           -1.472732756
## Barbados                                              0.960750286
## Belarus                                               0.329622731
## Belgium                                              -0.306988194
## Belize                                               -0.867062954
## Benin                                                 1.580277249
## Bhutan                                                0.567385718
## Bolivia                                               0.743099218
## Bosnia and Herzegovina                               -1.034565215
## Botswana                                              0.336834077
## Brazil                                                0.394759215
## Brunei Darussalam                                     0.195202744
## Bulgaria                                             -0.243377536
## Burkina Faso                                          1.389544683
## Burundi                                               1.045368902
## Cabo Verde                                            0.136991681
## Cambodia                                              1.808782549
## Cameroon                                              1.760772259
## Canada                                                0.819332764
## Caribbean small states                                0.072862091
## Cayman Islands                                        1.053765461
## Central African Republic                              0.509861315
## Central Europe and the Baltics                       -0.125440772
## Chad                                                  0.448841779
## Channel Islands                                       0.001251200
## Chile                                                -0.593441335
## China                                                 0.546450719
## Colombia                                              0.227261289
## Comoros                                              -1.114769780
## Congo, Dem. Rep.                                      1.415986742
## Congo, Rep.                                           1.166573364
## Costa Rica                                           -0.397352481
## Cote d'Ivoire                                        -0.061868183
## Croatia                                              -0.336865361
## Cuba                                                 -0.959734638
## Cyprus                                                0.310985908
## Czech Republic                                        0.069977696
## Denmark                                               0.739197542
## Djibouti                                             -0.037241149
## Dominican Republic                                   -0.655151160
## Early-demographic dividend                           -0.865927088
## East Asia & Pacific                                   0.386330446
## East Asia & Pacific (excluding high income)           0.442014163
## East Asia & Pacific (IDA & IBRD countries)            0.436908551
## Ecuador                                               0.176081095
## Egypt, Arab Rep.                                     -2.005033677
## El Salvador                                          -0.264923711
## Equatorial Guinea                                     0.060289066
## Eritrea                                               0.744175438
## Estonia                                               0.277800750
## Eswatini                                             -0.498152426
## Ethiopia                                              1.679320454
## Euro area                                            -0.106349196
## Europe & Central Asia                                -0.006807899
## Europe & Central Asia (excluding high income)        -0.001337942
## Europe & Central Asia (IDA & IBRD countries)         -0.019361503
## European Union                                       -0.039837413
## Fiji                                                 -0.946866807
## Finland                                               0.515624322
## Fragile and conflict affected situations             -0.034553476
## France                                                0.052207623
## French Polynesia                                     -0.151777904
## Gabon                                                -0.271022288
## Gambia, The                                          -0.054741891
## Georgia                                               0.411265626
## Germany                                               0.092597943
## Ghana                                                 1.324422734
## Greece                                               -0.488210709
## Guam                                                  0.340044186
## Guatemala                                            -0.378624796
## Guinea                                                0.416189510
## Guinea-Bissau                                         0.491520630
## Guyana                                               -0.513258095
## Haiti                                                 0.195356957
## Heavily indebted poor countries (HIPC)                0.485561463
## High income                                           0.149685853
## Honduras                                             -0.589130873
## Hong Kong SAR, China                                  0.171289897
## Hungary                                              -0.456806438
## IBRD only                                            -0.023631135
## Iceland                                               1.693784620
## IDA & IBRD total                                     -0.018782865
## IDA blend                                            -0.806941564
## IDA only                                              0.161754091
## IDA total                                             0.001778396
## India                                                -1.185765411
## Indonesia                                            -0.162841980
## Iran, Islamic Rep.                                   -2.112360416
## Iraq                                                 -2.536029376
## Ireland                                               0.238920337
## Isle of Man                                           0.256001551
## Israel                                                0.377123027
## Italy                                                -0.782635384
## Jamaica                                               0.421407379
## Japan                                                -0.072704909
## Jordan                                               -2.490151045
## Kazakhstan                                            1.027408228
## Kenya                                                 0.735505219
## Kiribati                                             -0.985310951
## Korea, Dem. People’s Rep.                             0.830878402
## Korea, Rep.                                           0.034976626
## Kosovo                                               -0.698268280
## Kuwait                                                0.046047582
## Kyrgyz Republic                                       0.300847727
## Lao PDR                                               1.999875482
## Late-demographic dividend                             0.388485135
## Latin America & Caribbean                             0.041142445
## Latin America & Caribbean (excluding high income)     0.075280389
## Latin America & the Caribbean (IDA & IBRD countries)  0.065569377
## Latvia                                                0.128623266
## Least developed countries: UN classification          0.216709160
## Lebanon                                              -1.946961775
## Lesotho                                              -0.137693307
## Liberia                                               0.765510910
## Libya                                                -0.941884570
## Liechtenstein                                         0.141807689
## Lithuania                                             0.134496532
## Low & middle income                                  -0.014293141
## Low income                                            0.508704767
## Lower middle income                                  -0.818704121
## Luxembourg                                           -0.227072385
## Macao SAR, China                                      0.539375369
## Madagascar                                            2.273801315
## Malawi                                                1.975846557
## Malaysia                                             -0.280719425
## Maldives                                             -0.319897128
## Mali                                                  0.730988288
## Malta                                                -1.298600132
## Mauritania                                           -0.703685818
## Mauritius                                            -0.575270084
## Mexico                                               -0.573230839
## Middle East & North Africa                           -1.975443501
## Middle East & North Africa (excluding high income)   -2.028850299
## Middle East & North Africa (IDA & IBRD countries)    -2.025291777
## Middle income                                        -0.060565269
## Moldova                                              -0.238247760
## Mongolia                                              0.432687495
## Montenegro                                           -0.414569055
## Morocco                                              -1.568033163
## Mozambique                                            2.542142687
## Myanmar                                               0.199796113
## Namibia                                              -0.249277877
## Nepal                                                 2.538850436
## Netherlands                                           0.521080833
## New Caledonia                                         0.334361949
## New Zealand                                           0.725181542
## Nicaragua                                            -0.361433382
## Niger                                                 0.251317114
## Nigeria                                              -0.091427247
## North America                                         0.648117672
## North Macedonia                                      -0.468344263
## Northern Mariana Islands                              1.125439692
## Norway                                                1.054652072
## OECD members                                          0.039050741
## Oman                                                 -1.671541746
## Other small states                                   -0.024994858
## Pacific island small states                          -0.169651496
## Pakistan                                             -2.086227681
## Palau                                                 0.321096783
## Panama                                               -0.182764593
## Papua New Guinea                                      0.305338522
## Paraguay                                              0.319355648
## Peru                                                  0.900286201
## Philippines                                          -0.147202953
## Poland                                               -0.151082728
## Portugal                                              0.382453534
## Post-demographic dividend                             0.202798162
## Pre-demographic dividend                              0.260775226
## Puerto Rico                                          -0.831745121
## Qatar                                                -0.272388758
## Romania                                              -0.120953027
## Russian Federation                                    0.597349047
## Rwanda                                                2.350623422
## Samoa                                                -1.374880549
## San Marino                                            0.172208561
## Sao Tome and Principe                                -1.019860577
## Saudi Arabia                                         -2.129877574
## Senegal                                              -1.054152738
## Serbia                                               -0.308830749
## Sierra Leone                                          1.023502680
## Singapore                                             0.186636237
## Slovak Republic                                       0.138050914
## Slovenia                                              0.203810232
## Small states                                         -0.010767330
## Solomon Islands                                       0.444523960
## Somalia                                              -1.074265326
## South Africa                                         -0.416041508
## South Asia                                           -1.199783982
## South Asia (IDA & IBRD)                              -1.199783982
## South Sudan                                           0.664178656
## Spain                                                -0.221935582
## Sri Lanka                                            -0.897814432
## St. Lucia                                             0.649728560
## St. Vincent and the Grenadines                        0.131420593
## Sub-Saharan Africa                                    0.379954847
## Sub-Saharan Africa (excluding high income)            0.379954847
## Sub-Saharan Africa (IDA & IBRD countries)             0.379954847
## Sudan                                                -0.843744066
## Suriname                                             -0.436831030
## Sweden                                                0.641036800
## Switzerland                                           0.680393591
## Syrian Arab Republic                                 -2.245588328
## Tajikistan                                           -0.674952343
## Tanzania                                              2.512556173
## Thailand                                              1.073992684
## Timor-Leste                                          -0.395653700
## Togo                                                  2.104439749
## Tonga                                                -0.658657852
## Trinidad and Tobago                                   0.152339251
## Tunisia                                              -1.785198120
## Turkey                                               -1.729348682
## Turkmenistan                                          0.063497873
## Uganda                                                0.677071249
## Ukraine                                               0.250958153
## United Arab Emirates                                 -0.805208024
## United Kingdom                                        0.368314436
## United States                                         0.628777497
## Upper middle income                                   0.246886943
## Uruguay                                               0.147303509
## Uzbekistan                                           -0.351101194
## Vanuatu                                               0.365019405
## Venezuela, RB                                        -0.001698803
## Vietnam                                               1.399045475
## Virgin Islands (U.S.)                                 0.282411076
## West Bank and Gaza                                   -2.388327075
## World                                                -0.003717115
## Yemen, Rep.                                          -2.505323817
## Zambia                                                0.760219351
## Zimbabwe                                              1.866854539
scores1=as.data.frame(Act1FLM1$scores)
names(scores1) = c("Empoderamiento")
head(scores1)
##             Empoderamiento
## Afghanistan    -0.21808191
## Albania        -0.74741919
## Algeria        -1.22463238
## Angola          1.29629214
## Arab World     -1.97999762
## Argentina       0.00458265
scores1$Pais=row.names(scores1)
row.names(scores1) = NULL

Análisis factorial calidad de vida

#Ponemos las variables en forma intuitiva restando con el mayor valor
Calidad1$BarriosTugurios= 100 - Calidad1$BarriosTugurios 
Calidad1$Gini= 65 - Calidad1$Gini
Calidad1_X=Calidad1
row.names(Calidad1) = Calidad1$Pais
Calidad1$Pais = NULL
head(Calidad1)
##                BarriosTugurios Gini      EDU      ENER      GAST
## Afghanistan                 NA   NA       NA  22.79312        NA
## Albania                     NA 34.4       NA 100.00000 0.0873700
## Algeria                     NA   NA 72.64868  98.80855 0.1419467
## American Samoa              NA   NA       NA        NA 0.3170075
## Andorra                     NA   NA       NA 100.00000        NA
## Angola                   18.65   NA       NA  29.52772        NA
##                        ban
## Afghanistan     0.00137906
## Albania         0.16976576
## Algeria         0.38217637
## American Samoa          NA
## Andorra        13.34488004
## Angola          0.04626376
Calidad1[is.na(Calidad1$BarriosTugurios), "BarriosTugurios"]=mean(Calidad1$BarriosTugurios, na.rm=T)
Calidad1[is.na(Calidad1$Gini), "Gini"]=mean(Calidad1$Gini, na.rm=T)
Calidad1[is.na(Calidad1$EDU), "EDU"]=mean(Calidad1$EDU, na.rm=T)
Calidad1[is.na(Calidad1$ENER), "ENER"]=mean(Calidad1$ENER, na.rm=T)
Calidad1[is.na(Calidad1$GAST), "GAST"]=mean(Calidad1$GAST, na.rm=T)
Calidad1[is.na(Calidad1$ban), "ban"]=mean(Calidad1$ban, na.rm=T)
Calidad1=as.data.frame(scale(Calidad1[,c(1:6)]))
head(Calidad1)
##                BarriosTugurios     Gini        EDU       ENER       GAST
## Afghanistan           0.000000 0.000000  0.0000000 -1.7233986  0.0000000
## Albania               0.000000 1.394347  0.0000000  0.7551778 -1.1905817
## Algeria               0.000000 0.000000 -0.2212941  0.7169287 -1.1038070
## American Samoa        0.000000 0.000000  0.0000000  0.0000000 -0.8254673
## Andorra               0.000000 0.000000  0.0000000  0.7551778  0.0000000
## Angola               -2.469433 0.000000  0.0000000 -1.5071972  0.0000000
##                       ban
## Afghanistan    -0.6777603
## Albania        -0.6512634
## Algeria        -0.6178389
## American Samoa  0.0000000
## Andorra         1.4219446
## Angola         -0.6706974
library(psych)
promedio1 = cor(Calidad1) #sacar la correlación de los puntajes estandarizadas
promedio1
##                 BarriosTugurios        Gini         EDU      ENER
## BarriosTugurios     1.000000000 -0.13270600  0.49417768 0.5779805
## Gini               -0.132706004  1.00000000 -0.09252552 0.2145609
## EDU                 0.494177679 -0.09252552  1.00000000 0.5721154
## ENER                0.577980511  0.21456087  0.57211541 1.0000000
## GAST               -0.007642321  0.27747953  0.04709207 0.1967345
## ban                 0.011836126  0.31819474  0.10412853 0.3545951
##                         GAST        ban
## BarriosTugurios -0.007642321 0.01183613
## Gini             0.277479531 0.31819474
## EDU              0.047092075 0.10412853
## ENER             0.196734526 0.35459509
## GAST             1.000000000 0.62000846
## ban              0.620008458 1.00000000
cor.plot(promedio1, 
         numbers=T, 
         upper=FALSE, 
         main = "Correlation", 
         show.legend = FALSE) #verlo en un gráfico

KMO(Calidad1) #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 = Calidad1)
## Overall MSA =  0.6
## MSA for each item = 
## BarriosTugurios            Gini             EDU            ENER 
##            0.62            0.54            0.70            0.58 
##            GAST             ban 
##            0.59            0.58
fa.parallel(promedio1, fm="pa", fa="fa", main = "Scree Plot",n.obs = nrow(Calidad1)) #cuantos indices deberia formar
## Warning in fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs
## = np.obs, : The estimated weights for the factor scores are probably
## incorrect. Try a different factor extraction method.

## Parallel analysis suggests that the number of factors =  3  and the number of components =  NA
Calidad1 = fa(Calidad1, 
                     nfactors=3, 
                     rotate="varimax") #codigo para el analisis factorial solo cambiar la data y el numero de factores
## Warning in fac(r = r, nfactors = nfactors, n.obs = n.obs, rotate =
## rotate, : An ultra-Heywood case was detected. Examine the results carefully
Calidad1$loadings
## 
## Loadings:
##                 MR1    MR2    MR3   
## BarriosTugurios  0.717        -0.143
## Gini                    0.241  0.551
## EDU              0.677              
## ENER             0.888  0.157  0.432
## GAST                    0.863  0.118
## ban              0.121  0.673  0.313
## 
##                  MR1   MR2   MR3
## SS loadings    1.782 1.285 0.632
## Proportion Var 0.297 0.214 0.105
## Cumulative Var 0.297 0.511 0.616
fa.diagram(Calidad1)

#Para ver el tipo de análisis factorial:
# mientras mas grande mejor (lo que aporta)
sort(Calidad1$communalities)
##            Gini             EDU BarriosTugurios             ban 
##       0.3668824       0.4712142       0.5351012       0.5657713 
##            GAST            ENER 
##       0.7585527       0.9950000
# mientras mas grande peor (lo que mantiene)
sort(Calidad1$uniquenesses)
##            ENER            GAST             ban BarriosTugurios 
##   -0.0006972736    0.2413269718    0.4340153963    0.4648857180 
##             EDU            Gini 
##    0.5288417029    0.6330720986
sort(Calidad1$complexity)
##            GAST             EDU BarriosTugurios            Gini 
##        1.038257        1.055293        1.080547        1.408544 
##             ban            ENER 
##        1.487721        1.520918
Calidad1$scores
##                                                              MR1
## Afghanistan                                          -1.28872296
## Albania                                               0.47328987
## Algeria                                               0.63538286
## American Samoa                                        0.02928735
## Andorra                                               0.45131879
## Angola                                               -1.54618516
## Antigua and Barbuda                                   0.87478567
## Arab World                                            0.37962060
## Argentina                                             1.26624404
## Armenia                                               0.52788649
## Aruba                                                 0.31144886
## Australia                                             0.29572552
## Austria                                               0.10617704
## Azerbaijan                                            0.58259044
## Bahamas, The                                          0.52927301
## Bahrain                                               0.61196199
## Bangladesh                                           -1.47593965
## Barbados                                              0.70408381
## Belarus                                               0.36794990
## Belgium                                               0.03415665
## Belize                                                0.69510370
## Benin                                                -1.98448749
## Bermuda                                               0.12295387
## Bhutan                                               -0.70295308
## Bolivia                                               0.58528978
## Bosnia and Herzegovina                                0.53055154
## Botswana                                             -0.84727758
## Brazil                                                1.35087042
## Brunei Darussalam                                     0.67504403
## Bulgaria                                              0.53877126
## Burkina Faso                                         -2.10020389
## Burundi                                              -2.17378997
## Cabo Verde                                            0.10482152
## Cambodia                                             -1.66772678
## Cameroon                                             -0.64171528
## Canada                                                0.12337850
## Caribbean small states                                0.55891719
## Cayman Islands                                        0.83042617
## Central African Republic                             -2.18979013
## Central Europe and the Baltics                        0.58641461
## Chad                                                 -2.81787378
## Channel Islands                                       0.59464125
## Chile                                                 1.29221255
## China                                                 0.73851168
## Colombia                                              1.47579858
## Comoros                                              -0.38736668
## Congo, Dem. Rep.                                     -2.03120474
## Congo, Rep.                                          -0.99528190
## Costa Rica                                            1.30392674
## Cote d'Ivoire                                        -0.63845748
## Croatia                                               0.60387032
## Cuba                                                  0.64590704
## Curacao                                               0.59464125
## Cyprus                                                0.39557968
## Czech Republic                                        0.19795345
## Denmark                                              -0.18758402
## Djibouti                                             -0.47181901
## Dominica                                              0.26900652
## Dominican Republic                                    1.21052802
## Early-demographic dividend                            0.07268648
## East Asia & Pacific                                   0.66249277
## East Asia & Pacific (excluding high income)           0.73458314
## East Asia & Pacific (IDA & IBRD countries)            0.75694924
## Ecuador                                               1.41726441
## Egypt, Arab Rep.                                      0.73174179
## El Salvador                                           0.88835512
## Equatorial Guinea                                    -0.50421759
## Eritrea                                              -1.06508883
## Estonia                                               0.30025367
## Eswatini                                             -1.05000765
## Ethiopia                                             -2.49421098
## Euro area                                             0.63086605
## Europe & Central Asia                                 0.70916626
## Europe & Central Asia (excluding high income)         0.84447754
## Europe & Central Asia (IDA & IBRD countries)          0.84506294
## European Union                                        0.65020917
## Faroe Islands                                         0.41899491
## Fiji                                                  0.22077322
## Finland                                              -0.11250373
## Fragile and conflict affected situations             -1.23880669
## France                                                0.12113052
## French Polynesia                                      0.59118472
## Gabon                                                 0.34357663
## Gambia, The                                          -0.73692487
## Georgia                                               0.61040154
## Germany                                               0.13578600
## Ghana                                                -0.35724373
## Gibraltar                                             0.59464125
## Greece                                                0.67609049
## Greenland                                             0.50864662
## Grenada                                               0.96658799
## Guam                                                  0.66853342
## Guatemala                                             0.64850773
## Guinea                                               -1.87316603
## Guinea-Bissau                                        -2.14797483
## Guyana                                                0.19093545
## Haiti                                                -1.60348315
## Heavily indebted poor countries (HIPC)               -1.74380376
## High income                                           0.34907271
## Honduras                                              0.57011946
## Hong Kong SAR, China                                  0.29062705
## Hungary                                               0.29210942
## IBRD only                                             0.57996366
## Iceland                                              -0.11265529
## IDA & IBRD total                                      0.21730463
## IDA blend                                            -0.44649028
## IDA only                                             -1.48465665
## IDA total                                            -1.13635754
## India                                                -0.30704108
## Indonesia                                             0.62143023
## Iran, Islamic Rep.                                    1.01081734
## Iraq                                                  0.26255170
## Ireland                                               0.34338351
## Isle of Man                                           0.59464125
## Israel                                                0.27011902
## Italy                                                 0.33678435
## Jamaica                                               0.33957689
## Japan                                                 0.25298583
## Jordan                                                0.96984775
## Kazakhstan                                            0.51310632
## Kenya                                                -1.25419578
## Kiribati                                             -0.31494032
## Korea, Dem. People’s Rep.                            -1.42845827
## Korea, Rep.                                          -0.05648612
## Kosovo                                                0.25791023
## Kuwait                                                0.86760922
## Kyrgyz Republic                                       0.53437903
## Lao PDR                                              -0.98977441
## Late-demographic dividend                             0.86466749
## Latin America & Caribbean                             0.86535543
## Latin America & Caribbean (excluding high income)     0.84915828
## Latin America & the Caribbean (IDA & IBRD countries)  0.85893282
## Latvia                                                0.54913602
## Least developed countries: UN classification         -1.69519780
## Lebanon                                               0.69299911
## Lesotho                                              -1.52439532
## Liberia                                              -2.31629524
## Libya                                                 0.67416460
## Liechtenstein                                         0.30930217
## Lithuania                                             0.43919362
## Low & middle income                                   0.19720627
## Low income                                           -1.75727091
## Lower middle income                                  -0.11636657
## Luxembourg                                            0.15262039
## Macao SAR, China                                      0.66434442
## Madagascar                                           -1.79495531
## Malawi                                               -1.94670000
## Malaysia                                              0.79011432
## Maldives                                              0.65082253
## Mali                                                 -2.15849881
## Malta                                                 0.37533013
## Marshall Islands                                     -0.05030317
## Mauritania                                           -1.50561264
## Mauritius                                             0.55225015
## Mexico                                                1.38852627
## Micronesia, Fed. Sts.                                -0.37486694
## Middle East & North Africa                            0.69788251
## Middle East & North Africa (excluding high income)    0.65634623
## Middle East & North Africa (IDA & IBRD countries)     0.65288652
## Middle income                                         0.39082017
## Moldova                                               0.55469328
## Monaco                                                0.27095935
## Mongolia                                             -0.09745198
## Montenegro                                            0.60195399
## Morocco                                               0.41115604
## Mozambique                                           -2.24022606
## Myanmar                                              -0.66759847
## Namibia                                              -0.03481467
## Nauru                                                 0.58503834
## Nepal                                                -0.75003491
## Netherlands                                          -0.03316193
## New Caledonia                                         0.59263892
## New Zealand                                           0.50010167
## Nicaragua                                             0.31084864
## Niger                                                -2.48974118
## Nigeria                                              -1.01291027
## North America                                         0.29694702
## North Macedonia                                       0.62233366
## Northern Mariana Islands                              0.59464125
## Norway                                                0.01619126
## OECD members                                          0.36242030
## Oman                                                  0.71428723
## Other small states                                   -0.37371102
## Pacific island small states                          -0.32538152
## Pakistan                                             -0.19247573
## Palau                                                 0.61747321
## Panama                                                0.97063199
## Papua New Guinea                                     -1.56504359
## Paraguay                                              1.45990858
## Peru                                                  0.67546043
## Philippines                                           0.43908948
## Poland                                                0.47860696
## Portugal                                              0.47708332
## Post-demographic dividend                             0.33697908
## Pre-demographic dividend                             -1.54547211
## Puerto Rico                                           0.61309036
## Qatar                                                 0.76566564
## Romania                                               0.61917325
## Russian Federation                                    0.67829303
## Rwanda                                               -1.58772460
## Samoa                                                 0.47755835
## San Marino                                            0.59846417
## Sao Tome and Principe                                -0.45879920
## Saudi Arabia                                          1.07603800
## Senegal                                              -1.02471482
## Serbia                                                0.46794911
## Seychelles                                            0.56230626
## Sierra Leone                                         -2.58758124
## Singapore                                             0.35540711
## Sint Maarten (Dutch part)                             0.59464125
## Slovak Republic                                       0.28001107
## Slovenia                                              0.32304036
## Small states                                         -0.18116503
## Solomon Islands                                      -1.28031868
## Somalia                                              -1.94086688
## South Africa                                          1.22630549
## South Asia                                           -0.29271171
## South Asia (IDA & IBRD)                              -0.29271171
## South Sudan                                          -1.92960790
## Spain                                                 0.52657555
## Sri Lanka                                             0.31471714
## St. Kitts and Nevis                                   0.34076772
## St. Lucia                                             0.77375456
## St. Martin (French part)                             -0.43812641
## St. Vincent and the Grenadines                        0.26280349
## Sub-Saharan Africa                                   -1.44087447
## Sub-Saharan Africa (excluding high income)           -1.44110644
## Sub-Saharan Africa (IDA & IBRD countries)            -1.44087447
## Sudan                                                -0.99364835
## Suriname                                              1.10695892
## Sweden                                               -0.18950717
## Switzerland                                           0.08076505
## Syrian Arab Republic                                  0.78990348
## Tajikistan                                            0.51670612
## Tanzania                                             -1.72998746
## Thailand                                              0.97906030
## Timor-Leste                                          -1.59996695
## Togo                                                 -1.50179459
## Tonga                                                 0.62244336
## Trinidad and Tobago                                   0.80215679
## Tunisia                                               0.60999492
## Turkey                                                1.08646735
## Turkmenistan                                          0.58593378
## Turks and Caicos Islands                              0.42401618
## Tuvalu                                                0.52636842
## Uganda                                               -1.74553044
## Ukraine                                               0.34677614
## United Arab Emirates                                  0.75863772
## United Kingdom                                        0.26678538
## United States                                         0.35139421
## Upper middle income                                   0.90063013
## Uruguay                                               1.02914988
## Uzbekistan                                            0.58813642
## Vanuatu                                              -1.10820402
## Venezuela, RB                                         1.27890147
## Vietnam                                               0.46795125
## Virgin Islands (U.S.)                                 0.65726233
## West Bank and Gaza                                    0.72894882
## World                                                 0.23193789
## Yemen, Rep.                                          -1.13072094
## Zambia                                               -1.17865742
## Zimbabwe                                             -0.68533868
##                                                               MR2
## Afghanistan                                           0.038673556
## Albania                                              -1.141039814
## Algeria                                              -1.066187218
## American Samoa                                       -0.596071750
## Andorra                                               0.283324544
## Angola                                               -0.057611355
## Antigua and Barbuda                                  -0.036392766
## Arab World                                           -0.183969970
## Argentina                                            -0.457542618
## Armenia                                              -0.943961150
## Aruba                                                 0.177247485
## Australia                                             1.460774186
## Austria                                               1.968257989
## Azerbaijan                                           -0.872896588
## Bahamas, The                                         -0.078658359
## Bahrain                                              -0.142086253
## Bangladesh                                           -0.225756689
## Barbados                                              0.360420947
## Belarus                                              -0.422674500
## Belgium                                               1.633200756
## Belize                                               -0.119811492
## Benin                                                -0.230122721
## Bermuda                                               0.501509377
## Bhutan                                               -0.018350604
## Bolivia                                              -0.088063431
## Bosnia and Herzegovina                               -1.184580709
## Botswana                                             -0.340734870
## Brazil                                                0.130761512
## Brunei Darussalam                                    -1.116576217
## Bulgaria                                             -0.555813083
## Burkina Faso                                         -0.892291173
## Burundi                                              -0.479159014
## Cabo Verde                                           -0.093544371
## Cambodia                                             -0.041797330
## Cameroon                                             -0.082428270
## Canada                                                1.891593845
## Caribbean small states                               -0.073788621
## Cayman Islands                                        0.003016415
## Central African Republic                              0.191304163
## Central Europe and the Baltics                       -0.168878154
## Chad                                                  0.005344313
## Channel Islands                                      -0.096217949
## Chile                                                -0.593597253
## China                                                 0.385816828
## Colombia                                             -0.846490324
## Comoros                                              -0.101454119
## Congo, Dem. Rep.                                     -0.648856511
## Congo, Rep.                                           0.179012241
## Costa Rica                                           -0.665401900
## Cote d'Ivoire                                        -0.110569877
## Croatia                                              -0.083026606
## Cuba                                                 -0.631253489
## Curacao                                              -0.096217949
## Cyprus                                               -0.661495798
## Czech Republic                                        0.415452766
## Denmark                                               2.594244773
## Djibouti                                             -0.091467854
## Dominica                                             -0.005702867
## Dominican Republic                                   -0.083529206
## Early-demographic dividend                           -0.371289965
## East Asia & Pacific                                   1.799223841
## East Asia & Pacific (excluding high income)           0.309168324
## East Asia & Pacific (IDA & IBRD countries)            0.305156655
## Ecuador                                              -0.952885612
## Egypt, Arab Rep.                                     -0.910446395
## El Salvador                                          -0.962811287
## Equatorial Guinea                                    -0.169953945
## Eritrea                                               0.172340320
## Estonia                                               0.412675050
## Eswatini                                              0.169900059
## Ethiopia                                             -0.949868930
## Euro area                                             1.479329669
## Europe & Central Asia                                 1.126543872
## Europe & Central Asia (excluding high income)        -0.143604277
## Europe & Central Asia (IDA & IBRD countries)         -0.173638980
## European Union                                        1.402028670
## Faroe Islands                                         0.393879398
## Fiji                                                 -0.162821343
## Finland                                               3.445077161
## Fragile and conflict affected situations              0.083130493
## France                                                1.783262297
## French Polynesia                                     -0.087064473
## Gabon                                                -0.659268842
## Gambia, The                                           0.014934555
## Georgia                                              -0.975507084
## Germany                                               2.141283612
## Ghana                                                -0.775304309
## Gibraltar                                            -0.096217949
## Greece                                               -0.399083943
## Greenland                                            -0.127756291
## Grenada                                               0.118049191
## Guam                                                 -0.867542228
## Guatemala                                            -1.057025754
## Guinea                                                0.029361244
## Guinea-Bissau                                         0.201196511
## Guyana                                               -0.147604999
## Haiti                                                 0.032591706
## Heavily indebted poor countries (HIPC)               -0.090908368
## High income                                           1.940143363
## Honduras                                             -0.804265058
## Hong Kong SAR, China                                  0.617148333
## Hungary                                               0.148211597
## IBRD only                                            -0.103249413
## Iceland                                               2.912597749
## IDA & IBRD total                                     -0.113469380
## IDA blend                                            -0.717257212
## IDA only                                             -0.111048709
## IDA total                                            -0.126674662
## India                                                -0.223974750
## Indonesia                                            -0.130333434
## Iran, Islamic Rep.                                   -0.505986899
## Iraq                                                 -1.204075513
## Ireland                                               0.474287072
## Isle of Man                                          -0.096217949
## Israel                                                4.178094497
## Italy                                                 0.453768093
## Jamaica                                              -0.178293277
## Japan                                                 3.143684121
## Jordan                                               -0.135870655
## Kazakhstan                                           -0.942233950
## Kenya                                                -0.529287367
## Kiribati                                             -0.113211581
## Korea, Dem. People’s Rep.                             0.231136548
## Korea, Rep.                                           2.920839185
## Kosovo                                               -0.092597574
## Kuwait                                               -0.991964148
## Kyrgyz Republic                                      -0.991741225
## Lao PDR                                              -0.179464201
## Late-demographic dividend                             0.136836954
## Latin America & Caribbean                            -0.358214098
## Latin America & Caribbean (excluding high income)    -0.337341831
## Latin America & the Caribbean (IDA & IBRD countries) -0.356369239
## Latvia                                               -0.448307153
## Least developed countries: UN classification         -0.112001232
## Lebanon                                              -0.222165075
## Lesotho                                              -0.801214149
## Liberia                                               0.166900102
## Libya                                                -0.047277648
## Liechtenstein                                         0.659408947
## Lithuania                                            -0.035043486
## Low & middle income                                  -0.089096894
## Low income                                           -0.091611216
## Lower middle income                                  -0.407146159
## Luxembourg                                            1.233445607
## Macao SAR, China                                     -0.490710996
## Madagascar                                           -0.720709798
## Malawi                                                0.065261626
## Malaysia                                             -0.439603013
## Maldives                                             -0.089877854
## Mali                                                 -0.903897635
## Malta                                                -0.118937774
## Marshall Islands                                      0.008139475
## Mauritania                                           -0.095554341
## Mauritius                                            -0.770523574
## Mexico                                               -0.557484070
## Micronesia, Fed. Sts.                                -0.087187079
## Middle East & North Africa                           -0.189530020
## Middle East & North Africa (excluding high income)   -0.219404712
## Middle East & North Africa (IDA & IBRD countries)    -0.220215144
## Middle income                                        -0.093949608
## Moldova                                              -0.756074758
## Monaco                                               -0.036862855
## Mongolia                                             -0.900740075
## Montenegro                                            0.109209165
## Morocco                                              -0.461744104
## Mozambique                                           -0.537220431
## Myanmar                                              -0.065475439
## Namibia                                               0.022964864
## Nauru                                                -0.094664119
## Nepal                                                -0.078425541
## Netherlands                                           1.806020389
## New Caledonia                                        -0.090915436
## New Zealand                                           0.459543824
## Nicaragua                                            -0.143254254
## Niger                                                -0.176345947
## Nigeria                                              -0.902908831
## North America                                         2.350717020
## North Macedonia                                      -0.891880407
## Northern Mariana Islands                             -0.096217949
## Norway                                                1.382424532
## OECD members                                          1.878486670
## Oman                                                 -0.235193576
## Other small states                                    0.032677782
## Pacific island small states                          -0.095241171
## Pakistan                                             -0.670270791
## Palau                                                -0.251454186
## Panama                                               -0.763408637
## Papua New Guinea                                      0.253237200
## Paraguay                                             -0.976977489
## Peru                                                 -0.856131578
## Philippines                                          -0.925876097
## Poland                                               -0.408627324
## Portugal                                              0.173693825
## Post-demographic dividend                             2.031560590
## Pre-demographic dividend                             -0.104061880
## Puerto Rico                                          -0.145074361
## Qatar                                                -0.070090611
## Romania                                              -0.600563764
## Russian Federation                                    0.134042632
## Rwanda                                                0.066749205
## Samoa                                                -0.245410754
## San Marino                                           -0.106341704
## Sao Tome and Principe                                -0.090399048
## Saudi Arabia                                         -1.064260348
## Senegal                                              -0.187050785
## Serbia                                               -0.618589436
## Seychelles                                           -0.730837807
## Sierra Leone                                         -0.015009675
## Singapore                                             1.851834413
## Sint Maarten (Dutch part)                            -0.096217949
## Slovak Republic                                      -0.507357440
## Slovenia                                              0.866347934
## Small states                                          0.015180312
## Solomon Islands                                       0.083274903
## Somalia                                               0.203971234
## South Africa                                         -0.046605946
## South Asia                                           -0.254725198
## South Asia (IDA & IBRD)                              -0.254725198
## South Sudan                                           0.312226770
## Spain                                                 0.605472539
## Sri Lanka                                            -0.867624443
## St. Kitts and Nevis                                   0.279233760
## St. Lucia                                            -0.025436339
## St. Martin (French part)                              0.070892534
## St. Vincent and the Grenadines                       -0.069702830
## Sub-Saharan Africa                                   -0.476288869
## Sub-Saharan Africa (excluding high income)           -0.476296136
## Sub-Saharan Africa (IDA & IBRD countries)            -0.476288869
## Sudan                                                -0.605447725
## Suriname                                             -0.098510133
## Sweden                                                3.637355430
## Switzerland                                           2.739352668
## Syrian Arab Republic                                 -0.177805992
## Tajikistan                                           -1.147706733
## Tanzania                                             -0.527397330
## Thailand                                             -0.797765656
## Timor-Leste                                          -0.123815067
## Togo                                                 -0.085046474
## Tonga                                                -0.113593468
## Trinidad and Tobago                                  -1.024744966
## Tunisia                                              -0.432702257
## Turkey                                               -0.351652098
## Turkmenistan                                         -0.094809008
## Turks and Caicos Islands                             -0.068609380
## Tuvalu                                               -0.185046003
## Uganda                                               -0.596488142
## Ukraine                                              -0.051874817
## United Arab Emirates                                 -0.082306122
## United Kingdom                                        1.236198046
## United States                                         2.390895483
## Upper middle income                                  -0.017229040
## Uruguay                                              -0.563391821
## Uzbekistan                                           -0.960016648
## Vanuatu                                               0.026823609
## Venezuela, RB                                        -0.773894179
## Vietnam                                              -0.223627404
## Virgin Islands (U.S.)                                -1.065345509
## West Bank and Gaza                                   -0.900469413
## World                                                 1.321749952
## Yemen, Rep.                                          -0.242455987
## Zambia                                               -0.952795992
## Zimbabwe                                              0.039555393
##                                                               MR3
## Afghanistan                                          -1.383960928
## Albania                                               1.178861819
## Algeria                                               0.754605654
## American Samoa                                        0.128088771
## Andorra                                               0.683137249
## Angola                                               -0.236433583
## Antigua and Barbuda                                  -0.683118279
## Arab World                                           -0.179963663
## Argentina                                            -0.942786035
## Armenia                                               0.963556281
## Aruba                                                 0.459208943
## Australia                                             0.651910080
## Austria                                               0.831483487
## Azerbaijan                                            0.786529608
## Bahamas, The                                          0.526419633
## Bahrain                                               0.574474833
## Bangladesh                                            0.764994519
## Barbados                                              0.128232469
## Belarus                                               1.160071049
## Belgium                                               1.038849324
## Belize                                               -0.370858809
## Benin                                                 0.522825990
## Bermuda                                               1.091048380
## Bhutan                                                0.015232477
## Bolivia                                              -1.234556271
## Bosnia and Herzegovina                                1.024539946
## Botswana                                             -1.069705024
## Brazil                                               -1.221833260
## Brunei Darussalam                                     0.762116022
## Bulgaria                                              0.841523706
## Burkina Faso                                         -0.149873263
## Burundi                                              -0.819435531
## Cabo Verde                                           -0.845431725
## Cambodia                                             -0.382786898
## Cameroon                                             -0.801709174
## Canada                                                0.769278501
## Caribbean small states                               -0.105548614
## Cayman Islands                                        0.054513173
## Central African Republic                             -0.632472148
## Central Europe and the Baltics                        0.618695037
## Chad                                                  0.470415508
## Channel Islands                                       0.586190945
## Chile                                                -0.852608812
## China                                                -0.040508722
## Colombia                                             -1.328451123
## Comoros                                              -0.943916083
## Congo, Dem. Rep.                                     -0.581961726
## Congo, Rep.                                          -1.354452257
## Costa Rica                                           -0.786354981
## Cote d'Ivoire                                        -0.292241319
## Croatia                                               0.569214302
## Cuba                                                  0.583579714
## Curacao                                               0.586190945
## Cyprus                                                1.152618643
## Czech Republic                                        1.184434735
## Denmark                                               1.132539236
## Djibouti                                             -0.577301661
## Dominica                                              0.290470676
## Dominican Republic                                   -1.345349390
## Early-demographic dividend                           -0.316100657
## East Asia & Pacific                                  -0.716923160
## East Asia & Pacific (excluding high income)          -0.437616863
## East Asia & Pacific (IDA & IBRD countries)           -0.412530805
## Ecuador                                              -1.143672951
## Egypt, Arab Rep.                                      0.431403759
## El Salvador                                          -0.603729738
## Equatorial Guinea                                     0.217032222
## Eritrea                                              -1.049953113
## Estonia                                               0.936862620
## Eswatini                                             -1.035086251
## Ethiopia                                              1.004805727
## Euro area                                            -0.078829412
## Europe & Central Asia                                -0.105810970
## Europe & Central Asia (excluding high income)         0.046998852
## Europe & Central Asia (IDA & IBRD countries)          0.057283047
## European Union                                       -0.086086701
## Faroe Islands                                         0.697883506
## Fiji                                                  0.132666700
## Finland                                               0.748508138
## Fragile and conflict affected situations             -0.355859383
## France                                                0.846353003
## French Polynesia                                      0.588529012
## Gabon                                                -0.179273317
## Gambia, The                                          -1.687206678
## Georgia                                               0.770867295
## Germany                                               0.718331186
## Ghana                                                -0.679193777
## Gibraltar                                             0.586190945
## Greece                                                0.500045908
## Greenland                                             0.718312028
## Grenada                                              -1.276780628
## Guam                                                  0.700404055
## Guatemala                                            -0.689192163
## Guinea                                               -0.326705660
## Guinea-Bissau                                        -0.650666462
## Guyana                                               -0.335769989
## Haiti                                                 0.113529884
## Heavily indebted poor countries (HIPC)               -0.362488848
## High income                                           0.345650041
## Honduras                                             -1.444686610
## Hong Kong SAR, China                                  0.817993167
## Hungary                                               1.076314940
## IBRD only                                            -0.349395494
## Iceland                                               0.889037429
## IDA & IBRD total                                     -0.364471552
## IDA blend                                             0.138062611
## IDA only                                             -0.237938503
## IDA total                                            -0.185638204
## India                                                -0.033948424
## Indonesia                                            -0.323572689
## Iran, Islamic Rep.                                   -0.252916997
## Iraq                                                  1.449952559
## Ireland                                               0.869974599
## Isle of Man                                           0.586190945
## Israel                                               -0.202936334
## Italy                                                 0.871391219
## Jamaica                                               0.342901540
## Japan                                                 0.151225406
## Jordan                                               -0.298676127
## Kazakhstan                                            0.988832083
## Kenya                                                -1.364526917
## Kiribati                                             -0.253662086
## Korea, Dem. People’s Rep.                            -1.408158796
## Korea, Rep.                                           0.762875295
## Kosovo                                                0.967715353
## Kuwait                                                0.324087068
## Kyrgyz Republic                                       0.977190058
## Lao PDR                                               0.619132617
## Late-demographic dividend                            -0.345568118
## Latin America & Caribbean                            -0.392300789
## Latin America & Caribbean (excluding high income)    -0.396025578
## Latin America & the Caribbean (IDA & IBRD countries) -0.391042338
## Latvia                                                0.778301578
## Least developed countries: UN classification         -0.151443646
## Lebanon                                               0.441057518
## Lesotho                                              -1.649729968
## Liberia                                              -1.006682271
## Libya                                                 0.320822834
## Liechtenstein                                         0.779200255
## Lithuania                                             0.843147136
## Low & middle income                                  -0.375756194
## Low income                                           -0.356444171
## Lower middle income                                  -0.198881175
## Luxembourg                                            0.960119455
## Macao SAR, China                                      0.471478055
## Madagascar                                           -0.517044049
## Malawi                                               -1.253257793
## Malaysia                                              0.183166587
## Maldives                                             -0.186738700
## Mali                                                  0.358788767
## Malta                                                 0.937184926
## Marshall Islands                                     -0.049588321
## Mauritania                                           -0.704343048
## Mauritius                                             0.816614067
## Mexico                                               -1.045446428
## Micronesia, Fed. Sts.                                -0.760889089
## Middle East & North Africa                           -0.033870126
## Middle East & North Africa (excluding high income)    0.020981082
## Middle East & North Africa (IDA & IBRD countries)     0.023876188
## Middle income                                        -0.326434824
## Moldova                                               0.831938072
## Monaco                                                1.032701150
## Mongolia                                              0.671252783
## Montenegro                                            0.454084268
## Morocco                                              -0.217708272
## Mozambique                                           -0.004036439
## Myanmar                                              -0.732649978
## Namibia                                              -2.562420851
## Nauru                                                 0.576724508
## Nepal                                                -0.656085832
## Netherlands                                           1.077840606
## New Caledonia                                         0.587545363
## New Zealand                                           0.563026743
## Nicaragua                                            -0.641379681
## Niger                                                 0.250479955
## Nigeria                                               0.378940499
## North America                                         0.314466352
## North Macedonia                                       0.683715113
## Northern Mariana Islands                              0.586190945
## Norway                                                1.141598448
## OECD members                                          0.336713186
## Oman                                                  0.413776918
## Other small states                                   -0.560287944
## Pacific island small states                          -0.419627022
## Pakistan                                              1.178012067
## Palau                                                 0.507388095
## Panama                                               -1.064040118
## Papua New Guinea                                     -1.542803135
## Paraguay                                             -1.308855259
## Peru                                                 -0.980928543
## Philippines                                          -0.417693447
## Poland                                                0.907377573
## Portugal                                              0.688788610
## Post-demographic dividend                             0.346218254
## Pre-demographic dividend                             -0.260756521
## Puerto Rico                                           0.573711582
## Qatar                                                 0.224126264
## Romania                                               0.700843001
## Russian Federation                                    0.371514089
## Rwanda                                               -1.770416315
## Samoa                                                 0.358366615
## San Marino                                            0.583605041
## Sao Tome and Principe                                -0.562343942
## Saudi Arabia                                         -0.129714659
## Senegal                                              -0.117831889
## Serbia                                                0.988274980
## Seychelles                                            0.586335510
## Sierra Leone                                          0.688862756
## Singapore                                             0.373064303
## Sint Maarten (Dutch part)                             0.586190945
## Slovak Republic                                       1.330889297
## Slovenia                                              0.737181709
## Small states                                         -0.444235755
## Solomon Islands                                      -1.952007208
## Somalia                                              -0.810146772
## South Africa                                         -2.135850646
## South Asia                                           -0.129643613
## South Asia (IDA & IBRD)                              -0.129643613
## South Sudan                                          -1.902186720
## Spain                                                 0.412542452
## Sri Lanka                                            -0.281662162
## St. Kitts and Nevis                                   0.559463640
## St. Lucia                                            -0.497928704
## St. Martin (French part)                             -0.431900302
## St. Vincent and the Grenadines                        0.240898853
## Sub-Saharan Africa                                   -0.326364007
## Sub-Saharan Africa (excluding high income)           -0.326425128
## Sub-Saharan Africa (IDA & IBRD countries)            -0.326364007
## Sudan                                                -0.991866448
## Suriname                                             -1.021303372
## Sweden                                                0.826477655
## Switzerland                                           0.583417148
## Syrian Arab Republic                                 -0.317970857
## Tajikistan                                            1.037788850
## Tanzania                                             -1.028535221
## Thailand                                             -0.489601496
## Timor-Leste                                           0.039750570
## Togo                                                 -0.571379380
## Tonga                                                -0.256525312
## Trinidad and Tobago                                   0.090949028
## Tunisia                                               0.623837993
## Turkey                                               -0.607938503
## Turkmenistan                                          0.577607216
## Turks and Caicos Islands                              0.417990591
## Tuvalu                                                0.452118712
## Uganda                                               -1.127900527
## Ukraine                                               1.057440069
## United Arab Emirates                                  0.244735236
## United Kingdom                                        0.730646427
## United States                                         0.198425817
## Upper middle income                                  -0.324783747
## Uruguay                                              -0.259468252
## Uzbekistan                                            0.877257285
## Vanuatu                                              -1.295507926
## Venezuela, RB                                        -0.704418912
## Vietnam                                               0.394349770
## Virgin Islands (U.S.)                                 0.772962562
## West Bank and Gaza                                    0.519147512
## World                                                -0.611312688
## Yemen, Rep.                                           0.871877662
## Zambia                                               -1.424985708
## Zimbabwe                                             -1.744006562
promedio1=as.data.frame(Calidad1$scores)
names(promedio1) = c("Densidad","Informacion", "Desigualdad")
head(promedio1)
##                   Densidad Informacion Desigualdad
## Afghanistan    -1.28872296  0.03867356  -1.3839609
## Albania         0.47328987 -1.14103981   1.1788618
## Algeria         0.63538286 -1.06618722   0.7546057
## American Samoa  0.02928735 -0.59607175   0.1280888
## Andorra         0.45131879  0.28332454   0.6831372
## Angola         -1.54618516 -0.05761135  -0.2364336
promedio1$Pais=row.names(promedio1)
row.names(promedio1) = NULL

Análisis factorial de salud

salud1_X=salud1
row.names(salud1) = salud1$Pais
salud1$Pais = NULL
head(salud1)
##                        VidaM CobARet
## Afghanistan         59.71540      NA
## Albania             78.16240     6.2
## Algeria             74.10120    14.6
## Angola              55.38620     1.4
## Antigua and Barbuda 76.90380      NA
## Arab World          70.78677      NA
salud1[is.na(salud1$VidaM), "VidaM"]=mean(salud1$VidaM, na.rm=T)
salud1[is.na(salud1$CobARet), "CobARet"]=mean(salud1$CobARet, na.rm=T)
salud1=as.data.frame(scale(salud1[,c(1,2)]))
head(salud1)
##                            VidaM     CobARet
## Afghanistan         -1.133702486  0.00000000
## Albania              0.739051823 -0.64026360
## Algeria              0.326755526 -0.05502504
## Angola              -1.573206359 -0.97468563
## Antigua and Barbuda  0.611277737  0.00000000
## Arab World          -0.009727659  0.00000000
library(psych)
puntaje1 = cor(salud1) #sacar la correlación de los puntajes estandarizadas
puntaje1
##             VidaM   CobARet
## VidaM   1.0000000 0.4826546
## CobARet 0.4826546 1.0000000
cor.plot(puntaje1, 
         numbers=T, 
         upper=FALSE, 
         main = "Correlation", 
         show.legend = FALSE) #verlo en un gráfico

KMO(salud1) #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 = salud1)
## Overall MSA =  0.5
## MSA for each item = 
##   VidaM CobARet 
##     0.5     0.5
fa.parallel(puntaje1, fm="pa", fa="fa", main = "Scree Plot",n.obs = nrow(salud1)) #cuantos indices deberia formar

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

#Para ver el tipo de análisis factorial:
# mientras mas grande mejor (lo que aporta)
sort(salud1$communalities)
##     VidaM   CobARet 
## 0.4826546 0.4826546
# mientras mas grande peor (lo que mantiene)
sort(salud1$uniquenesses)
##     VidaM   CobARet 
## 0.5173454 0.5173454
sort(salud1$complexity)
##   VidaM CobARet 
##       1       1
salud1$scores
##                                                               MR1
## Afghanistan                                          -0.531223568
## Albania                                               0.046289599
## Algeria                                               0.127325856
## Angola                                               -1.193876075
## Antigua and Barbuda                                   0.286428886
## Arab World                                           -0.004558128
## Argentina                                             1.136605835
## Armenia                                              -0.250722761
## Aruba                                                 0.277495237
## Australia                                             1.816622019
## Austria                                               1.746740690
## Azerbaijan                                           -0.446383479
## Bahamas, The                                          0.435434166
## Bahrain                                               0.263627063
## Bangladesh                                           -0.594973180
## Barbados                                              0.976052458
## Belarus                                              -0.037640984
## Belgium                                               0.526952398
## Belize                                               -0.084709744
## Benin                                                -1.077452549
## Bermuda                                               0.499361789
## Bhutan                                               -0.279283252
## Bolivia                                              -0.678960846
## Bosnia and Herzegovina                                0.329260928
## Botswana                                             -0.695994685
## Brazil                                                0.825928745
## Brunei Darussalam                                     0.337909157
## Bulgaria                                              0.492009979
## Burkina Faso                                         -1.065722512
## Burundi                                              -1.079721209
## Cabo Verde                                           -0.195891973
## Cambodia                                             -0.248401824
## Cameroon                                             -1.165292105
## Canada                                                0.554543007
## Caribbean small states                                0.153951841
## Central African Republic                             -1.648226807
## Central Europe and the Baltics                        0.336295082
## Chad                                                 -1.441149955
## Channel Islands                                       0.487478799
## Chile                                                 2.008619424
## China                                                 0.221505329
## Colombia                                             -0.048372110
## Comoros                                              -0.868593956
## Congo, Dem. Rep.                                     -1.188587936
## Congo, Rep.                                          -1.110690571
## Costa Rica                                            0.745081791
## Cote d'Ivoire                                        -1.347554179
## Croatia                                               0.383481231
## Cuba                                                  0.679105473
## Curacao                                               0.374252648
## Cyprus                                                1.123172427
## Czech Republic                                        1.442572154
## Denmark                                               1.516128510
## Djibouti                                             -0.950432434
## Dominican Republic                                   -0.219300325
## Early-demographic dividend                           -0.150445711
## East Asia & Pacific                                   0.213396793
## East Asia & Pacific (excluding high income)           0.160686354
## East Asia & Pacific (IDA & IBRD countries)            0.162369841
## Ecuador                                              -0.045767225
## Egypt, Arab Rep.                                     -0.405086485
## El Salvador                                           0.176765861
## Equatorial Guinea                                    -1.152752955
## Eritrea                                              -0.832730127
## Estonia                                               0.093521685
## Eswatini                                             -1.289354093
## Ethiopia                                             -0.991857074
## Euro area                                             0.557465684
## Europe & Central Asia                                 0.348775182
## Europe & Central Asia (excluding high income)         0.136991308
## Europe & Central Asia (IDA & IBRD countries)          0.162594996
## European Union                                        0.506593020
## Faroe Islands                                         0.526000998
## Fiji                                                  0.021397302
## Finland                                               0.548834605
## Fragile and conflict affected situations             -0.522476279
## France                                                2.233242721
## French Polynesia                                      0.281196184
## Gabon                                                -0.621277868
## Gambia, The                                          -1.015193583
## Georgia                                              -0.086135140
## Germany                                               2.014868172
## Ghana                                                -0.991006365
## Greece                                                1.522321820
## Greenland                                             0.043545901
## Grenada                                               0.139171146
## Guam                                                  0.406923735
## Guatemala                                             0.058762705
## Guinea                                               -1.228136671
## Guinea-Bissau                                        -1.264182912
## Guyana                                                0.030613334
## Haiti                                                -0.788298757
## Heavily indebted poor countries (HIPC)               -0.671600820
## High income                                           0.509147448
## Honduras                                              0.049510519
## Hong Kong SAR, China                                  0.668711044
## Hungary                                               0.944261599
## IBRD only                                             0.053640720
## Iceland                                               0.581182216
## IDA & IBRD total                                     -0.078103905
## IDA blend                                            -0.607383275
## IDA only                                             -0.489339559
## IDA total                                            -0.527963387
## India                                                -0.701492628
## Indonesia                                            -0.562927395
## Iran, Islamic Rep.                                   -0.358385842
## Iraq                                                  0.008334576
## Ireland                                               1.857774963
## Israel                                                0.541223403
## Italy                                                 1.484023077
## Jamaica                                              -0.118597895
## Japan                                                 1.871170737
## Jordan                                                0.157533172
## Kazakhstan                                           -0.388250968
## Kenya                                                -0.951841847
## Kiribati                                             -0.144555454
## Korea, Dem. People’s Rep.                             0.034288776
## Korea, Rep.                                           0.511729993
## Kosovo                                                0.003682228
## Kuwait                                                2.062804848
## Kyrgyz Republic                                      -0.423014465
## Lao PDR                                              -0.707901162
## Late-demographic dividend                             0.223937384
## Latin America & Caribbean                             0.256480255
## Latin America & Caribbean (excluding high income)     0.237142353
## Latin America & the Caribbean (IDA & IBRD countries)  0.250725234
## Latvia                                                0.286248120
## Least developed countries: UN classification         -0.519093785
## Lebanon                                               0.429039473
## Lesotho                                              -1.408489722
## Liberia                                              -1.177488693
## Libya                                                 0.130580001
## Liechtenstein                                         0.600210222
## Lithuania                                            -0.012289095
## Low & middle income                                  -0.086007665
## Low income                                           -0.605906529
## Lower middle income                                  -0.236671017
## Luxembourg                                            1.805112027
## Macao SAR, China                                      0.636116069
## Madagascar                                           -0.887243354
## Malawi                                               -1.266635266
## Malaysia                                              0.011518846
## Maldives                                              0.224378558
## Mali                                                 -1.194080502
## Malta                                                 0.506021591
## Mauritania                                           -0.830770549
## Mauritius                                             0.237155864
## Mexico                                                0.641142284
## Micronesia, Fed. Sts.                                -0.106309162
## Middle East & North Africa                            0.099066974
## Middle East & North Africa (excluding high income)    0.078120053
## Middle East & North Africa (IDA & IBRD countries)     0.077658702
## Middle income                                        -0.027404434
## Moldova                                              -0.357086387
## Mongolia                                             -0.505037002
## Montenegro                                            0.593335394
## Morocco                                              -0.157634214
## Mozambique                                           -1.278797091
## Myanmar                                              -0.694994564
## Namibia                                              -0.848907283
## Nepal                                                -0.653252364
## Netherlands                                           1.679844135
## New Caledonia                                         0.387096553
## New Zealand                                           1.470218565
## Nicaragua                                            -0.233348239
## Niger                                                -1.237056537
## Nigeria                                              -1.436488093
## North America                                         0.452428819
## North Macedonia                                       0.013030596
## Norway                                                2.579758332
## OECD members                                          0.491026088
## Oman                                                  0.271177939
## Other small states                                   -0.364012688
## Pacific island small states                          -0.017075781
## Pakistan                                             -0.707142970
## Palau                                                 0.057912046
## Panama                                                0.430264157
## Papua New Guinea                                     -0.642356878
## Paraguay                                             -0.263644117
## Peru                                                 -0.109136401
## Philippines                                          -0.419045173
## Poland                                                0.403270358
## Portugal                                              1.121744350
## Post-demographic dividend                             0.507833903
## Pre-demographic dividend                             -0.760460376
## Puerto Rico                                           0.549405445
## Qatar                                                 1.609931278
## Romania                                               2.189087140
## Russian Federation                                   -0.299733353
## Rwanda                                               -0.845681366
## Samoa                                                 0.170472216
## Sao Tome and Principe                                -0.209773945
## Saudi Arabia                                          0.183972587
## Senegal                                              -0.792198828
## Serbia                                                1.342320787
## Seychelles                                            0.271025715
## Sierra Leone                                         -1.716780444
## Singapore                                             0.178774408
## Sint Maarten (Dutch part)                             0.286248120
## Slovak Republic                                       1.040259842
## Slovenia                                              0.920420235
## Small states                                         -0.232259117
## Solomon Islands                                      -0.162213444
## Somalia                                              -1.293614968
## South Africa                                         -1.110207003
## South Asia                                           -0.241991799
## South Asia (IDA & IBRD)                              -0.241991799
## South Sudan                                          -1.387028696
## Spain                                                 1.694730622
## Sri Lanka                                            -0.146130080
## St. Lucia                                             0.210706935
## St. Martin (French part)                              0.490799186
## St. Vincent and the Grenadines                        0.129229013
## Sub-Saharan Africa                                   -0.777661864
## Sub-Saharan Africa (excluding high income)           -0.777775639
## Sub-Saharan Africa (IDA & IBRD countries)            -0.777661864
## Sudan                                                -0.912118204
## Suriname                                             -0.104952250
## Sweden                                                0.565008410
## Switzerland                                           0.614481226
## Syrian Arab Republic                                  0.276610435
## Tajikistan                                           -0.501243844
## Tanzania                                             -1.014317989
## Thailand                                              0.242204151
## Timor-Leste                                          -0.256877774
## Togo                                                 -1.120817739
## Tonga                                                 0.154545775
## Trinidad and Tobago                                   0.107926134
## Tunisia                                               0.356074937
## Turkey                                                0.241798697
## Turkmenistan                                         -0.094644994
## Uganda                                               -1.040429046
## Ukraine                                              -0.304992281
## United Arab Emirates                                  0.282804051
## United Kingdom                                        0.489847786
## United States                                         0.441326370
## Upper middle income                                   0.190969536
## Uruguay                                               0.572336401
## Uzbekistan                                           -0.448759358
## Vanuatu                                               0.016278768
## Venezuela, RB                                         0.314019495
## Vietnam                                              -0.021868355
## Virgin Islands (U.S.)                                 0.479382383
## West Bank and Gaza                                    0.120485644
## World                                                -0.239476561
## Yemen, Rep.                                          -0.362502237
## Zambia                                               -1.163770229
## Zimbabwe                                             -1.545252176
puntaje1=as.data.frame(salud1$scores)
names(puntaje1) = c("Salud")
head(puntaje1)
##                            Salud
## Afghanistan         -0.531223568
## Albania              0.046289599
## Algeria              0.127325856
## Angola              -1.193876075
## Antigua and Barbuda  0.286428886
## Arab World          -0.004558128
puntaje1$Pais=row.names(puntaje1)
row.names(puntaje1) = NULL

Merge final e imputación a las variables faltantes

responsabilidad1 = merge(scores1, DataMetodos1, by= "Pais")
dendes1 = merge(responsabilidad1, promedio1, by= "Pais")
sal1 = merge(dendes1, puntaje1, by= "Pais")
movilidad1 = merge(sal1, migra1, by= "Pais")
movi1 = merge(movilidad1, ODA1, by= "Pais")
control1 = merge(movi1, women1, by= "Pais")
final1 = merge(control1, AFRICA, by= "Pais")
VIH1 = merge(final1, DataVIH1,by= "Pais")
VIH1[is.na(VIH1$Metodos), "Metodos"]=mean(VIH1$Metodos, na.rm=T)
VIH1[is.na(VIH1$Migracion), "Migracion"]=mean(VIH1$Migracion, na.rm=T)
VIH1[is.na(VIH1$ODA), "ODA"]=mean(VIH1$ODA, na.rm=T)
VIH1[is.na(VIH1$Women), "Women"]=mean(VIH1$Women, na.rm=T)
VIH1[is.na(VIH1$Africa), "Africa"]=mean(VIH1$Africa, na.rm=T)
## Warning in mean.default(VIH1$Africa, na.rm = T): argument is not numeric or
## logical: returning NA
VIH1$Metodos=scale(VIH1$Metodos)
VIH1$Migracion=scale(VIH1$Migracion)
VIH1$ODA=scale(VIH1$ODA)
VIH1$Women=scale(VIH1$Women)
VIH1=VIH1[-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",VIH1$Pais),] #Eliminamos los casos que no son países
row.names(VIH1)=NULL

Regresión

VIH1$VIH=VIH1$VIH/100
summary(VIH1)
##      Pais           Empoderamiento         Metodos.V1     
##  Length:90          Min.   :-2.1124   Min.   :-1.7936258  
##  Class :character   1st Qu.:-0.4316   1st Qu.:-0.7444031  
##  Mode  :character   Median : 0.1976   Median : 0.1163042  
##                     Mean   : 0.2201   Mean   : 0.0269795  
##                     3rd Qu.: 0.8666   3rd Qu.: 0.8617479  
##                     Max.   : 2.5421   Max.   : 2.2222902  
##     Densidad        Informacion       Desigualdad          Salud         
##  Min.   :-2.8179   Min.   :-1.1477   Min.   :-2.5624   Min.   :-1.71678  
##  1st Qu.:-1.5047   1st Qu.:-0.8537   1st Qu.:-1.0176   1st Qu.:-1.05940  
##  Median : 0.1479   Median :-0.4596   Median :-0.3533   Median :-0.53398  
##  Mean   :-0.3188   Mean   :-0.4443   Mean   :-0.3037   Mean   :-0.50162  
##  3rd Qu.: 0.6187   3rd Qu.:-0.0858   3rd Qu.: 0.4663   3rd Qu.:-0.08507  
##  Max.   : 1.4758   Max.   : 0.2532   Max.   : 1.1789   Max.   : 1.34232  
##     Migracion.V1           ODA.V1             Women.V1      
##  Min.   :-5.823900   Min.   :-0.885939   Min.   :-2.383372  
##  1st Qu.:-0.021024   1st Qu.:-0.778577   1st Qu.:-0.595795  
##  Median : 0.265644   Median :-0.341706   Median :-0.116951  
##  Mean   :-0.006229   Mean   : 0.001995   Mean   : 0.002270  
##  3rd Qu.: 0.381999   3rd Qu.: 0.466889   3rd Qu.: 0.392172  
##  Max.   : 1.635120   Max.   : 4.205506   Max.   : 3.287269  
##     Africa               VIH         
##  Length:90          Min.   :0.00100  
##  Class :character   1st Qu.:0.00100  
##  Mode  :character   Median :0.00200  
##                     Mean   :0.01488  
##                     3rd Qu.:0.01100  
##                     Max.   :0.21720
table(VIH1$Africa)
## 
## NO SI 
## 52 38
library(betareg)
modelo1=betareg(VIH ~ Empoderamiento + Metodos + Densidad + Desigualdad + Salud + Informacion + Migracion + ODA + Women + Africa,data=VIH1)
summary(modelo1)
## 
## Call:
## betareg(formula = VIH ~ Empoderamiento + Metodos + Densidad + Desigualdad + 
##     Salud + Informacion + Migracion + ODA + Women + Africa, data = VIH1)
## 
## Standardized weighted residuals 2:
##     Min      1Q  Median      3Q     Max 
## -2.4120 -0.6356 -0.0050  0.6321  3.9196 
## 
## Coefficients (mean model with logit link):
##                Estimate Std. Error z value Pr(>|z|)    
## (Intercept)    -5.94355    0.20460 -29.050  < 2e-16 ***
## Empoderamiento -0.16459    0.08228  -2.001 0.045443 *  
## Metodos         0.48632    0.15781   3.082 0.002059 ** 
## Densidad       -0.46753    0.13852  -3.375 0.000738 ***
## Desigualdad    -0.53010    0.09153  -5.791 6.98e-09 ***
## Salud          -1.45091    0.19841  -7.313 2.62e-13 ***
## Informacion    -0.05573    0.17983  -0.310 0.756655    
## Migracion       0.38492    0.10307   3.734 0.000188 ***
## ODA            -0.36620    0.10634  -3.444 0.000574 ***
## Women           0.29142    0.08753   3.329 0.000871 ***
## AfricaSI        0.07138    0.18483   0.386 0.699346    
## 
## Phi coefficients (precision model with identity link):
##       Estimate Std. Error z value Pr(>|z|)    
## (phi)   126.92      22.15    5.73    1e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
## 
## Type of estimator: ML (maximum likelihood)
## Log-likelihood: 352.4 on 12 Df
## Pseudo R-squared: 0.6222
## Number of iterations: 53 (BFGS) + 8 (Fisher scoring)
library(margins)
(modelo1M = margins(modelo1))
## Average marginal effects
## betareg(formula = VIH ~ Empoderamiento + Metodos + Densidad +     Desigualdad + Salud + Informacion + Migracion + ODA + Women +     Africa, data = VIH1)
##  Empoderamiento Metodos  Densidad Desigualdad    Salud Informacion
##       -0.002342 0.00692 -0.006652   -0.007542 -0.02064  -0.0007929
##  Migracion      ODA    Women AfricaSI
##   0.005477 -0.00521 0.004146 0.001007
resultado = summary(modelo1M)
#salen los limites de su error 
bet=summary(modelo1M) 

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))

Mapa de Similitudes

VIH1_x=VIH1
row.names(VIH1_x) = VIH1_x$Pais
VIH1_x$Pais=NULL
head(VIH1_x) #resultado final
##            Empoderamiento   Metodos   Densidad Informacion Desigualdad
## Albania       -0.74741919 0.6753870  0.4732899  -1.1410398   1.1788618
## Algeria       -1.22463238 0.7314029  0.6353829  -1.0661872   0.7546057
## Argentina      0.00458265 1.4854644  1.2662440  -0.4575426  -0.9427860
## Armenia       -0.31023875 0.3737624  0.5278865  -0.9439612   0.9635563
## Azerbaijan     0.30285455 0.2875839  0.5825904  -0.8728966   0.7865296
## Bangladesh    -1.47273276 0.5482737 -1.4759396  -0.2257567   0.7649945
##                 Salud   Migracion        ODA      Women Africa   VIH
## Albania     0.0462896  0.01754680 -0.3312780 -0.6752982     NO 0.001
## Algeria     0.1273259 -0.22628024 -0.8194162 -1.0730844     SI 0.001
## Argentina   1.1366058  0.24809750 -0.8542239  0.6493450     NO 0.001
## Armenia    -0.2507228  0.07676433 -0.1883990  2.6460604     NO 0.001
## Azerbaijan -0.4463835  0.48947898 -0.5907136  0.2936687     NO 0.001
## Bangladesh -0.5949732 -5.82389983 -0.6128485 -1.4247675     NO 0.001
VIH1_x =dist(VIH1_x[-c(10)])
VIH1_map = cmdscale(VIH1_x,eig=TRUE, k=2) # k sugiere dimensiones
VIH1_map$GOF # mientras mas cerca a 1 mejor.
## [1] 0.6340295 0.6340295
titulo="Mapa de Similitudes entre paises"
x = VIH1_map$points[,1]
y = VIH1_map$points[,2]
plot(x, y, main=titulo)

plot(x, y, xlab="Dimensión 1", ylab="Dimensión 2", main=titulo, 
     type="n") # 'n' evita que se pongan los puntos.
# etiquetas y colores de los puntos
text(x, y,labels = rownames(VIH1_map$points),cex=1) 

VIH1_map_DF=as.data.frame(VIH1_map$points)
install.packages("ggrepel")
## Installing package into '/home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6'
## (as 'lib' is unspecified)
library(ggrepel)
base=ggplot(VIH1_map_DF,aes(x=V1,y=V2))
base+geom_point() + geom_text_repel(aes(label=row.names(VIH1_map_DF)),size=2.6)

Análisis de Conglomerados

Mapa de todas las variables (incluyendo las de control y la dependiente)

VIH1_x=VIH1
row.names(VIH1_x) = VIH1_x$Pais
VIH1_x$Pais=NULL
head(VIH1_x) #resultado final
##            Empoderamiento   Metodos   Densidad Informacion Desigualdad
## Albania       -0.74741919 0.6753870  0.4732899  -1.1410398   1.1788618
## Algeria       -1.22463238 0.7314029  0.6353829  -1.0661872   0.7546057
## Argentina      0.00458265 1.4854644  1.2662440  -0.4575426  -0.9427860
## Armenia       -0.31023875 0.3737624  0.5278865  -0.9439612   0.9635563
## Azerbaijan     0.30285455 0.2875839  0.5825904  -0.8728966   0.7865296
## Bangladesh    -1.47273276 0.5482737 -1.4759396  -0.2257567   0.7649945
##                 Salud   Migracion        ODA      Women Africa   VIH
## Albania     0.0462896  0.01754680 -0.3312780 -0.6752982     NO 0.001
## Algeria     0.1273259 -0.22628024 -0.8194162 -1.0730844     SI 0.001
## Argentina   1.1366058  0.24809750 -0.8542239  0.6493450     NO 0.001
## Armenia    -0.2507228  0.07676433 -0.1883990  2.6460604     NO 0.001
## Azerbaijan -0.4463835  0.48947898 -0.5907136  0.2936687     NO 0.001
## Bangladesh -0.5949732 -5.82389983 -0.6128485 -1.4247675     NO 0.001
VIH1_d = as.data.frame(scale(VIH1_x[,-c(10)])) #Estandarizamos y eliminamos la variable 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 
VIH1_d=dist(VIH1_d[c(1:10)]) 
#Pedimos el numero de grupos:
VIH1_clus=kmeans(VIH1_d,centers = 5) #El 5 hace referencia al numero de grupos que se piden
VIH1_clus$cluster
##             Albania             Algeria           Argentina 
##                   5                   5                   1 
##             Armenia          Azerbaijan          Bangladesh 
##                   5                   5                   3 
##             Belarus              Belize               Benin 
##                   5                   1                   2 
##             Bolivia            Botswana              Brazil 
##                   1                   4                   1 
##        Burkina Faso             Burundi          Cabo Verde 
##                   2                   4                   1 
##            Cambodia            Cameroon                Chad 
##                   2                   2                   2 
##            Colombia    Congo, Dem. Rep.         Congo, Rep. 
##                   1                   2                   2 
##          Costa Rica       Cote d'Ivoire                Cuba 
##                   1                   2                   1 
##  Dominican Republic             Ecuador    Egypt, Arab Rep. 
##                   1                   1                   1 
##         El Salvador            Eswatini            Ethiopia 
##                   5                   3                   2 
##             Georgia               Ghana              Guinea 
##                   5                   2                   2 
##       Guinea-Bissau              Guyana               Haiti 
##                   2                   1                   2 
##            Honduras               India           Indonesia 
##                   1                   3                   1 
##  Iran, Islamic Rep.          Kazakhstan               Kenya 
##                   1                   5                   2 
##     Kyrgyz Republic             Lao PDR             Lebanon 
##                   5                   2                   1 
##             Lesotho             Liberia          Madagascar 
##                   4                   4                   2 
##              Malawi            Malaysia                Mali 
##                   4                   1                   2 
##          Mauritania              Mexico             Moldova 
##                   2                   1                   5 
##            Mongolia          Montenegro             Morocco 
##                   5                   1                   1 
##          Mozambique             Myanmar             Namibia 
##                   4                   2                   4 
##               Nepal           Nicaragua               Niger 
##                   2                   1                   2 
##             Nigeria            Pakistan    Papua New Guinea 
##                   2                   5                   2 
##            Paraguay                Peru         Philippines 
##                   1                   1                   1 
##              Rwanda             Senegal              Serbia 
##                   4                   2                   5 
##        Sierra Leone        South Africa           Sri Lanka 
##                   4                   4                   1 
##               Sudan            Suriname          Tajikistan 
##                   2                   1                   5 
##            Tanzania            Thailand                Togo 
##                   2                   1                   2 
## Trinidad and Tobago             Tunisia              Uganda 
##                   1                   1                   2 
##             Ukraine             Uruguay          Uzbekistan 
##                   5                   1                   5 
##             Vietnam              Zambia            Zimbabwe 
##                   1                   2                   4
#Para ver la cantidad de paises en cada grupo:
table(VIH1_clus$cluster)
## 
##  1  2  3  4  5 
## 31 29  3 11 16
#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:
grupos1=as.data.frame(VIH1_clus$cluster)
grupos1
##                     VIH1_clus$cluster
## Albania                             5
## Algeria                             5
## Argentina                           1
## Armenia                             5
## Azerbaijan                          5
## Bangladesh                          3
## Belarus                             5
## Belize                              1
## Benin                               2
## Bolivia                             1
## Botswana                            4
## Brazil                              1
## Burkina Faso                        2
## Burundi                             4
## Cabo Verde                          1
## Cambodia                            2
## Cameroon                            2
## Chad                                2
## Colombia                            1
## Congo, Dem. Rep.                    2
## Congo, Rep.                         2
## Costa Rica                          1
## Cote d'Ivoire                       2
## Cuba                                1
## Dominican Republic                  1
## Ecuador                             1
## Egypt, Arab Rep.                    1
## El Salvador                         5
## Eswatini                            3
## Ethiopia                            2
## Georgia                             5
## Ghana                               2
## Guinea                              2
## Guinea-Bissau                       2
## Guyana                              1
## Haiti                               2
## Honduras                            1
## India                               3
## Indonesia                           1
## Iran, Islamic Rep.                  1
## Kazakhstan                          5
## Kenya                               2
## Kyrgyz Republic                     5
## Lao PDR                             2
## Lebanon                             1
## Lesotho                             4
## Liberia                             4
## Madagascar                          2
## Malawi                              4
## Malaysia                            1
## Mali                                2
## Mauritania                          2
## Mexico                              1
## Moldova                             5
## Mongolia                            5
## Montenegro                          1
## Morocco                             1
## Mozambique                          4
## Myanmar                             2
## Namibia                             4
## Nepal                               2
## Nicaragua                           1
## Niger                               2
## Nigeria                             2
## Pakistan                            5
## Papua New Guinea                    2
## Paraguay                            1
## Peru                                1
## Philippines                         1
## Rwanda                              4
## Senegal                             2
## Serbia                              5
## Sierra Leone                        4
## South Africa                        4
## Sri Lanka                           1
## Sudan                               2
## Suriname                            1
## Tajikistan                          5
## Tanzania                            2
## Thailand                            1
## Togo                                2
## Trinidad and Tobago                 1
## Tunisia                             1
## Uganda                              2
## Ukraine                             5
## Uruguay                             1
## Uzbekistan                          5
## Vietnam                             1
## Zambia                              2
## Zimbabwe                            4
names(grupos1)='cluster'
grupos1$NAME=row.names(grupos1)
head(grupos1)
##            cluster       NAME
## Albania          5    Albania
## Algeria          5    Algeria
## Argentina        1  Argentina
## Armenia          5    Armenia
## Azerbaijan       5 Azerbaijan
## Bangladesh       3 Bangladesh
#Creamos el objeto final:
mapamundo_VIH1=merge(mapamundo,grupos1)
library("RColorBrewer")
plot(mapamundo,col='gray',border=NA) 
plot(mapamundo,
     col=brewer.pal(n = 5, name = "Set2")[mapamundo_VIH1$cluster],
     border='gray',add=T)

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

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


title="Clusters"

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

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

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

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

layer_12345= layer_1234%>%addPolygons(data=c5,color="tomato",fillOpacity = 1,stroke = F,
                              group = "5")
layer_12345
layer_12345%>% addLayersControl(
        overlayGroups = c("1", "2","3","4","5"),
        options = layersControlOptions(collapsed = FALSE)) 
VIH1_x=merge(VIH1_x, grupos1[-2], by=0)
row.names(VIH1_x) = VIH1_x$Row.names
VIH1_x=VIH1_x[-1]
head(VIH1_x)
##            Empoderamiento   Metodos   Densidad Informacion Desigualdad
## Albania       -0.74741919 0.6753870  0.4732899  -1.1410398   1.1788618
## Algeria       -1.22463238 0.7314029  0.6353829  -1.0661872   0.7546057
## Argentina      0.00458265 1.4854644  1.2662440  -0.4575426  -0.9427860
## Armenia       -0.31023875 0.3737624  0.5278865  -0.9439612   0.9635563
## Azerbaijan     0.30285455 0.2875839  0.5825904  -0.8728966   0.7865296
## Bangladesh    -1.47273276 0.5482737 -1.4759396  -0.2257567   0.7649945
##                 Salud   Migracion        ODA      Women Africa   VIH
## Albania     0.0462896  0.01754680 -0.3312780 -0.6752982     NO 0.001
## Algeria     0.1273259 -0.22628024 -0.8194162 -1.0730844     SI 0.001
## Argentina   1.1366058  0.24809750 -0.8542239  0.6493450     NO 0.001
## Armenia    -0.2507228  0.07676433 -0.1883990  2.6460604     NO 0.001
## Azerbaijan -0.4463835  0.48947898 -0.5907136  0.2936687     NO 0.001
## Bangladesh -0.5949732 -5.82389983 -0.6128485 -1.4247675     NO 0.001
##            cluster
## Albania          5
## Algeria          5
## Argentina        1
## Armenia          5
## Azerbaijan       5
## Bangladesh       3
agg1=aggregate(cbind(Empoderamiento,Metodos,Densidad,Informacion,Desigualdad,Salud,Migracion,ODA,Women,VIH) ~ cluster, data=VIH1_x,FUN=mean)
names(agg1)=c("cluster", "Empoderamiento","Metodos","Densidad","DesarrolloTecno","Desigualdad","Salud","Migracion", "ODA", "Women","VIH")
agg1
##   cluster Empoderamiento    Metodos   Densidad DesarrolloTecno Desigualdad
## 1       1     -0.3548007  0.8507184  0.8148660     -0.47705777  -0.4850922
## 2       2      0.8969817 -0.9414249 -1.5074389     -0.33230315  -0.4234698
## 3       3     -1.0522169  0.4114654 -0.9443295     -0.09327713  -0.1013467
## 4       4      1.0094246 -0.4619728 -1.3379853     -0.16895572  -1.2115162
## 5       5     -0.1969331  0.4502816  0.4573547     -0.83902038   0.8511718
##         Salud   Migracion        ODA      Women         VIH
## 1  0.07629879  0.06216519 -0.5236006 -0.3123196 0.002167742
## 2 -1.00648177  0.03956145  0.4115030 -0.1910575 0.013303448
## 3 -0.86193997 -3.37249651 -0.7179959 -0.8676613 0.073066667
## 4 -1.17945045  0.46550216  1.1246357  0.5304265 0.058727273
## 5 -0.17273172  0.08512182 -0.3587131  0.7621978 0.001337500

Mapa de las variables significativas

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

VIH_Sig=VIH1_x
VIH_Sig=VIH_Sig[-c(4,10)]
VIH1_ds = as.data.frame(scale(VIH_Sig)) #Estandarizamos 
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 
VIH1_ds=dist(VIH1_ds[c(1:9)]) 
#Pedimos el numero de grupos:
VIH1s_clus=kmeans(VIH1_ds,centers = 5) #El 5 hace referencia al numero de grupos que se piden
VIH1s_clus$cluster
##             Albania             Algeria           Argentina 
##                   1                   1                   1 
##             Armenia          Azerbaijan          Bangladesh 
##                   5                   1                   3 
##             Belarus              Belize               Benin 
##                   5                   1                   2 
##             Bolivia            Botswana              Brazil 
##                   1                   4                   1 
##        Burkina Faso             Burundi          Cabo Verde 
##                   2                   4                   1 
##            Cambodia            Cameroon                Chad 
##                   2                   2                   2 
##            Colombia    Congo, Dem. Rep.         Congo, Rep. 
##                   1                   2                   2 
##          Costa Rica       Cote d'Ivoire                Cuba 
##                   1                   2                   1 
##  Dominican Republic             Ecuador    Egypt, Arab Rep. 
##                   1                   1                   1 
##         El Salvador            Eswatini            Ethiopia 
##                   1                   3                   2 
##             Georgia               Ghana              Guinea 
##                   5                   2                   2 
##       Guinea-Bissau              Guyana               Haiti 
##                   2                   1                   2 
##            Honduras               India           Indonesia 
##                   1                   3                   1 
##  Iran, Islamic Rep.          Kazakhstan               Kenya 
##                   1                   5                   2 
##     Kyrgyz Republic             Lao PDR             Lebanon 
##                   1                   2                   1 
##             Lesotho             Liberia          Madagascar 
##                   4                   4                   2 
##              Malawi            Malaysia                Mali 
##                   4                   1                   2 
##          Mauritania              Mexico             Moldova 
##                   2                   1                   5 
##            Mongolia          Montenegro             Morocco 
##                   1                   1                   1 
##          Mozambique             Myanmar             Namibia 
##                   4                   2                   4 
##               Nepal           Nicaragua               Niger 
##                   2                   1                   2 
##             Nigeria            Pakistan    Papua New Guinea 
##                   2                   5                   2 
##            Paraguay                Peru         Philippines 
##                   1                   1                   1 
##              Rwanda             Senegal              Serbia 
##                   4                   2                   5 
##        Sierra Leone        South Africa           Sri Lanka 
##                   4                   4                   1 
##               Sudan            Suriname          Tajikistan 
##                   2                   1                   1 
##            Tanzania            Thailand                Togo 
##                   2                   1                   2 
## Trinidad and Tobago             Tunisia              Uganda 
##                   1                   1                   2 
##             Ukraine             Uruguay          Uzbekistan 
##                   5                   1                   1 
##             Vietnam              Zambia            Zimbabwe 
##                   1                   2                   4
#Para ver la cantidad de paises en cada grupo:
table(VIH1s_clus$cluster)
## 
##  1  2  3  4  5 
## 39 29  3 11  8
#Creamos un objeto (cluster) que mezcla la informacion de los grupos con el mapa:
grupos1s=as.data.frame(VIH1s_clus$cluster)
grupos1s
##                     VIH1s_clus$cluster
## Albania                              1
## Algeria                              1
## Argentina                            1
## Armenia                              5
## Azerbaijan                           1
## Bangladesh                           3
## Belarus                              5
## Belize                               1
## Benin                                2
## Bolivia                              1
## Botswana                             4
## Brazil                               1
## Burkina Faso                         2
## Burundi                              4
## Cabo Verde                           1
## Cambodia                             2
## Cameroon                             2
## Chad                                 2
## Colombia                             1
## Congo, Dem. Rep.                     2
## Congo, Rep.                          2
## Costa Rica                           1
## Cote d'Ivoire                        2
## Cuba                                 1
## Dominican Republic                   1
## Ecuador                              1
## Egypt, Arab Rep.                     1
## El Salvador                          1
## Eswatini                             3
## Ethiopia                             2
## Georgia                              5
## Ghana                                2
## Guinea                               2
## Guinea-Bissau                        2
## Guyana                               1
## Haiti                                2
## Honduras                             1
## India                                3
## Indonesia                            1
## Iran, Islamic Rep.                   1
## Kazakhstan                           5
## Kenya                                2
## Kyrgyz Republic                      1
## Lao PDR                              2
## Lebanon                              1
## Lesotho                              4
## Liberia                              4
## Madagascar                           2
## Malawi                               4
## Malaysia                             1
## Mali                                 2
## Mauritania                           2
## Mexico                               1
## Moldova                              5
## Mongolia                             1
## Montenegro                           1
## Morocco                              1
## Mozambique                           4
## Myanmar                              2
## Namibia                              4
## Nepal                                2
## Nicaragua                            1
## Niger                                2
## Nigeria                              2
## Pakistan                             5
## Papua New Guinea                     2
## Paraguay                             1
## Peru                                 1
## Philippines                          1
## Rwanda                               4
## Senegal                              2
## Serbia                               5
## Sierra Leone                         4
## South Africa                         4
## Sri Lanka                            1
## Sudan                                2
## Suriname                             1
## Tajikistan                           1
## Tanzania                             2
## Thailand                             1
## Togo                                 2
## Trinidad and Tobago                  1
## Tunisia                              1
## Uganda                               2
## Ukraine                              5
## Uruguay                              1
## Uzbekistan                           1
## Vietnam                              1
## Zambia                               2
## Zimbabwe                             4
names(grupos1s)='cluster'
grupos1s$NAME=row.names(grupos1s)
head(grupos1s)
##            cluster       NAME
## Albania          1    Albania
## Algeria          1    Algeria
## Argentina        1  Argentina
## Armenia          5    Armenia
## Azerbaijan       1 Azerbaijan
## Bangladesh       3 Bangladesh
#Creamos el objeto final:
mapamundo_VIH1s=merge(mapamundo,grupos1s)
library("RColorBrewer")
plot(mapamundo,col='gray',border=NA) 
plot(mapamundo,
     col=brewer.pal(n = 5, name = "Accent")[mapamundo_VIH1s$cluster],
     border='gray',add=T)

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

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


title="Clusters"

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

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

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

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

layer_12345= layer_1234%>%addPolygons(data=c5,color="turquoise",fillOpacity = 1,stroke = F,
                              group = "5")
layer_12345
layer_12345%>% addLayersControl(
        overlayGroups = c("1", "2","3","4","5"),
        options = layersControlOptions(collapsed = FALSE)) 
agg12=aggregate(cbind(Empoderamiento,Metodos,Densidad,Desigualdad,Salud,Migracion,VIH) ~ cluster, data=VIH1_x,FUN=mean)
names(agg12)=c("cluster","Empoderamiento","Metodos","Densidad","Desigualdad","Salud","Migracion","VIH")
agg12
##   cluster Empoderamiento    Metodos   Densidad Desigualdad       Salud
## 1       1     -0.3548007  0.8507184  0.8148660  -0.4850922  0.07629879
## 2       2      0.8969817 -0.9414249 -1.5074389  -0.4234698 -1.00648177
## 3       3     -1.0522169  0.4114654 -0.9443295  -0.1013467 -0.86193997
## 4       4      1.0094246 -0.4619728 -1.3379853  -1.2115162 -1.17945045
## 5       5     -0.1969331  0.4502816  0.4573547   0.8511718 -0.17273172
##     Migracion         VIH
## 1  0.06216519 0.002167742
## 2  0.03956145 0.013303448
## 3 -3.37249651 0.073066667
## 4  0.46550216 0.058727273
## 5  0.08512182 0.001337500

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 Uso de métodos anticonceptivos.

VIH_H1=VIH1_x[c(1,2,11)]
VIH1_dH1 = as.data.frame(scale(VIH_H1)) #Estandarizamos y nos quedamos con las variables de la hipótesis y la dependiente
set.seed(15) #Para que todos los grupos tengan el mismo punto de inicio, el 15 es inventado

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

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

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


title="Clusters"

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

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

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

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

layer_12345= layer_1234%>%addPolygons(data=c5,color="mediumvioletred",fillOpacity = 1,stroke = F,
                              group = "5")
layer_12345
layer_12345%>% addLayersControl(
        overlayGroups = c("1", "2","3","4","5"),
        options = layersControlOptions(collapsed = FALSE)) 
agg1H=aggregate(cbind(Empoderamiento,Metodos,VIH) ~ cluster, data=VIH1_x,FUN=mean)
names(agg1H)=c("cluster","Empoderamiento","Metodos","VIH")
agg1H
##   cluster Empoderamiento    Metodos         VIH
## 1       1     -0.3548007  0.8507184 0.002167742
## 2       2      0.8969817 -0.9414249 0.013303448
## 3       3     -1.0522169  0.4114654 0.073066667
## 4       4      1.0094246 -0.4619728 0.058727273
## 5       5     -0.1969331  0.4502816 0.001337500
Calidad de vida

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

VIH_H2=VIH1_x[c(3,5,6,11)]
VIH1_dH2 = as.data.frame(scale(VIH_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 
VIH1_dH2=dist(VIH1_dH2[c(1:4)])
#Pedimos las distancias como un criterio de agrupamiento
#Pedimos el numero de grupos:
VIH1H2_clus=kmeans(VIH1_dH2,centers = 5) #El 5 hace referencia al numero de grupos que se piden
VIH1H2_clus$cluster
##             Albania             Algeria           Argentina 
##                   5                   5                   1 
##             Armenia          Azerbaijan          Bangladesh 
##                   5                   5                   2 
##             Belarus              Belize               Benin 
##                   5                   3                   2 
##             Bolivia            Botswana              Brazil 
##                   3                   4                   1 
##        Burkina Faso             Burundi          Cabo Verde 
##                   2                   2                   3 
##            Cambodia            Cameroon                Chad 
##                   3                   2                   2 
##            Colombia    Congo, Dem. Rep.         Congo, Rep. 
##                   1                   2                   2 
##          Costa Rica       Cote d'Ivoire                Cuba 
##                   1                   2                   5 
##  Dominican Republic             Ecuador    Egypt, Arab Rep. 
##                   1                   1                   5 
##         El Salvador            Eswatini            Ethiopia 
##                   1                   4                   2 
##             Georgia               Ghana              Guinea 
##                   5                   3                   2 
##       Guinea-Bissau              Guyana               Haiti 
##                   2                   3                   2 
##            Honduras               India           Indonesia 
##                   1                   3                   3 
##  Iran, Islamic Rep.          Kazakhstan               Kenya 
##                   3                   5                   2 
##     Kyrgyz Republic             Lao PDR             Lebanon 
##                   5                   3                   5 
##             Lesotho             Liberia          Madagascar 
##                   4                   2                   2 
##              Malawi            Malaysia                Mali 
##                   2                   5                   2 
##          Mauritania              Mexico             Moldova 
##                   2                   1                   5 
##            Mongolia          Montenegro             Morocco 
##                   5                   5                   3 
##          Mozambique             Myanmar             Namibia 
##                   2                   3                   4 
##               Nepal           Nicaragua               Niger 
##                   3                   3                   2 
##             Nigeria            Pakistan    Papua New Guinea 
##                   2                   5                   2 
##            Paraguay                Peru         Philippines 
##                   1                   3                   3 
##              Rwanda             Senegal              Serbia 
##                   2                   3                   1 
##        Sierra Leone        South Africa           Sri Lanka 
##                   2                   4                   3 
##               Sudan            Suriname          Tajikistan 
##                   2                   1                   5 
##            Tanzania            Thailand                Togo 
##                   2                   1                   2 
## Trinidad and Tobago             Tunisia              Uganda 
##                   5                   5                   2 
##             Ukraine             Uruguay          Uzbekistan 
##                   5                   1                   5 
##             Vietnam              Zambia            Zimbabwe 
##                   5                   2                   4
#Para ver la cantidad de paises en cada grupo:
table(VIH1H2_clus$cluster)
## 
##  1  2  3  4  5 
## 14 30 18  6 22
#Creamos un objeto (cluster) que mezcla la informacion de los grupos con el mapa:
grupos1H2=as.data.frame(VIH1H2_clus$cluster)
grupos1H2
##                     VIH1H2_clus$cluster
## Albania                               5
## Algeria                               5
## Argentina                             1
## Armenia                               5
## Azerbaijan                            5
## Bangladesh                            2
## Belarus                               5
## Belize                                3
## Benin                                 2
## Bolivia                               3
## Botswana                              4
## Brazil                                1
## Burkina Faso                          2
## Burundi                               2
## Cabo Verde                            3
## Cambodia                              3
## Cameroon                              2
## Chad                                  2
## Colombia                              1
## Congo, Dem. Rep.                      2
## Congo, Rep.                           2
## Costa Rica                            1
## Cote d'Ivoire                         2
## Cuba                                  5
## Dominican Republic                    1
## Ecuador                               1
## Egypt, Arab Rep.                      5
## El Salvador                           1
## Eswatini                              4
## Ethiopia                              2
## Georgia                               5
## Ghana                                 3
## Guinea                                2
## Guinea-Bissau                         2
## Guyana                                3
## Haiti                                 2
## Honduras                              1
## India                                 3
## Indonesia                             3
## Iran, Islamic Rep.                    3
## Kazakhstan                            5
## Kenya                                 2
## Kyrgyz Republic                       5
## Lao PDR                               3
## Lebanon                               5
## Lesotho                               4
## Liberia                               2
## Madagascar                            2
## Malawi                                2
## Malaysia                              5
## Mali                                  2
## Mauritania                            2
## Mexico                                1
## Moldova                               5
## Mongolia                              5
## Montenegro                            5
## Morocco                               3
## Mozambique                            2
## Myanmar                               3
## Namibia                               4
## Nepal                                 3
## Nicaragua                             3
## Niger                                 2
## Nigeria                               2
## Pakistan                              5
## Papua New Guinea                      2
## Paraguay                              1
## Peru                                  3
## Philippines                           3
## Rwanda                                2
## Senegal                               3
## Serbia                                1
## Sierra Leone                          2
## South Africa                          4
## Sri Lanka                             3
## Sudan                                 2
## Suriname                              1
## Tajikistan                            5
## Tanzania                              2
## Thailand                              1
## Togo                                  2
## Trinidad and Tobago                   5
## Tunisia                               5
## Uganda                                2
## Ukraine                               5
## Uruguay                               1
## Uzbekistan                            5
## Vietnam                               5
## Zambia                                2
## Zimbabwe                              4
names(grupos1H2)='cluster'
grupos1H2$NAME=row.names(grupos1H2)
head(grupos1H2)
##            cluster       NAME
## Albania          5    Albania
## Algeria          5    Algeria
## Argentina        1  Argentina
## Armenia          5    Armenia
## Azerbaijan       5 Azerbaijan
## Bangladesh       2 Bangladesh
#Creamos el objeto final:
mapamundo_VIH1H2=merge(mapamundo,grupos1H2)
library("RColorBrewer")
plot(mapamundo,col='gray',border=NA) 
plot(mapamundo,
     col=brewer.pal(n = 5, name = "BrBG")[mapamundo_VIH1H2$cluster],
     border='gray',add=T)

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

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


title="Clusters"

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

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

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

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

layer_12345= layer_1234%>%addPolygons(data=c5,color="orange",fillOpacity = 1,stroke = F,
                              group = "5")
layer_12345
layer_12345%>% addLayersControl(
        overlayGroups = c("1", "2","3","4","5"),
        options = layersControlOptions(collapsed = FALSE)) 
agg1H2=aggregate(cbind(Densidad,Desigualdad,Salud,VIH) ~ cluster, data=VIH1_x,FUN=mean)
names(agg1H2)=c("cluster","Densidad","Desigualdad","Salud","VIH")
agg1H2
##   cluster   Densidad Desigualdad       Salud         VIH
## 1       1  0.8148660  -0.4850922  0.07629879 0.002167742
## 2       2 -1.5074389  -0.4234698 -1.00648177 0.013303448
## 3       3 -0.9443295  -0.1013467 -0.86193997 0.073066667
## 4       4 -1.3379853  -1.2115162 -1.17945045 0.058727273
## 5       5  0.4573547   0.8511718 -0.17273172 0.001337500
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

VIH_H3=VIH1_x[c(4,7,11)]
VIH1_dH3 = as.data.frame(scale(VIH_H3)) #Estandarizamos 
set.seed(15) #Para que todos los grupos tengan el mismo punto de inicio, el 15 es inventado

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

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

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


title="Clusters"

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

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

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

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

layer_12345= layer_1234%>%addPolygons(data=c5,color="lightgreen",fillOpacity = 1,stroke = F,
                              group = "5")
layer_12345
layer_12345%>% addLayersControl(
        overlayGroups = c("1", "2","3","4","5"),
        options = layersControlOptions(collapsed = FALSE)) 
agg1H3=aggregate(cbind(Informacion,Migracion,VIH) ~ cluster, data=VIH1_x,FUN=mean)
names(agg1H3)=c("cluster","DesarrolloTecno","Migracion","VIH")
agg1H3
##   cluster DesarrolloTecno   Migracion         VIH
## 1       1     -0.47705777  0.06216519 0.002167742
## 2       2     -0.33230315  0.03956145 0.013303448
## 3       3     -0.09327713 -3.37249651 0.073066667
## 4       4     -0.16895572  0.46550216 0.058727273
## 5       5     -0.83902038  0.08512182 0.001337500