About

This is an R notebook for:

Notes about this document

This code was not written well. It’s not easy to fix now without doing a lot of work and possibly affect results. As such, I leave it mainly as it was originally. It can serve as a historical reminder of how terrible my R coding was back then!

The old code was not written for an R notebook setup because to obtain the results without the federal district (FD), one has to run specific parts of the code in order. I changed this so that it outputs all the results, and it required rewriting and duplicating some code.

Initialize

Load packages.

#packages
library(pacman)
p_load(kirkegaard,plyr, VIM, gtools, reshape2, GGally)
options(digits = 2)

Data

Load and treat Wikipedia data.

#wikipedia data
d = read.csv("data.csv", header=TRUE, row.names=1, encoding="UTF-8"); d$State = rownames(d)

#names alfabetical?
d.alfa = arrange(d, State)
identical(rownames(d), d.alfa$State) #yes
## [1] TRUE
d$State = NULL #revemo redundant col

#calculate mean values
poverty.mean = apply(d[grep("Poverty", colnames(d))], 1, mean)
unemployment.mean = apply(d[grep("Unemploy", colnames(d))], 1, mean)
homocide.mean = apply(d[grep("Homicides", colnames(d))], 1, mean)
homicide.mean.per.cap = homocide.mean/d$Population
d$HDI.mean = apply(d[grep("HDI", colnames(d))], 1, mean)
infant.mortaility.per.cap = d$Infant.mortality.2006/d$Population

#make d2
d2 = data.frame(
  poverty.mean,
  unemployment.mean,
  homicide.mean.per.cap,
  infant.mortaility.per.cap,
  Fertility.Rate.2010=d$Fertility.Rate.2010,
  LE_2007_men=d$LE_2007_Men,
  LE_2007_women=d$LE_2007_Women,
  Lit.boys=d$Lit.boys,
  Lit.girls=d$Lit.girls,
  GDP.per.cap=d$GDP.Per.capita.2007.USD
)

#without FD
d_noFD = d[-10, ]
d2_noFD = d2[-10, ]

Load and treat INEG data.

#load data
n = read.csv("data2.csv", skip=1, header=TRUE, row.names=1, encoding = "UTF-8");n$State = rownames(n)

#does the order match?
n.alfa = arrange(n, State);rownames(n.alfa)=n.alfa$State #reordered version
#was initially alfabetical?
identical(rownames(n),n.alfa$State) #no
## [1] FALSE
n = n.alfa #replace old
#identical with first dataset after reorder?
identical(rownames(d),rownames(n)) #no
## [1] FALSE
#compare order
cbind(rownames(d),rownames(n)) #federal district in wrong place
##       [,1]                  [,2]                             
##  [1,] "Aguascalientes"      "Aguascalientes"                 
##  [2,] "Baja California"     "Baja California"                
##  [3,] "Baja California Sur" "Baja California Sur"            
##  [4,] "Campeche"            "Campeche"                       
##  [5,] "Chiapas"             "Chiapas"                        
##  [6,] "Chihuahua"           "Chihuahua"                      
##  [7,] "Coahuila"            "Coahuila de Zaragoza"           
##  [8,] "Colima"              "Colima"                         
##  [9,] "Durango"             "Distrito Federal"               
## [10,] "Federal District"    "Durango"                        
## [11,] "Guanajuato"          "Guanajuato"                     
## [12,] "Guerrero"            "Guerrero"                       
## [13,] "Hidalgo"             "Hidalgo"                        
## [14,] "Jalisco"             "Jalisco"                        
## [15,] "México"              "México"                         
## [16,] "Michoacán"           "Michoacán de Ocampo"            
## [17,] "Morelos"             "Morelos"                        
## [18,] "Nayarit"             "Nayarit"                        
## [19,] "Nuevo León"          "Nuevo León"                     
## [20,] "Oaxaca"              "Oaxaca"                         
## [21,] "Puebla"              "Puebla"                         
## [22,] "Querétaro"           "Querétaro"                      
## [23,] "Quintana Roo"        "Quintana Roo"                   
## [24,] "San Luis Potosí"     "San Luis Potosí"                
## [25,] "Sinaloa"             "Sinaloa"                        
## [26,] "Sonora"              "Sonora"                         
## [27,] "Tabasco"             "Tabasco"                        
## [28,] "Tamaulipas"          "Tamaulipas"                     
## [29,] "Tlaxcala"            "Tlaxcala"                       
## [30,] "Veracruz"            "Veracruz de Ignacio de la Llave"
## [31,] "Yucatán"             "Yucatán"                        
## [32,] "Zacatecas"           "Zacatecas"
n.new = n[c(1:8,10,9,11:32),]
cbind(rownames(d),rownames(n.new)) #worked? yes
##       [,1]                  [,2]                             
##  [1,] "Aguascalientes"      "Aguascalientes"                 
##  [2,] "Baja California"     "Baja California"                
##  [3,] "Baja California Sur" "Baja California Sur"            
##  [4,] "Campeche"            "Campeche"                       
##  [5,] "Chiapas"             "Chiapas"                        
##  [6,] "Chihuahua"           "Chihuahua"                      
##  [7,] "Coahuila"            "Coahuila de Zaragoza"           
##  [8,] "Colima"              "Colima"                         
##  [9,] "Durango"             "Durango"                        
## [10,] "Federal District"    "Distrito Federal"               
## [11,] "Guanajuato"          "Guanajuato"                     
## [12,] "Guerrero"            "Guerrero"                       
## [13,] "Hidalgo"             "Hidalgo"                        
## [14,] "Jalisco"             "Jalisco"                        
## [15,] "México"              "México"                         
## [16,] "Michoacán"           "Michoacán de Ocampo"            
## [17,] "Morelos"             "Morelos"                        
## [18,] "Nayarit"             "Nayarit"                        
## [19,] "Nuevo León"          "Nuevo León"                     
## [20,] "Oaxaca"              "Oaxaca"                         
## [21,] "Puebla"              "Puebla"                         
## [22,] "Querétaro"           "Querétaro"                      
## [23,] "Quintana Roo"        "Quintana Roo"                   
## [24,] "San Luis Potosí"     "San Luis Potosí"                
## [25,] "Sinaloa"             "Sinaloa"                        
## [26,] "Sonora"              "Sonora"                         
## [27,] "Tabasco"             "Tabasco"                        
## [28,] "Tamaulipas"          "Tamaulipas"                     
## [29,] "Tlaxcala"            "Tlaxcala"                       
## [30,] "Veracruz"            "Veracruz de Ignacio de la Llave"
## [31,] "Yucatán"             "Yucatán"                        
## [32,] "Zacatecas"           "Zacatecas"
n = n.new #replace with new

#Calculate means
GDP.change = apply(n[grep("GDP.change",colnames(n))], 1, mean)
cost.crime1 = apply(n[grep("cost.crime.\\d",colnames(n))], 1, mean)
cost.crime2 = apply(n[grep("Cost.crime2",colnames(n))], 1, mean)
crime.per.econ = apply(n[grep("Crime.rate.per.10k.econ",colnames(n))], 1, mean)
crime.rate.per.adult = apply(n[grep("Crime.rate.per.100k.adult",colnames(n))], 1, mean)
Dark.crime1 = apply(n[grep("Dark.crime.pct",colnames(n))], 1, mean)
Dark.crime2 = apply(n[grep("Dark.crime.2",colnames(n))], 1, mean)
Doctors.per.pers = apply(n[grep("Doctors.per",colnames(n))], 1, mean)
Econ.units = apply(n[grep("Econ.unit",colnames(n))], 1, mean)
Econ.active.15plus = apply(n[grep("Econ.active.\\d",colnames(n))], 1, mean)
Unemploy.15plus = apply(n[grep("Unemployed.\\d",colnames(n))], 1, mean)
Elec.users = apply(n[grep("Electricity.users.\\d",colnames(n))], 1, mean)
High.income = apply(n[grep("High.income.\\d",colnames(n))], 1, mean)
No.income.work = apply(n[grep("No.income.\\d",colnames(n))], 1, mean)
Low.income = apply(n[grep("Low.income.\\d",colnames(n))], 1, mean)
Fertility.teen = apply(n[grep("Fertility.rate.adol.\\d",colnames(n))], 1, mean)
Cervical.cancer.mort.rate = apply(n[grep("Cervical.cancer.\\d",colnames(n))], 1, mean)
Total.fertility = apply(n[grep("Total.fertility.\\d",colnames(n))], 1, mean)
Women.participation = apply(n[grep("Women.parti",colnames(n))], 1, mean)
Hospital.beds.per.pers = apply(n[grep("Hospital.beds.\\d",colnames(n))], 1, mean)
Households = apply(n[grep("Households.\\d",colnames(n))], 1, mean)
Has.computer = apply(n[grep("Households.computer.\\d",colnames(n))], 1, mean)
Has.toilet = apply(n[grep("Households.toilet.\\d",colnames(n))], 1, mean)
Has.refrig = apply(n[grep("Households.refrig.\\d",colnames(n))], 1, mean)
Has.water.net = apply(n[grep("Households.water.net.\\d",colnames(n))], 1, mean)
Has.drainage = apply(n[grep("Households.drainage.\\d",colnames(n))], 1, mean)
Has.elec = apply(n[grep("Households.elec.\\d",colnames(n))], 1, mean)
Has.wash.mach = apply(n[grep("Households.wash.mach.\\d",colnames(n))], 1, mean)
Has.tv = apply(n[grep("Households.tv.\\d",colnames(n))], 1, mean)
Prison.inmates = apply(n[grep("Prison.inmates.\\d",colnames(n))], 1, mean)
Life.expect = apply(n[grep("Life.expec.\\d",colnames(n))], 1, mean)
Lit.young.women = apply(n[grep("Lit.young.women.\\d",colnames(n))], 1, mean)
Lit.young.men = apply(n[grep("Lit.young.men.\\d",colnames(n))], 1, mean)
Median.age = apply(n[grep("Median.age.\\d",colnames(n))], 1, mean)
Nurses.per.pers = apply(n[grep("Nurses.per",colnames(n))], 1, mean)
Victims.crime.households = apply(n[grep("Victim.crime.households",colnames(n))], 1, mean)
Home.births.pct = apply(n[grep("Home.births",colnames(n))], 1, mean)
Prof.tech.employ.pct = apply(n[grep("Prof.tech",colnames(n))], 1, mean)
Piped.water.pct = apply(n[grep("Household.water",colnames(n))], 1, mean)
Elec.pct = apply(n[grep("Household.elec",colnames(n))], 1, mean)
Good.sani.prop = apply(n[grep("Good.sani",colnames(n))], 1, mean)
Good.water.prop = apply(n[grep("Good.water",colnames(n))], 1, mean)
Prisoner.rate = apply(n[grep("Prisoner.rate",colnames(n))], 1, mean)
Maternal.death.rate = apply(n[grep("Maternal.death",colnames(n))], 1, mean)
Unsafe.neighborhood.percept.rate = apply(n[grep("Neighborhood.unsafe",colnames(n))], 1, mean)
Unsafe.state.percept.rate = apply(n[grep("State.unsafe",colnames(n))], 1, mean)
Sentence.rate = apply(n[grep("Sentence.rate",colnames(n))], 1, mean)
GDP = apply(n[grep("GDP.\\d",colnames(n))], 1, mean)
Population = apply(n[grep("Population.\\d",colnames(n))], 1, mean)
Child.resp.death.rate = apply(n[grep("Child.death.resp.rate",colnames(n))], 1, mean)
Child.diar.death.rate = apply(n[grep("Child.death.diar.rate",colnames(n))], 1, mean)
Unemploy.men.rate = apply(n[grep("Unemploy.rate.men",colnames(n))], 1, mean)
Unemploy.women.rate = apply(n[grep("Unemploy.rate.women",colnames(n))], 1, mean)

#Per capita calculations
Cost.crime1.per.pers = cost.crime1/Population
Cost.crime2.per.pers = cost.crime2/Population
Econ.units.per.pers = Econ.units/Population
Elec.users.per.pers = Elec.users/Population
Households.per.pers = Households/Population
Inmates.per.pers = Prison.inmates/Population
GDP.per.pers = GDP/Population

#Per household calculations
Has.computer.per.household = Has.computer/Households
Has.toilet.per.household = Has.toilet/Households
Has.refrig.per.household = Has.refrig/Households
Has.water.net.per.hh = Has.water.net/Households
Has.drainage.per.hh = Has.drainage/Households
Has.elec.per.hh = Has.elec/Households
Has.wash.mach.per.hh = Has.wash.mach/Households
Has.tv.per.hh = Has.tv/Households

#Employment
Unemployed.15plus.peap = Unemploy.15plus/Econ.active.15plus
Low.income.peap = Low.income/Econ.active.15plus
High.income.peap = High.income/Econ.active.15plus
No.income.peap = No.income.work/Econ.active.15plus

s = data.frame( #select everything
  GDP.change,              #Economic
  Econ.units.per.pers,
  Unemployed.15plus.peap,
  Unemploy.men.rate,
  Unemploy.women.rate,
  Low.income.peap,
  High.income.peap,
  No.income.peap,
  Prof.tech.employ.pct,
  Cost.crime1.per.pers,    #Crime
  Cost.crime2.per.pers,
  Dark.crime1,
  Dark.crime2,
  crime.rate.per.adult,
  Sentence.rate,
  Inmates.per.pers,
  Prisoner.rate,
  Victims.crime.households,
  Unsafe.neighborhood.percept.rate,
  Unsafe.state.percept.rate,
  Has.computer.per.household, #Appliances and home
  Has.toilet.per.household,
  Has.refrig.per.household,
  Has.water.net.per.hh,
  Piped.water.pct,
  Good.water.prop,
  Has.drainage.per.hh,
  Good.sani.prop,
  Has.elec.per.hh,
  Elec.pct,
  Has.wash.mach.per.hh,
  Has.tv.per.hh,
  Doctors.per.pers,      #Health
  Nurses.per.pers,
  Hospital.beds.per.pers,
  Total.fertility,
  Fertility.teen,
  Home.births.pct,
  Maternal.death.rate,
  Cervical.cancer.mort.rate,
  Life.expect,
  Median.age,
  Child.resp.death.rate,
  Child.diar.death.rate,
  Women.participation,   #Gender equality
  Lit.young.women,       #education
  Lit.young.men
)

s2 = data.frame( #select chosen variables
  GDP.change,              #Economic
  Unemploy.men.rate,
  Unemploy.women.rate,
  Low.income.peap,
  High.income.peap,
  Prof.tech.employ.pct,
  crime.rate.per.adult,   #Crime
  Inmates.per.pers,
  Unsafe.neighborhood.percept.rate,
  Has.water.net.per.hh,  #Materials
  Elec.pct,
  Has.wash.mach.per.hh,
  Doctors.per.pers,      #Health
  Nurses.per.pers,
  Hospital.beds.per.pers,
  Total.fertility,
  Home.births.pct,
  Maternal.death.rate,
  Life.expect,
  Women.participation,   #Gender equality
  Lit.young.women        #education
)

s3 = remove_redundant_vars(s, threshold = 0.80)
## The following variable pairs had stronger intercorrelations than |0.8|:
##                            Var1                       Var2     r
## 1200            Piped.water.pct            Good.water.prop  1.00
## 1152       Has.water.net.per.hh            Piped.water.pct  1.00
## 1199       Has.water.net.per.hh            Good.water.prop  0.99
## 1728            Total.fertility             Fertility.teen  0.99
## 1296        Has.drainage.per.hh             Good.sani.prop  0.98
## 813        crime.rate.per.adult   Victims.crime.households  0.97
## 1584           Doctors.per.pers            Nurses.per.pers  0.96
## 1632            Nurses.per.pers     Hospital.beds.per.pers  0.94
## 1771              Has.tv.per.hh            Home.births.pct -0.94
## 2208            Lit.young.women              Lit.young.men  0.94
## 1392            Has.elec.per.hh                   Elec.pct  0.94
## 2153            Home.births.pct            Lit.young.women -0.93
## 1433   Has.refrig.per.household       Has.wash.mach.per.hh  0.93
## 768            Inmates.per.pers              Prisoner.rate  0.90
## 1764            Piped.water.pct            Home.births.pct -0.90
## 1765            Good.water.prop            Home.births.pct -0.90
## 1763       Has.water.net.per.hh            Home.births.pct -0.89
## 2200            Home.births.pct              Lit.young.men -0.89
## 192           Unemploy.men.rate        Unemploy.women.rate  0.89
## 767               Sentence.rate              Prisoner.rate  0.88
## 2089 Has.computer.per.household        Women.participation  0.88
## 1631           Doctors.per.pers     Hospital.beds.per.pers  0.87
## 1482            Piped.water.pct              Has.tv.per.hh  0.87
## 949        Prof.tech.employ.pct Has.computer.per.household  0.87
## 144      Unemployed.15plus.peap          Unemploy.men.rate  0.87
## 1483            Good.water.prop              Has.tv.per.hh  0.86
## 1486            Has.elec.per.hh              Has.tv.per.hh  0.86
## 1963            Total.fertility                 Median.age -0.86
## 1481       Has.water.net.per.hh              Has.tv.per.hh  0.86
## 2147              Has.tv.per.hh            Lit.young.women  0.86
## 1040            Low.income.peap   Has.refrig.per.household -0.86
## 1480   Has.refrig.per.household              Has.tv.per.hh  0.86
## 1488       Has.wash.mach.per.hh              Has.tv.per.hh  0.85
## 1343        Has.drainage.per.hh            Has.elec.per.hh  0.85
## 1770       Has.wash.mach.per.hh            Home.births.pct -0.85
## 1344             Good.sani.prop            Has.elec.per.hh  0.85
## 2044   Has.refrig.per.household      Child.diar.death.rate -0.85
## 1936       Prof.tech.employ.pct                 Median.age  0.85
## 1485             Good.sani.prop              Has.tv.per.hh  0.84
## 1277             No.income.peap             Good.sani.prop -0.84
## 946             Low.income.peap Has.computer.per.household -0.84
## 2187            Piped.water.pct              Lit.young.men  0.83
## 1487                   Elec.pct              Has.tv.per.hh  0.83
## 1391             Good.sani.prop                   Elec.pct  0.83
## 2186       Has.water.net.per.hh              Lit.young.men  0.83
## 2188            Good.water.prop              Lit.young.men  0.82
## 1390        Has.drainage.per.hh                   Elec.pct  0.82
## 1762   Has.refrig.per.household            Home.births.pct -0.82
## 1465             No.income.peap              Has.tv.per.hh -0.82
## 2194              Has.tv.per.hh              Lit.young.men  0.81
## 1964             Fertility.teen                 Median.age -0.81
## 1560       Prof.tech.employ.pct            Nurses.per.pers  0.81
## 1745            Low.income.peap            Home.births.pct  0.81
## 191      Unemployed.15plus.peap        Unemploy.women.rate  0.80
## 1905            Piped.water.pct                Life.expect  0.80
## 1607       Prof.tech.employ.pct     Hospital.beds.per.pers  0.80
## 1484        Has.drainage.per.hh              Has.tv.per.hh  0.80
## The following variables were excluded:
## Good.water.prop, Piped.water.pct, Fertility.teen, Good.sani.prop, Victims.crime.households, Nurses.per.pers, Home.births.pct, Lit.young.men, Elec.pct, Has.wash.mach.per.hh, Prisoner.rate, Unemploy.women.rate, Women.participation, Hospital.beds.per.pers, Has.computer.per.household, Unemploy.men.rate, Has.tv.per.hh, Median.age, Has.refrig.per.household, Has.elec.per.hh
#noFD variants
s_noFD = s[-10, ]
s2_noFD = s2[-10, ]
s3_noFD = remove_redundant_vars(s[-10, ], threshold = 0.80)
## The following variable pairs had stronger intercorrelations than |0.8|:
##                            Var1                       Var2     r
## 1200            Piped.water.pct            Good.water.prop  1.00
## 1152       Has.water.net.per.hh            Piped.water.pct  1.00
## 1199       Has.water.net.per.hh            Good.water.prop  0.99
## 1728            Total.fertility             Fertility.teen  0.98
## 1296        Has.drainage.per.hh             Good.sani.prop  0.98
## 813        crime.rate.per.adult   Victims.crime.households  0.97
## 1771              Has.tv.per.hh            Home.births.pct -0.94
## 2208            Lit.young.women              Lit.young.men  0.94
## 768            Inmates.per.pers              Prisoner.rate  0.94
## 1584           Doctors.per.pers            Nurses.per.pers  0.94
## 1392            Has.elec.per.hh                   Elec.pct  0.93
## 2153            Home.births.pct            Lit.young.women -0.93
## 1433   Has.refrig.per.household       Has.wash.mach.per.hh  0.92
## 1764            Piped.water.pct            Home.births.pct -0.90
## 1765            Good.water.prop            Home.births.pct -0.90
## 2200            Home.births.pct              Lit.young.men -0.89
## 1763       Has.water.net.per.hh            Home.births.pct -0.89
## 767               Sentence.rate              Prisoner.rate  0.88
## 1632            Nurses.per.pers     Hospital.beds.per.pers  0.88
## 192           Unemploy.men.rate        Unemploy.women.rate  0.88
## 946             Low.income.peap Has.computer.per.household -0.87
## 1482            Piped.water.pct              Has.tv.per.hh  0.86
## 144      Unemployed.15plus.peap          Unemploy.men.rate  0.86
## 2089 Has.computer.per.household        Women.participation  0.86
## 1483            Good.water.prop              Has.tv.per.hh  0.86
## 1486            Has.elec.per.hh              Has.tv.per.hh  0.86
## 1481       Has.water.net.per.hh              Has.tv.per.hh  0.86
## 2147              Has.tv.per.hh            Lit.young.women  0.86
## 1040            Low.income.peap   Has.refrig.per.household -0.85
## 1480   Has.refrig.per.household              Has.tv.per.hh  0.85
## 1488       Has.wash.mach.per.hh              Has.tv.per.hh  0.85
## 1770       Has.wash.mach.per.hh            Home.births.pct -0.85
## 720               Sentence.rate           Inmates.per.pers  0.85
## 2044   Has.refrig.per.household      Child.diar.death.rate -0.85
## 1343        Has.drainage.per.hh            Has.elec.per.hh  0.84
## 1043       Prof.tech.employ.pct   Has.refrig.per.household  0.84
## 1344             Good.sani.prop            Has.elec.per.hh  0.84
## 949        Prof.tech.employ.pct Has.computer.per.household  0.84
## 1277             No.income.peap             Good.sani.prop -0.84
## 1485             Good.sani.prop              Has.tv.per.hh  0.83
## 1419       Prof.tech.employ.pct       Has.wash.mach.per.hh  0.83
## 1055 Has.computer.per.household   Has.refrig.per.household  0.83
## 2187            Piped.water.pct              Lit.young.men  0.83
## 1487                   Elec.pct              Has.tv.per.hh  0.82
## 2186       Has.water.net.per.hh              Lit.young.men  0.82
## 2188            Good.water.prop              Lit.young.men  0.82
## 1762   Has.refrig.per.household            Home.births.pct -0.82
## 1391             Good.sani.prop                   Elec.pct  0.81
## 1465             No.income.peap              Has.tv.per.hh -0.81
## 1390        Has.drainage.per.hh                   Elec.pct  0.81
## 2194              Has.tv.per.hh              Lit.young.men  0.81
## 1745            Low.income.peap            Home.births.pct  0.80
## The following variables were excluded:
## Good.water.prop, Piped.water.pct, Fertility.teen, Good.sani.prop, Victims.crime.households, Home.births.pct, Lit.young.men, Prisoner.rate, Nurses.per.pers, Elec.pct, Has.wash.mach.per.hh, Unemploy.women.rate, Has.computer.per.household, Unemploy.men.rate, Has.tv.per.hh, Has.refrig.per.household, Inmates.per.pers, Has.elec.per.hh
#examine missing data
matrixplot(s, labels = substr(colnames(s), 1,8))

matrixplot(s2, labels = substr(colnames(s2), 1,8))

matrixplot(s3, labels = substr(colnames(s3), 1,8))

#impute
#s = irmi(s) #doesnt work becus too few cases
s2 = irmi(s2, noise = F)
s3 = irmi(s3, noise = F)
s2_noFD = irmi(s2_noFD, noise = F)
s3_noFD = irmi(s3_noFD, noise = F)
## No missings in x. Nothing to impute
## Warning in kNN_work(as.data.table(data), variable, metric, k, dist_var, :
## Nothing to impute, because no NA are present (also after using makeNA)

Analyses with FD

Wikipedia S analysis

The Wikipedia data S analysis.

#factor analysis
S.fa = fa(d2) #standard
S.fa_reg = S.fa$scores %>% as.vector
S.fa
## Factor Analysis using method =  minres
## Call: fa(r = d2)
## Standardized loadings (pattern matrix) based upon correlation matrix
##                             MR1     h2    u2 com
## poverty.mean              -0.80 0.6357 0.364   1
## unemployment.mean          0.71 0.5066 0.493   1
## homicide.mean.per.cap      0.09 0.0079 0.992   1
## infant.mortaility.per.cap -0.57 0.3212 0.679   1
## Fertility.Rate.2010       -0.47 0.2164 0.784   1
## LE_2007_men                0.74 0.5497 0.450   1
## LE_2007_women              0.72 0.5221 0.478   1
## Lit.boys                   0.99 0.9752 0.025   1
## Lit.girls                  0.99 0.9730 0.027   1
## GDP.per.cap                0.50 0.2500 0.750   1
## 
##                MR1
## SS loadings    5.0
## Proportion Var 0.5
## 
## Mean item complexity =  1
## Test of the hypothesis that 1 factor is sufficient.
## 
## The degrees of freedom for the null model are  45  and the objective function was  11 with Chi Square of  305
## The degrees of freedom for the model are 35  and the objective function was  4.1 
## 
## The root mean square of the residuals (RMSR) is  0.13 
## The df corrected root mean square of the residuals is  0.15 
## 
## The harmonic number of observations is  32 with the empirical chi square  52  with prob <  0.031 
## The total number of observations was  32  with Likelihood Chi Square =  107  with prob <  3.3e-09 
## 
## Tucker Lewis Index of factoring reliability =  0.63
## RMSEA index =  0.066  and the 90 % confidence intervals are  0.066 0.31
## BIC =  -14
## Fit based upon off diagonal values = 0.94
## Measures of factor score adequacy             
##                                                 MR1
## Correlation of scores with factors             0.99
## Multiple R square of scores with factors       0.99
## Minimum correlation of possible factor scores  0.97
fa_plot_loadings(S.fa)

ggsave("figures/S_wiki.png")
## Saving 7 x 5 in image
#factor analysis Bartlett's
S.fa = fa(d2, scores = "Bartlett") #Bartlett's
S.fa
## Factor Analysis using method =  minres
## Call: fa(r = d2, scores = "Bartlett")
## Standardized loadings (pattern matrix) based upon correlation matrix
##                             MR1     h2    u2 com
## poverty.mean              -0.80 0.6357 0.364   1
## unemployment.mean          0.71 0.5066 0.493   1
## homicide.mean.per.cap      0.09 0.0079 0.992   1
## infant.mortaility.per.cap -0.57 0.3212 0.679   1
## Fertility.Rate.2010       -0.47 0.2164 0.784   1
## LE_2007_men                0.74 0.5497 0.450   1
## LE_2007_women              0.72 0.5221 0.478   1
## Lit.boys                   0.99 0.9752 0.025   1
## Lit.girls                  0.99 0.9730 0.027   1
## GDP.per.cap                0.50 0.2500 0.750   1
## 
##                MR1
## SS loadings    5.0
## Proportion Var 0.5
## 
## Mean item complexity =  1
## Test of the hypothesis that 1 factor is sufficient.
## 
## The degrees of freedom for the null model are  45  and the objective function was  11 with Chi Square of  305
## The degrees of freedom for the model are 35  and the objective function was  4.1 
## 
## The root mean square of the residuals (RMSR) is  0.13 
## The df corrected root mean square of the residuals is  0.15 
## 
## The harmonic number of observations is  32 with the empirical chi square  52  with prob <  0.031 
## The total number of observations was  32  with Likelihood Chi Square =  107  with prob <  3.3e-09 
## 
## Tucker Lewis Index of factoring reliability =  0.63
## RMSEA index =  0.066  and the 90 % confidence intervals are  0.066 0.31
## BIC =  -14
## Fit based upon off diagonal values = 0.94
## Measures of factor score adequacy             
##                                                 MR1
## Correlation of scores with factors             0.99
## Multiple R square of scores with factors       0.99
## Minimum correlation of possible factor scores  0.97
fa_plot_loadings(S.fa)

ggsave("figures/S_wiki_Bartlett.png")
## Saving 7 x 5 in image
#insert into d2
d2$S.wiki =  as.vector(S.fa$scores)

d3 = data.frame(d, d2) #merge d and d2
d4 = subset(d3, select=c(
                S.wiki,
                HDI.mean,
                Achievement,
                Euro,
                Afri,
                Amer))

#correlations
wtd.cors(d3)
##                           Poverty.Rate.2012 Poverty.Rate.2010
## Poverty.Rate.2012                     1.000            0.9709
## Poverty.Rate.2010                     0.971            1.0000
## Unemployment.2010.1                  -0.673           -0.6113
## Unemployment.2010.2                  -0.673           -0.6162
## Unemployment.2010.3                  -0.669           -0.6019
## Unemployment.2010.4                  -0.589           -0.5290
## Fertility.Rate.2010                   0.480            0.4629
## Homicides..2011.                     -0.164           -0.1966
## Homicides..2010.                     -0.196           -0.1917
## Infant.mortality.2006                 0.357            0.3233
## LE_2007_Men                          -0.569           -0.5886
## LE_2007_Women                        -0.591           -0.6128
## Lit.boys                             -0.771           -0.7744
## Lit.girls                            -0.762           -0.7572
## GDP.Per.capita.2007.USD              -0.744           -0.7304
## HDI2015                              -0.865           -0.8520
## HDI2014                              -0.887           -0.8784
## Population                           -0.049           -0.0744
## Achievement                          -0.699           -0.7430
## Euro                                 -0.654           -0.6332
## Afri                                  0.043            0.0069
## Amer                                  0.678            0.6643
## HDI.mean                             -0.881           -0.8698
## poverty.mean                          0.992            0.9932
## unemployment.mean                    -0.665           -0.6026
## homicide.mean.per.cap                -0.133           -0.1621
## infant.mortaility.per.cap             0.701            0.6968
## Fertility.Rate.2010.1                 0.480            0.4629
## LE_2007_men                          -0.569           -0.5886
## LE_2007_women                        -0.591           -0.6128
## Lit.boys.1                           -0.771           -0.7744
## Lit.girls.1                          -0.762           -0.7572
## GDP.per.cap                          -0.744           -0.7304
## S.wiki                               -0.790           -0.7889
##                           Unemployment.2010.1 Unemployment.2010.2
## Poverty.Rate.2012                      -0.673              -0.673
## Poverty.Rate.2010                      -0.611              -0.616
## Unemployment.2010.1                     1.000               0.945
## Unemployment.2010.2                     0.945               1.000
## Unemployment.2010.3                     0.943               0.951
## Unemployment.2010.4                     0.935               0.922
## Fertility.Rate.2010                    -0.239              -0.294
## Homicides..2011.                        0.227               0.166
## Homicides..2010.                        0.281               0.215
## Infant.mortality.2006                  -0.377              -0.312
## LE_2007_Men                             0.562               0.555
## LE_2007_Women                           0.549               0.519
## Lit.boys                                0.700               0.705
## Lit.girls                               0.682               0.686
## GDP.Per.capita.2007.USD                 0.500               0.525
## HDI2015                                 0.669               0.675
## HDI2014                                 0.668               0.671
## Population                             -0.043               0.035
## Achievement                             0.458               0.470
## Euro                                    0.488               0.399
## Afri                                    0.089               0.174
## Amer                                   -0.530              -0.453
## HDI.mean                                0.671               0.676
## poverty.mean                           -0.646              -0.649
## unemployment.mean                       0.978               0.977
## homicide.mean.per.cap                   0.262               0.181
## infant.mortaility.per.cap              -0.406              -0.431
## Fertility.Rate.2010.1                  -0.239              -0.294
## LE_2007_men                             0.562               0.555
## LE_2007_women                           0.549               0.519
## Lit.boys.1                              0.700               0.705
## Lit.girls.1                             0.682               0.686
## GDP.per.cap                             0.500               0.525
## S.wiki                                  0.709               0.713
##                           Unemployment.2010.3 Unemployment.2010.4
## Poverty.Rate.2012                       -0.67              -0.589
## Poverty.Rate.2010                       -0.60              -0.529
## Unemployment.2010.1                      0.94               0.935
## Unemployment.2010.2                      0.95               0.922
## Unemployment.2010.3                      1.00               0.935
## Unemployment.2010.4                      0.94               1.000
## Fertility.Rate.2010                     -0.21              -0.188
## Homicides..2011.                         0.19               0.058
## Homicides..2010.                         0.25               0.062
## Infant.mortality.2006                   -0.37              -0.319
## LE_2007_Men                              0.53               0.468
## LE_2007_Women                            0.51               0.471
## Lit.boys                                 0.67               0.675
## Lit.girls                                0.66               0.674
## GDP.Per.capita.2007.USD                  0.47               0.395
## HDI2015                                  0.64               0.621
## HDI2014                                  0.65               0.606
## Population                              -0.08              -0.021
## Achievement                              0.42               0.377
## Euro                                     0.45               0.411
## Afri                                     0.13               0.038
## Amer                                    -0.50              -0.439
## HDI.mean                                 0.65               0.616
## poverty.mean                            -0.64              -0.562
## unemployment.mean                        0.98               0.972
## homicide.mean.per.cap                    0.24               0.086
## infant.mortaility.per.cap               -0.42              -0.380
## Fertility.Rate.2010.1                   -0.21              -0.188
## LE_2007_men                              0.53               0.468
## LE_2007_women                            0.51               0.471
## Lit.boys.1                               0.67               0.675
## Lit.girls.1                              0.66               0.674
## GDP.per.cap                              0.47               0.395
## S.wiki                                   0.68               0.686
##                           Fertility.Rate.2010 Homicides..2011.
## Poverty.Rate.2012                       0.480          -0.1642
## Poverty.Rate.2010                       0.463          -0.1966
## Unemployment.2010.1                    -0.239           0.2270
## Unemployment.2010.2                    -0.294           0.1657
## Unemployment.2010.3                    -0.207           0.1898
## Unemployment.2010.4                    -0.188           0.0581
## Fertility.Rate.2010                     1.000           0.0112
## Homicides..2011.                        0.011           1.0000
## Homicides..2010.                        0.010           0.9153
## Infant.mortality.2006                   0.040           0.1110
## LE_2007_Men                            -0.370          -0.0248
## LE_2007_Women                          -0.449          -0.0512
## Lit.boys                               -0.426           0.0382
## Lit.girls                              -0.455           0.0211
## GDP.Per.capita.2007.USD                -0.520           0.1806
## HDI2015                                -0.636           0.0054
## HDI2014                                -0.584           0.0491
## Population                             -0.448           0.1999
## Achievement                            -0.327           0.1637
## Euro                                    0.066           0.1994
## Afri                                   -0.232           0.1710
## Amer                                   -0.024          -0.2447
## HDI.mean                               -0.610           0.0291
## poverty.mean                            0.475          -0.1823
## unemployment.mean                      -0.237           0.1616
## homicide.mean.per.cap                   0.123           0.8728
## infant.mortaility.per.cap               0.490          -0.0295
## Fertility.Rate.2010.1                   1.000           0.0112
## LE_2007_men                            -0.370          -0.0248
## LE_2007_women                          -0.449          -0.0512
## Lit.boys.1                             -0.426           0.0382
## Lit.girls.1                            -0.455           0.0211
## GDP.per.cap                            -0.520           0.1806
## S.wiki                                 -0.458           0.0368
##                           Homicides..2010. Infant.mortality.2006
## Poverty.Rate.2012                   -0.196                0.3574
## Poverty.Rate.2010                   -0.192                0.3233
## Unemployment.2010.1                  0.281               -0.3771
## Unemployment.2010.2                  0.215               -0.3118
## Unemployment.2010.3                  0.246               -0.3659
## Unemployment.2010.4                  0.062               -0.3195
## Fertility.Rate.2010                  0.010                0.0397
## Homicides..2011.                     0.915                0.1110
## Homicides..2010.                     1.000                0.0752
## Infant.mortality.2006                0.075                1.0000
## LE_2007_Men                          0.110               -0.2607
## LE_2007_Women                        0.044               -0.1583
## Lit.boys                             0.082               -0.2782
## Lit.girls                            0.059               -0.3282
## GDP.Per.capita.2007.USD              0.177               -0.2286
## HDI2015                              0.017               -0.4412
## HDI2014                              0.073               -0.4996
## Population                           0.114                0.6989
## Achievement                          0.169               -0.0238
## Euro                                 0.283               -0.3073
## Afri                                 0.219               -0.0097
## Amer                                -0.341                0.3240
## HDI.mean                             0.047               -0.4747
## poverty.mean                        -0.195                0.3423
## unemployment.mean                    0.202               -0.3508
## homicide.mean.per.cap                0.879               -0.1498
## infant.mortaility.per.cap            0.050                0.6783
## Fertility.Rate.2010.1                0.010                0.0397
## LE_2007_men                          0.110               -0.2607
## LE_2007_women                        0.044               -0.1583
## Lit.boys.1                           0.082               -0.2782
## Lit.girls.1                          0.059               -0.3282
## GDP.per.cap                          0.177               -0.2286
## S.wiki                               0.080               -0.3135
##                           LE_2007_Men LE_2007_Women Lit.boys Lit.girls
## Poverty.Rate.2012              -0.569        -0.591   -0.771    -0.762
## Poverty.Rate.2010              -0.589        -0.613   -0.774    -0.757
## Unemployment.2010.1             0.562         0.549    0.700     0.682
## Unemployment.2010.2             0.555         0.519    0.705     0.686
## Unemployment.2010.3             0.533         0.507    0.668     0.656
## Unemployment.2010.4             0.468         0.471    0.675     0.674
## Fertility.Rate.2010            -0.370        -0.449   -0.426    -0.455
## Homicides..2011.               -0.025        -0.051    0.038     0.021
## Homicides..2010.                0.110         0.044    0.082     0.059
## Infant.mortality.2006          -0.261        -0.158   -0.278    -0.328
## LE_2007_Men                     1.000         0.942    0.732     0.703
## LE_2007_Women                   0.942         1.000    0.714     0.677
## Lit.boys                        0.732         0.714    1.000     0.985
## Lit.girls                       0.703         0.677    0.985     1.000
## GDP.Per.capita.2007.USD         0.474         0.511    0.478     0.433
## HDI2015                         0.550         0.575    0.714     0.714
## HDI2014                         0.557         0.548    0.723     0.728
## Population                     -0.042         0.056    0.030    -0.017
## Achievement                     0.620         0.635    0.784     0.754
## Euro                            0.300         0.258    0.580     0.584
## Afri                            0.175         0.130    0.124     0.101
## Amer                           -0.349        -0.296   -0.634    -0.633
## HDI.mean                        0.556         0.563    0.722     0.725
## poverty.mean                   -0.583        -0.607   -0.778    -0.765
## unemployment.mean               0.541         0.523    0.704     0.691
## homicide.mean.per.cap           0.067         0.013    0.089     0.082
## infant.mortaility.per.cap      -0.346        -0.312   -0.525    -0.555
## Fertility.Rate.2010.1          -0.370        -0.449   -0.426    -0.455
## LE_2007_men                     1.000         0.942    0.732     0.703
## LE_2007_women                   0.942         1.000    0.714     0.677
## Lit.boys.1                      0.732         0.714    1.000     0.985
## Lit.girls.1                     0.703         0.677    0.985     1.000
## GDP.per.cap                     0.474         0.511    0.478     0.433
## S.wiki                          0.740         0.721    0.996     0.994
##                           GDP.Per.capita.2007.USD HDI2015 HDI2014
## Poverty.Rate.2012                          -0.744 -0.8655  -0.887
## Poverty.Rate.2010                          -0.730 -0.8520  -0.878
## Unemployment.2010.1                         0.500  0.6686   0.668
## Unemployment.2010.2                         0.525  0.6747   0.671
## Unemployment.2010.3                         0.465  0.6413   0.654
## Unemployment.2010.4                         0.395  0.6213   0.606
## Fertility.Rate.2010                        -0.520 -0.6361  -0.584
## Homicides..2011.                            0.181  0.0054   0.049
## Homicides..2010.                            0.177  0.0169   0.073
## Infant.mortality.2006                      -0.229 -0.4412  -0.500
## LE_2007_Men                                 0.474  0.5501   0.557
## LE_2007_Women                               0.511  0.5747   0.548
## Lit.boys                                    0.478  0.7138   0.723
## Lit.girls                                   0.433  0.7139   0.728
## GDP.Per.capita.2007.USD                     1.000  0.8073   0.773
## HDI2015                                     0.807  1.0000   0.984
## HDI2014                                     0.773  0.9836   1.000
## Population                                  0.341  0.1484   0.067
## Achievement                                 0.457  0.5291   0.530
## Euro                                        0.195  0.4410   0.516
## Afri                                        0.101  0.0878   0.069
## Amer                                       -0.225 -0.4805  -0.556
## HDI.mean                                    0.792  0.9952   0.997
## poverty.mean                               -0.742 -0.8648  -0.889
## unemployment.mean                           0.481  0.6667   0.665
## homicide.mean.per.cap                       0.047 -0.0166   0.056
## infant.mortaility.per.cap                  -0.692 -0.7992  -0.817
## Fertility.Rate.2010.1                      -0.520 -0.6361  -0.584
## LE_2007_men                                 0.474  0.5501   0.557
## LE_2007_women                               0.511  0.5747   0.548
## Lit.boys.1                                  0.478  0.7138   0.723
## Lit.girls.1                                 0.433  0.7139   0.728
## GDP.per.cap                                 1.000  0.8073   0.773
## S.wiki                                      0.490  0.7392   0.750
##                           Population Achievement   Euro    Afri   Amer
## Poverty.Rate.2012             -0.049      -0.699 -0.654  0.0433  0.678
## Poverty.Rate.2010             -0.074      -0.743 -0.633  0.0069  0.664
## Unemployment.2010.1           -0.043       0.458  0.488  0.0886 -0.530
## Unemployment.2010.2            0.035       0.470  0.399  0.1741 -0.453
## Unemployment.2010.3           -0.080       0.416  0.449  0.1333 -0.498
## Unemployment.2010.4           -0.021       0.377  0.411  0.0384 -0.439
## Fertility.Rate.2010           -0.448      -0.327  0.066 -0.2317 -0.024
## Homicides..2011.               0.200       0.164  0.199  0.1710 -0.245
## Homicides..2010.               0.114       0.169  0.283  0.2194 -0.341
## Infant.mortality.2006          0.699      -0.024 -0.307 -0.0097  0.324
## LE_2007_Men                   -0.042       0.620  0.300  0.1752 -0.349
## LE_2007_Women                  0.056       0.635  0.258  0.1303 -0.296
## Lit.boys                       0.030       0.784  0.580  0.1241 -0.634
## Lit.girls                     -0.017       0.754  0.584  0.1009 -0.633
## GDP.Per.capita.2007.USD        0.341       0.457  0.195  0.1012 -0.225
## HDI2015                        0.148       0.529  0.441  0.0878 -0.481
## HDI2014                        0.067       0.530  0.516  0.0687 -0.556
## Population                     1.000       0.107 -0.203  0.0446  0.203
## Achievement                    0.107       1.000  0.468  0.2384 -0.538
## Euro                          -0.203       0.468  1.000 -0.3471 -0.983
## Afri                           0.045       0.238 -0.347  1.0000  0.170
## Amer                           0.203      -0.538 -0.983  0.1704  1.000
## HDI.mean                       0.105       0.532  0.484  0.0778 -0.523
## poverty.mean                  -0.062      -0.727 -0.648  0.0247  0.676
## unemployment.mean             -0.027       0.440  0.446  0.1102 -0.490
## homicide.mean.per.cap         -0.147       0.116  0.271  0.1543 -0.317
## infant.mortaility.per.cap      0.061      -0.342 -0.364 -0.0333  0.389
## Fertility.Rate.2010.1         -0.448      -0.327  0.066 -0.2317 -0.024
## LE_2007_men                   -0.042       0.620  0.300  0.1752 -0.349
## LE_2007_women                  0.056       0.635  0.258  0.1303 -0.296
## Lit.boys.1                     0.030       0.784  0.580  0.1241 -0.634
## Lit.girls.1                   -0.017       0.754  0.584  0.1009 -0.633
## GDP.per.cap                    0.341       0.457  0.195  0.1012 -0.225
## S.wiki                         0.013       0.776  0.582  0.1153 -0.634
##                           HDI.mean poverty.mean unemployment.mean
## Poverty.Rate.2012           -0.881        0.992            -0.665
## Poverty.Rate.2010           -0.870        0.993            -0.603
## Unemployment.2010.1          0.671       -0.646             0.978
## Unemployment.2010.2          0.676       -0.649             0.977
## Unemployment.2010.3          0.651       -0.639             0.980
## Unemployment.2010.4          0.616       -0.562             0.972
## Fertility.Rate.2010         -0.610        0.475            -0.237
## Homicides..2011.             0.029       -0.182             0.162
## Homicides..2010.             0.047       -0.195             0.202
## Infant.mortality.2006       -0.475        0.342            -0.351
## LE_2007_Men                  0.556       -0.583             0.541
## LE_2007_Women                0.563       -0.607             0.523
## Lit.boys                     0.722       -0.778             0.704
## Lit.girls                    0.725       -0.765             0.691
## GDP.Per.capita.2007.USD      0.792       -0.742             0.481
## HDI2015                      0.995       -0.865             0.667
## HDI2014                      0.997       -0.889             0.665
## Population                   0.105       -0.062            -0.027
## Achievement                  0.532       -0.727             0.440
## Euro                         0.484       -0.648             0.446
## Afri                         0.078        0.025             0.110
## Amer                        -0.523        0.676            -0.490
## HDI.mean                     1.000       -0.882             0.668
## poverty.mean                -0.882        1.000            -0.638
## unemployment.mean            0.668       -0.638             1.000
## homicide.mean.per.cap        0.023       -0.149             0.195
## infant.mortaility.per.cap   -0.812        0.704            -0.419
## Fertility.Rate.2010.1       -0.610        0.475            -0.237
## LE_2007_men                  0.556       -0.583             0.541
## LE_2007_women                0.563       -0.607             0.523
## Lit.boys.1                   0.722       -0.778             0.704
## Lit.girls.1                  0.725       -0.765             0.691
## GDP.per.cap                  0.792       -0.742             0.481
## S.wiki                       0.748       -0.795             0.713
##                           homicide.mean.per.cap infant.mortaility.per.cap
## Poverty.Rate.2012                        -0.133                     0.701
## Poverty.Rate.2010                        -0.162                     0.697
## Unemployment.2010.1                       0.262                    -0.406
## Unemployment.2010.2                       0.181                    -0.431
## Unemployment.2010.3                       0.243                    -0.420
## Unemployment.2010.4                       0.086                    -0.380
## Fertility.Rate.2010                       0.123                     0.490
## Homicides..2011.                          0.873                    -0.029
## Homicides..2010.                          0.879                     0.050
## Infant.mortality.2006                    -0.150                     0.678
## LE_2007_Men                               0.067                    -0.346
## LE_2007_Women                             0.013                    -0.312
## Lit.boys                                  0.089                    -0.525
## Lit.girls                                 0.082                    -0.555
## GDP.Per.capita.2007.USD                   0.047                    -0.692
## HDI2015                                  -0.017                    -0.799
## HDI2014                                   0.056                    -0.817
## Population                               -0.147                     0.061
## Achievement                               0.116                    -0.342
## Euro                                      0.271                    -0.364
## Afri                                      0.154                    -0.033
## Amer                                     -0.317                     0.389
## HDI.mean                                  0.023                    -0.812
## poverty.mean                             -0.149                     0.704
## unemployment.mean                         0.195                    -0.419
## homicide.mean.per.cap                     1.000                    -0.022
## infant.mortaility.per.cap                -0.022                     1.000
## Fertility.Rate.2010.1                     0.123                     0.490
## LE_2007_men                               0.067                    -0.346
## LE_2007_women                             0.013                    -0.312
## Lit.boys.1                                0.089                    -0.525
## Lit.girls.1                               0.082                    -0.555
## GDP.per.cap                               0.047                    -0.692
## S.wiki                                    0.089                    -0.559
##                           Fertility.Rate.2010.1 LE_2007_men LE_2007_women
## Poverty.Rate.2012                         0.480      -0.569        -0.591
## Poverty.Rate.2010                         0.463      -0.589        -0.613
## Unemployment.2010.1                      -0.239       0.562         0.549
## Unemployment.2010.2                      -0.294       0.555         0.519
## Unemployment.2010.3                      -0.207       0.533         0.507
## Unemployment.2010.4                      -0.188       0.468         0.471
## Fertility.Rate.2010                       1.000      -0.370        -0.449
## Homicides..2011.                          0.011      -0.025        -0.051
## Homicides..2010.                          0.010       0.110         0.044
## Infant.mortality.2006                     0.040      -0.261        -0.158
## LE_2007_Men                              -0.370       1.000         0.942
## LE_2007_Women                            -0.449       0.942         1.000
## Lit.boys                                 -0.426       0.732         0.714
## Lit.girls                                -0.455       0.703         0.677
## GDP.Per.capita.2007.USD                  -0.520       0.474         0.511
## HDI2015                                  -0.636       0.550         0.575
## HDI2014                                  -0.584       0.557         0.548
## Population                               -0.448      -0.042         0.056
## Achievement                              -0.327       0.620         0.635
## Euro                                      0.066       0.300         0.258
## Afri                                     -0.232       0.175         0.130
## Amer                                     -0.024      -0.349        -0.296
## HDI.mean                                 -0.610       0.556         0.563
## poverty.mean                              0.475      -0.583        -0.607
## unemployment.mean                        -0.237       0.541         0.523
## homicide.mean.per.cap                     0.123       0.067         0.013
## infant.mortaility.per.cap                 0.490      -0.346        -0.312
## Fertility.Rate.2010.1                     1.000      -0.370        -0.449
## LE_2007_men                              -0.370       1.000         0.942
## LE_2007_women                            -0.449       0.942         1.000
## Lit.boys.1                               -0.426       0.732         0.714
## Lit.girls.1                              -0.455       0.703         0.677
## GDP.per.cap                              -0.520       0.474         0.511
## S.wiki                                   -0.458       0.740         0.721
##                           Lit.boys.1 Lit.girls.1 GDP.per.cap S.wiki
## Poverty.Rate.2012             -0.771      -0.762      -0.744 -0.790
## Poverty.Rate.2010             -0.774      -0.757      -0.730 -0.789
## Unemployment.2010.1            0.700       0.682       0.500  0.709
## Unemployment.2010.2            0.705       0.686       0.525  0.713
## Unemployment.2010.3            0.668       0.656       0.465  0.680
## Unemployment.2010.4            0.675       0.674       0.395  0.686
## Fertility.Rate.2010           -0.426      -0.455      -0.520 -0.458
## Homicides..2011.               0.038       0.021       0.181  0.037
## Homicides..2010.               0.082       0.059       0.177  0.080
## Infant.mortality.2006         -0.278      -0.328      -0.229 -0.313
## LE_2007_Men                    0.732       0.703       0.474  0.740
## LE_2007_Women                  0.714       0.677       0.511  0.721
## Lit.boys                       1.000       0.985       0.478  0.996
## Lit.girls                      0.985       1.000       0.433  0.994
## GDP.Per.capita.2007.USD        0.478       0.433       1.000  0.490
## HDI2015                        0.714       0.714       0.807  0.739
## HDI2014                        0.723       0.728       0.773  0.750
## Population                     0.030      -0.017       0.341  0.013
## Achievement                    0.784       0.754       0.457  0.776
## Euro                           0.580       0.584       0.195  0.582
## Afri                           0.124       0.101       0.101  0.115
## Amer                          -0.634      -0.633      -0.225 -0.634
## HDI.mean                       0.722       0.725       0.792  0.748
## poverty.mean                  -0.778      -0.765      -0.742 -0.795
## unemployment.mean              0.704       0.691       0.481  0.713
## homicide.mean.per.cap          0.089       0.082       0.047  0.089
## infant.mortaility.per.cap     -0.525      -0.555      -0.692 -0.559
## Fertility.Rate.2010.1         -0.426      -0.455      -0.520 -0.458
## LE_2007_men                    0.732       0.703       0.474  0.740
## LE_2007_women                  0.714       0.677       0.511  0.721
## Lit.boys.1                     1.000       0.985       0.478  0.996
## Lit.girls.1                    0.985       1.000       0.433  0.994
## GDP.per.cap                    0.478       0.433       1.000  0.490
## S.wiki                         0.996       0.994       0.490  1.000
wtd.cors(d4)
##             S.wiki HDI.mean Achievement  Euro   Afri  Amer
## S.wiki        1.00    0.748        0.78  0.58  0.115 -0.63
## HDI.mean      0.75    1.000        0.53  0.48  0.078 -0.52
## Achievement   0.78    0.532        1.00  0.47  0.238 -0.54
## Euro          0.58    0.484        0.47  1.00 -0.347 -0.98
## Afri          0.12    0.078        0.24 -0.35  1.000  0.17
## Amer         -0.63   -0.523       -0.54 -0.98  0.170  1.00

INEG S analysis

The INEG data S analysis.

#Regression method
#all variables
s.fa = fa(s)
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was
## done

## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was
## done
## Warning in cor.smooth(r): Matrix was not positive definite, smoothing was
## done
## The estimated weights for the factor scores are probably incorrect.  Try a different factor extraction method.
## In factor.scores, the correlation matrix is singular, an approximation is used
## Warning in cor.smooth(r): Matrix was not positive definite, smoothing was
## done
s.fa_orig_scores = s.fa$scores %>% as.vector
fa_plot_loadings(s.fa)

ggsave("figures/S_self_all.png")
## Saving 7 x 5 in image
#selected
s2.fa = fa(s2)
s2.fa_orig_scores = s2.fa$scores %>% as.vector
fa_plot_loadings(s2.fa)

ggsave("figures/S_self_chosen.png")
## Saving 7 x 5 in image
#automatically selected
s3.fa = fa(s3)
s3.fa_orig_scores = s3.fa$scores %>% as.vector
fa_plot_loadings(s3.fa)

ggsave("figures/S_self_automatic.png")
## Saving 7 x 5 in image
#Bartlett's method
#all variables
s.fa = fa(s, scores = "Bartlett")
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was
## done
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was
## done
## Warning in cor.smooth(r): Matrix was not positive definite, smoothing was
## done
## The estimated weights for the factor scores are probably incorrect.  Try a different factor extraction method.
fa_plot_loadings(s.fa)