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)

ggsave("figures/S_self_all_Bartlett.png")
## Saving 7 x 5 in image
#selected
s2.fa = fa(s2, scores = "Bartlett")
fa_plot_loadings(s2.fa)

ggsave("figures/S_schosen_Bartlett.png")
## Saving 7 x 5 in image
#automatically selected
s3.fa = fa(s3, scores = "Bartlett")
fa_plot_loadings(s3.fa)

ggsave("figures/S_self_automatic_Bartlett.png")
## Saving 7 x 5 in image
#correlate loadings
load1 = data.frame(all = as.vector(s.fa$loadings)); rownames(load1) = rownames(s.fa$loadings)
load2 = data.frame(chosen = as.vector(s2.fa$loadings)); rownames(load2) = rownames(s2.fa$loadings)
load3 = data.frame(automatic = as.vector(s3.fa$loadings)); rownames(load3) = rownames(s3.fa$loadings)
loadings = merge_datasets(load1, load2)
loadings = merge_datasets(loadings, load3)
wtd.cors(loadings)
##            all chosen automatic
## all       1.00   0.98      1.00
## chosen    0.98   1.00      0.99
## automatic 1.00   0.99      1.00
count.pairwise(loadings)
##           all chosen automatic
## all        47     21        27
## chosen     21     21        13
## automatic  27     13        27

Main results

#results
#regression
s$S.all_reg = s.fa_orig_scores
s$S.chosen_reg = s2.fa_orig_scores
s$S.automatic_reg = s3.fa_orig_scores
s$S.wiki_reg = S.fa_reg

#bartlett
s$S.all = as.vector(s.fa$scores)
s$S.chosen = as.vector(s2.fa$scores)
s$S.automatic = as.vector(s3.fa$scores)
s$S.wiki = d4$S.wiki

#other
s$HDI.mean = d4$HDI.mean
s$Cognitive.ability = d3$Achievement
#s$Euro = d3$Euro #saving this result for the admixture paper
#reorder and save
s = s[order(rownames(s)), ] #to match up with admixture paper dataset
write.csv(wtd.cors(s)[48:53,48:53], "results/correlations.csv")
write.csv(s["S.chosen"], "S factor scores.csv")

#examine some correlations
wtd.cors(s[c("S.all_reg", "S.chosen_reg", "S.automatic_reg", "S.wiki_reg", "HDI.mean", "Cognitive.ability")]) %>% write_clipboard()
##                   S all reg S chosen reg S automatic reg S wiki reg
## S all reg              1.00        -0.08           -0.04       0.08
## S chosen reg          -0.08         1.00            0.94       0.83
## S automatic reg       -0.04         0.94            1.00       0.91
## S wiki reg             0.08         0.83            0.91       1.00
## HDI mean              -0.17         0.93            0.89       0.76
## Cognitive ability     -0.12         0.65            0.74       0.78
##                   HDI mean Cognitive ability
## S all reg            -0.17             -0.12
## S chosen reg          0.93              0.65
## S automatic reg       0.89              0.74
## S wiki reg            0.76              0.78
## HDI mean              1.00              0.53
## Cognitive ability     0.53              1.00
wtd.cors(s[c("S.all", "S.chosen", "S.automatic", "S.wiki", "HDI.mean", "Cognitive.ability")]) %>% write_clipboard()
##                   S all S chosen S automatic S wiki HDI mean
## S all              1.00     0.96        0.99   0.93     0.86
## S chosen           0.96     1.00        0.96   0.86     0.93
## S automatic        0.99     0.96        1.00   0.91     0.88
## S wiki             0.93     0.86        0.91   1.00     0.75
## HDI mean           0.86     0.93        0.88   0.75     1.00
## Cognitive ability  0.76     0.70        0.76   0.78     0.53
##                   Cognitive ability
## S all                          0.76
## S chosen                       0.70
## S automatic                    0.76
## S wiki                         0.78
## HDI mean                       0.53
## Cognitive ability              1.00
#plots
#plot all 6 plots automatically
temp = s[str_detect(colnames(s) ,"S\\.")]
temp$HDI = s$HDI.mean

ggpairs(temp, axisLabels = "none")
## Warning: Removed 3 rows containing non-finite values (stat_density).
## Warning in (function (data, mapping, alignPercent = 0.6, method =
## "pearson", : Removed 3 rows containing missing values
## Warning in (function (data, mapping, alignPercent = 0.6, method =
## "pearson", : Removed 3 rows containing missing values
## Warning in (function (data, mapping, alignPercent = 0.6, method =
## "pearson", : Removed 3 rows containing missing values
## Warning in (function (data, mapping, alignPercent = 0.6, method =
## "pearson", : Removed 3 rows containing missing values
## Warning in (function (data, mapping, alignPercent = 0.6, method =
## "pearson", : Removed 3 rows containing missing values
## Warning in (function (data, mapping, alignPercent = 0.6, method =
## "pearson", : Removed 3 rows containing missing values
## Warning in (function (data, mapping, alignPercent = 0.6, method =
## "pearson", : Removed 3 rows containing missing values
## Warning in (function (data, mapping, alignPercent = 0.6, method =
## "pearson", : Removed 3 rows containing missing values
## Warning: Removed 3 rows containing missing values (geom_point).
## Warning in (function (data, mapping, alignPercent = 0.6, method =
## "pearson", : Removed 3 rows containing missing values
## Warning: Removed 3 rows containing missing values (geom_point).
## Warning in (function (data, mapping, alignPercent = 0.6, method =
## "pearson", : Removed 3 rows containing missing values
## Warning: Removed 3 rows containing missing values (geom_point).
## Warning in (function (data, mapping, alignPercent = 0.6, method =
## "pearson", : Removed 3 rows containing missing values
## Warning: Removed 3 rows containing missing values (geom_point).

## Warning: Removed 3 rows containing missing values (geom_point).

## Warning: Removed 3 rows containing missing values (geom_point).

## Warning: Removed 3 rows containing missing values (geom_point).
## Warning: Removed 3 rows containing non-finite values (stat_density).
## Warning in (function (data, mapping, alignPercent = 0.6, method =
## "pearson", : Removed 3 rows containing missing values
## Warning in (function (data, mapping, alignPercent = 0.6, method =
## "pearson", : Removed 3 rows containing missing values
## Warning in (function (data, mapping, alignPercent = 0.6, method =
## "pearson", : Removed 3 rows containing missing values
## Warning in (function (data, mapping, alignPercent = 0.6, method =
## "pearson", : Removed 3 rows containing missing values
## Warning: Removed 3 rows containing missing values (geom_point).

## Warning: Removed 3 rows containing missing values (geom_point).

## Warning: Removed 3 rows containing missing values (geom_point).

## Warning: Removed 3 rows containing missing values (geom_point).

## Warning: Removed 3 rows containing missing values (geom_point).

## Warning: Removed 3 rows containing missing values (geom_point).

## Warning: Removed 3 rows containing missing values (geom_point).

## Warning: Removed 3 rows containing missing values (geom_point).

#Scatterplot with names
GG_scatter(s, "Cognitive.ability", "S.chosen")

ggsave("figures/CA_S_chosen.png")
## Saving 7 x 5 in image
#MCV
#S.all
fa_Jensens_method(s.fa, s, criterion = "Cognitive.ability") +
  xlab("Loading on S (all variables)") +
  ylab("Correlation with cognitive ability")
## Using Pearson correlations for the criterion-indicators relationships.

ggsave("figures/MCV_S_all.png")
## Saving 7 x 5 in image
#S.chosen
s2$ACH = d3$Achievement
fa_Jensens_method(s2.fa, s2, criterion = "ACH") +
  xlab("Loading on S (chosen variables)") +
  ylab("Correlation with cognitive ability")
## Using Pearson correlations for the criterion-indicators relationships.

ggsave("figures/MCV_S_chosen.png")
## Saving 7 x 5 in image
#S.automatic
s3$ACH = d3$Achievement
fa_Jensens_method(s3.fa, s3, criterion = "ACH") +
  xlab("Loading on S (automatically chosen variables)") +
  ylab("Correlation with cognitive ability")
## Using Pearson correlations for the criterion-indicators relationships.

ggsave("figures/MCV_S_automatic.png")
## Saving 7 x 5 in image
#S.wiki
fa_Jensens_method(S.fa, d3, criterion = "Achievement") +
  xlab("Loading on S (Wikipedia variables)") +
  ylab("Correlation with cognitive ability")
## Using Pearson correlations for the criterion-indicators relationships.

ggsave("figures/MCV_S_wiki.png")
## Saving 7 x 5 in image

Analyses without FD

This is some of the above code chunks repeated. The only difference are some plot names. First we simply swap out the variables with their alternate versions.

#Wikipedia data
d = d_noFD
d2 = d2_noFD

#INEG data
s = s_noFD
s2 = s2_noFD
s3 = s3_noFD

Wikipedia S analysis

The Wikipedia data S analysis.

#factor analysis
S.fa = fa(d2) #standard
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.78 0.603 0.397   1
## unemployment.mean          0.69 0.482 0.518   1
## homicide.mean.per.cap      0.11 0.012 0.988   1
## infant.mortaility.per.cap -0.54 0.289 0.711   1
## Fertility.Rate.2010       -0.44 0.191 0.809   1
## LE_2007_men                0.72 0.514 0.486   1
## LE_2007_women              0.69 0.480 0.520   1
## Lit.boys                   0.99 0.980 0.020   1
## Lit.girls                  0.99 0.988 0.012   1
## GDP.per.cap                0.47 0.217 0.783   1
## 
##                 MR1
## SS loadings    4.76
## Proportion Var 0.48
## 
## 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  290
## The degrees of freedom for the model are 35  and the objective function was  4 
## 
## 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  31 with the empirical chi square  51  with prob <  0.041 
## The total number of observations was  31  with Likelihood Chi Square =  101  with prob <  2.4e-08 
## 
## Tucker Lewis Index of factoring reliability =  0.64
## RMSEA index =  0.063  and the 90 % confidence intervals are  0.063 0.3
## BIC =  -19
## Fit based upon off diagonal values = 0.93
## Measures of factor score adequacy             
##                                                 MR1
## Correlation of scores with factors             1.00
## Multiple R square of scores with factors       0.99
## Minimum correlation of possible factor scores  0.99
fa_plot_loadings(S.fa)

ggsave("figures/S_wiki_noFD.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.78 0.603 0.397   1
## unemployment.mean          0.69 0.482 0.518   1
## homicide.mean.per.cap      0.11 0.012 0.988   1
## infant.mortaility.per.cap -0.54 0.289 0.711   1
## Fertility.Rate.2010       -0.44 0.191 0.809   1
## LE_2007_men                0.72 0.514 0.486   1
## LE_2007_women              0.69 0.480 0.520   1
## Lit.boys                   0.99 0.980 0.020   1
## Lit.girls                  0.99 0.988 0.012   1
## GDP.per.cap                0.47 0.217 0.783   1
## 
##                 MR1
## SS loadings    4.76
## Proportion Var 0.48
## 
## 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  290
## The degrees of freedom for the model are 35  and the objective function was  4 
## 
## 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  31 with the empirical chi square  51  with prob <  0.041 
## The total number of observations was  31  with Likelihood Chi Square =  101  with prob <  2.4e-08 
## 
## Tucker Lewis Index of factoring reliability =  0.64
## RMSEA index =  0.063  and the 90 % confidence intervals are  0.063 0.3
## BIC =  -19
## Fit based upon off diagonal values = 0.93
## Measures of factor score adequacy             
##                                                 MR1
## Correlation of scores with factors             1.00
## Multiple R square of scores with factors       0.99
## Minimum correlation of possible factor scores  0.99
fa_plot_loadings(S.fa)

ggsave("figures/S_wiki_Bartlett_noFD.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.969
## Poverty.Rate.2010                     0.969             1.000
## Unemployment.2010.1                  -0.658            -0.593
## Unemployment.2010.2                  -0.655            -0.594
## Unemployment.2010.3                  -0.665            -0.596
## Unemployment.2010.4                  -0.575            -0.513
## Fertility.Rate.2010                   0.435             0.411
## Homicides..2011.                     -0.158            -0.191
## Homicides..2010.                     -0.192            -0.187
## Infant.mortality.2006                 0.403             0.368
## LE_2007_Men                          -0.547            -0.568
## LE_2007_Women                        -0.565            -0.588
## Lit.boys                             -0.760            -0.764
## Lit.girls                            -0.755            -0.750
## GDP.Per.capita.2007.USD              -0.789            -0.768
## HDI2015                              -0.887            -0.870
## HDI2014                              -0.896            -0.884
## Population                            0.186             0.153
## Achievement                          -0.703            -0.749
## Euro                                 -0.718            -0.698
## Afri                                  0.066             0.029
## Amer                                  0.740             0.727
## HDI.mean                             -0.896            -0.882
## poverty.mean                          0.992             0.993
## unemployment.mean                    -0.652            -0.586
## homicide.mean.per.cap                -0.163            -0.193
## infant.mortaility.per.cap             0.680             0.675
## Fertility.Rate.2010.1                 0.435             0.411
## LE_2007_men                          -0.547            -0.568
## LE_2007_women                        -0.565            -0.588
## Lit.boys.1                           -0.760            -0.764
## Lit.girls.1                          -0.755            -0.750
## GDP.per.cap                          -0.789            -0.768
## S.wiki                               -0.771            -0.769
##                           Unemployment.2010.1 Unemployment.2010.2
## Poverty.Rate.2012                      -0.658               -0.65
## Poverty.Rate.2010                      -0.593               -0.59
## Unemployment.2010.1                     1.000                0.94
## Unemployment.2010.2                     0.943                1.00
## Unemployment.2010.3                     0.945                0.96
## Unemployment.2010.4                     0.934                0.92
## Fertility.Rate.2010                    -0.157               -0.20
## Homicides..2011.                        0.222                0.16
## Homicides..2010.                        0.278                0.21
## Infant.mortality.2006                  -0.415               -0.36
## LE_2007_Men                             0.544                0.53
## LE_2007_Women                           0.526                0.49
## Lit.boys                                0.687                0.69
## Lit.girls                               0.673                0.68
## GDP.Per.capita.2007.USD                 0.492                0.50
## HDI2015                                 0.670                0.66
## HDI2014                                 0.658                0.65
## Population                             -0.284               -0.21
## Achievement                             0.454                0.47
## Euro                                    0.535                0.45
## Afri                                    0.073                0.16
## Amer                                   -0.576               -0.51
## HDI.mean                                0.666                0.66
## poverty.mean                           -0.629               -0.63
## unemployment.mean                       0.978                0.98
## homicide.mean.per.cap                   0.290                0.21
## infant.mortaility.per.cap              -0.368               -0.39
## Fertility.Rate.2010.1                  -0.157               -0.20
## LE_2007_men                             0.544                0.53
## LE_2007_women                           0.526                0.49
## Lit.boys.1                              0.687                0.69
## Lit.girls.1                             0.673                0.68
## GDP.per.cap                             0.492                0.50
## S.wiki                                  0.689                0.69
##                           Unemployment.2010.3 Unemployment.2010.4
## Poverty.Rate.2012                       -0.66              -0.575
## Poverty.Rate.2010                       -0.60              -0.513
## Unemployment.2010.1                      0.95               0.934
## Unemployment.2010.2                      0.96               0.922
## Unemployment.2010.3                      1.00               0.935
## Unemployment.2010.4                      0.93               1.000
## Fertility.Rate.2010                     -0.17              -0.122
## Homicides..2011.                         0.19               0.051
## Homicides..2010.                         0.24               0.056
## Infant.mortality.2006                   -0.39              -0.348
## LE_2007_Men                              0.52               0.451
## LE_2007_Women                            0.50               0.451
## Lit.boys                                 0.66               0.665
## Lit.girls                                0.65               0.666
## GDP.Per.capita.2007.USD                  0.51               0.385
## HDI2015                                  0.68               0.633
## HDI2014                                  0.67               0.603
## Population                              -0.25              -0.205
## Achievement                              0.41               0.371
## Euro                                     0.48               0.446
## Afri                                     0.12               0.025
## Amer                                    -0.52              -0.472
## HDI.mean                                 0.68               0.619
## poverty.mean                            -0.63              -0.547
## unemployment.mean                        0.98               0.971
## homicide.mean.per.cap                    0.26               0.105
## infant.mortaility.per.cap               -0.41              -0.352
## Fertility.Rate.2010.1                   -0.17              -0.122
## LE_2007_men                              0.52               0.451
## LE_2007_women                            0.50               0.451
## Lit.boys.1                               0.66               0.665
## Lit.girls.1                              0.65               0.666
## GDP.per.cap                              0.51               0.385
## S.wiki                                   0.67               0.673
##                           Fertility.Rate.2010 Homicides..2011.
## Poverty.Rate.2012                       0.435          -0.1578
## Poverty.Rate.2010                       0.411          -0.1912
## Unemployment.2010.1                    -0.157           0.2224
## Unemployment.2010.2                    -0.203           0.1594
## Unemployment.2010.3                    -0.173           0.1859
## Unemployment.2010.4                    -0.122           0.0515
## Fertility.Rate.2010                     1.000           0.0465
## Homicides..2011.                        0.046           1.0000
## Homicides..2010.                        0.041           0.9151
## Infant.mortality.2006                   0.143           0.1058
## LE_2007_Men                            -0.313          -0.0353
## LE_2007_Women                          -0.378          -0.0658
## Lit.boys                               -0.387           0.0294
## Lit.girls                              -0.451           0.0139
## GDP.Per.capita.2007.USD                -0.253           0.1940
## HDI2015                                -0.496          -0.0203
## HDI2014                                -0.459           0.0323
## Population                             -0.047           0.2452
## Achievement                            -0.349           0.1609
## Euro                                   -0.028           0.2094
## Afri                                   -0.222           0.1677
## Amer                                    0.072          -0.2544
## HDI.mean                               -0.478           0.0086
## poverty.mean                            0.426          -0.1764
## unemployment.mean                      -0.167           0.1559
## homicide.mean.per.cap                   0.077           0.8836
## infant.mortaility.per.cap               0.385          -0.0146
## Fertility.Rate.2010.1                   1.000           0.0465
## LE_2007_men                            -0.313          -0.0353
## LE_2007_women                          -0.378          -0.0658
## Lit.boys.1                             -0.387           0.0294
## Lit.girls.1                            -0.451           0.0139
## GDP.per.cap                            -0.253           0.1940
## S.wiki                                 -0.434           0.0235
##                           Homicides..2010. Infant.mortality.2006
## Poverty.Rate.2012                  -0.1915                 0.403
## Poverty.Rate.2010                  -0.1873                 0.368
## Unemployment.2010.1                 0.2785                -0.415
## Unemployment.2010.2                 0.2113                -0.355
## Unemployment.2010.3                 0.2430                -0.387
## Unemployment.2010.4                 0.0558                -0.348
## Fertility.Rate.2010                 0.0414                 0.143
## Homicides..2011.                    0.9151                 0.106
## Homicides..2010.                    1.0000                 0.070
## Infant.mortality.2006               0.0704                 1.000
## LE_2007_Men                         0.1041                -0.297
## LE_2007_Women                       0.0343                -0.202
## Lit.boys                            0.0752                -0.314
## Lit.girls                           0.0533                -0.357
## GDP.Per.capita.2007.USD             0.1934                -0.403
## HDI2015                            -0.0041                -0.587
## HDI2014                             0.0609                -0.620
## Population                          0.1238                 0.898
## Achievement                         0.1670                -0.034
## Euro                                0.2929                -0.293
## Afri                                0.2168                -0.022
## Amer                               -0.3509                 0.311
## HDI.mean                            0.0317                -0.608
## poverty.mean                       -0.1908                 0.388
## unemployment.mean                   0.1984                -0.384
## homicide.mean.per.cap               0.8890                -0.138
## infant.mortaility.per.cap           0.0684                 0.775
## Fertility.Rate.2010.1               0.0414                 0.143
## LE_2007_men                         0.1041                -0.297
## LE_2007_women                       0.0343                -0.202
## Lit.boys.1                          0.0752                -0.314
## Lit.girls.1                         0.0533                -0.357
## GDP.per.cap                         0.1934                -0.403
## S.wiki                              0.0663                -0.350
##                           LE_2007_Men LE_2007_Women Lit.boys Lit.girls
## Poverty.Rate.2012              -0.547        -0.565   -0.760    -0.755
## Poverty.Rate.2010              -0.568        -0.588   -0.764    -0.750
## Unemployment.2010.1             0.544         0.526    0.687     0.673
## Unemployment.2010.2             0.533         0.488    0.691     0.676
## Unemployment.2010.3             0.524         0.497    0.663     0.650
## Unemployment.2010.4             0.451         0.451    0.665     0.666
## Fertility.Rate.2010            -0.313        -0.378   -0.387    -0.451
## Homicides..2011.               -0.035        -0.066    0.029     0.014
## Homicides..2010.                0.104         0.034    0.075     0.053
## Infant.mortality.2006          -0.297        -0.202   -0.314    -0.357
## LE_2007_Men                     1.000         0.941    0.720     0.694
## LE_2007_Women                   0.941         1.000    0.699     0.668
## Lit.boys                        0.720         0.699    1.000     0.986
## Lit.girls                       0.694         0.668    0.986     1.000
## GDP.Per.capita.2007.USD         0.451         0.461    0.460     0.435
## HDI2015                         0.526         0.531    0.721     0.740
## HDI2014                         0.530         0.500    0.719     0.740
## Population                     -0.295        -0.209   -0.180    -0.200
## Achievement                     0.620         0.640    0.788     0.754
## Euro                            0.344         0.313    0.632     0.623
## Afri                            0.161         0.112    0.109     0.088
## Amer                           -0.391        -0.349   -0.684    -0.671
## HDI.mean                        0.531         0.516    0.723     0.743
## poverty.mean                   -0.562        -0.581   -0.768    -0.758
## unemployment.mean               0.524         0.501    0.693     0.682
## homicide.mean.per.cap           0.092         0.042    0.113     0.101
## infant.mortaility.per.cap      -0.301        -0.247   -0.495    -0.540
## Fertility.Rate.2010.1          -0.313        -0.378   -0.387    -0.451
## LE_2007_men                     1.000         0.941    0.720     0.694
## LE_2007_women                   0.941         1.000    0.699     0.668
## Lit.boys.1                      0.720         0.699    1.000     0.986
## Lit.girls.1                     0.694         0.668    0.986     1.000
## GDP.per.cap                     0.451         0.461    0.460     0.435
## S.wiki                          0.717         0.693    0.994     0.998
##                           GDP.Per.capita.2007.USD HDI2015 HDI2014
## Poverty.Rate.2012                          -0.789 -0.8872  -0.896
## Poverty.Rate.2010                          -0.768 -0.8697  -0.884
## Unemployment.2010.1                         0.492  0.6697   0.658
## Unemployment.2010.2                         0.501  0.6623   0.651
## Unemployment.2010.3                         0.507  0.6764   0.673
## Unemployment.2010.4                         0.385  0.6330   0.603
## Fertility.Rate.2010                        -0.253 -0.4964  -0.459
## Homicides..2011.                            0.194 -0.0203   0.032
## Homicides..2010.                            0.193 -0.0041   0.061
## Infant.mortality.2006                      -0.403 -0.5872  -0.620
## LE_2007_Men                                 0.451  0.5263   0.530
## LE_2007_Women                               0.461  0.5312   0.500
## Lit.boys                                    0.460  0.7207   0.719
## Lit.girls                                   0.435  0.7404   0.740
## GDP.Per.capita.2007.USD                     1.000  0.7354   0.718
## HDI2015                                     0.735  1.0000   0.983
## HDI2014                                     0.718  0.9829   1.000
## Population                                 -0.227 -0.3649  -0.404
## Achievement                                 0.529  0.5687   0.554
## Euro                                        0.379  0.6017   0.651
## Afri                                        0.059  0.0511   0.035
## Amer                                       -0.408 -0.6406  -0.689
## HDI.mean                                    0.729  0.9948   0.997
## poverty.mean                               -0.784 -0.8849  -0.897
## unemployment.mean                           0.481  0.6754   0.661
## homicide.mean.per.cap                       0.145  0.0405   0.112
## infant.mortaility.per.cap                  -0.655 -0.7730  -0.791
## Fertility.Rate.2010.1                      -0.253 -0.4964  -0.459
## LE_2007_men                                 0.451  0.5263   0.530
## LE_2007_women                               0.461  0.5312   0.500
## Lit.boys.1                                  0.460  0.7207   0.719
## Lit.girls.1                                 0.435  0.7404   0.740
## GDP.per.cap                                 1.000  0.7354   0.718
## S.wiki                                      0.462  0.7465   0.745
##                           Population Achievement   Euro    Afri   Amer
## Poverty.Rate.2012              0.186      -0.703 -0.718  0.0658  0.740
## Poverty.Rate.2010              0.153      -0.749 -0.698  0.0287  0.727
## Unemployment.2010.1           -0.284       0.454  0.535  0.0729 -0.576
## Unemployment.2010.2           -0.206       0.467  0.453  0.1586 -0.505
## Unemployment.2010.3           -0.245       0.412  0.476  0.1245 -0.523
## Unemployment.2010.4           -0.205       0.371  0.446  0.0250 -0.472
## Fertility.Rate.2010           -0.047      -0.349 -0.028 -0.2218  0.072
## Homicides..2011.               0.245       0.161  0.209  0.1677 -0.254
## Homicides..2010.               0.124       0.167  0.293  0.2168 -0.351
## Infant.mortality.2006          0.898      -0.034 -0.293 -0.0218  0.311
## LE_2007_Men                   -0.295       0.620  0.344  0.1610 -0.391
## LE_2007_Women                 -0.209       0.640  0.313  0.1115 -0.349
## Lit.boys                      -0.180       0.788  0.632  0.1090 -0.684
## Lit.girls                     -0.200       0.754  0.623  0.0885 -0.671
## GDP.Per.capita.2007.USD       -0.227       0.529  0.379  0.0593 -0.408
## HDI2015                       -0.365       0.569  0.602  0.0511 -0.641
## HDI2014                       -0.404       0.554  0.651  0.0346 -0.689
## Population                     1.000       0.080 -0.132 -0.0305  0.144
## Achievement                    0.080       1.000  0.486  0.2336 -0.556
## Euro                          -0.132       0.486  1.000 -0.3388 -0.983
## Afri                          -0.031       0.234 -0.339  1.0000  0.160
## Amer                           0.144      -0.556 -0.983  0.1599  1.000
## HDI.mean                      -0.388       0.563  0.631  0.0422 -0.670
## poverty.mean                   0.170      -0.733 -0.713  0.0470  0.739
## unemployment.mean             -0.239       0.435  0.488  0.0963 -0.530
## homicide.mean.per.cap         -0.103       0.125  0.260  0.1651 -0.306
## infant.mortaility.per.cap      0.486      -0.339 -0.447 -0.0039  0.470
## Fertility.Rate.2010.1         -0.047      -0.349 -0.028 -0.2218  0.072
## LE_2007_men                   -0.295       0.620  0.344  0.1610 -0.391
## LE_2007_women                 -0.209       0.640  0.313  0.1115 -0.349
## Lit.boys.1                    -0.180       0.788  0.632  0.1090 -0.684
## Lit.girls.1                   -0.200       0.754  0.623  0.0885 -0.671
## GDP.per.cap                   -0.227       0.529  0.379  0.0593 -0.408
## S.wiki                        -0.199       0.772  0.630  0.0971 -0.680
##                           HDI.mean poverty.mean unemployment.mean
## Poverty.Rate.2012          -0.8958        0.992            -0.652
## Poverty.Rate.2010          -0.8815        0.993            -0.586
## Unemployment.2010.1         0.6662       -0.629             0.978
## Unemployment.2010.2         0.6587       -0.628             0.978
## Unemployment.2010.3         0.6776       -0.634             0.981
## Unemployment.2010.4         0.6193       -0.547             0.971
## Fertility.Rate.2010        -0.4778        0.426            -0.167
## Homicides..2011.            0.0086       -0.176             0.156
## Homicides..2010.            0.0317       -0.191             0.198
## Infant.mortality.2006      -0.6077        0.388            -0.384
## LE_2007_Men                 0.5306       -0.562             0.524
## LE_2007_Women               0.5163       -0.581             0.501
## Lit.boys                    0.7227       -0.768             0.693
## Lit.girls                   0.7432       -0.758             0.682
## GDP.Per.capita.2007.USD     0.7287       -0.784             0.481
## HDI2015                     0.9948       -0.885             0.675
## HDI2014                     0.9965       -0.897             0.661
## Population                 -0.3878        0.170            -0.239
## Achievement                 0.5628       -0.733             0.435
## Euro                        0.6314       -0.713             0.488
## Afri                        0.0422        0.047             0.096
## Amer                       -0.6701        0.739            -0.530
## HDI.mean                    1.0000       -0.895             0.670
## poverty.mean               -0.8953        1.000            -0.623
## unemployment.mean           0.6702       -0.623             1.000
## homicide.mean.per.cap       0.0801       -0.180             0.219
## infant.mortaility.per.cap  -0.7862        0.682            -0.387
## Fertility.Rate.2010.1      -0.4778        0.426            -0.167
## LE_2007_men                 0.5306       -0.562             0.524
## LE_2007_women               0.5163       -0.581             0.501
## Lit.boys.1                  0.7227       -0.768             0.693
## Lit.girls.1                 0.7432       -0.758             0.682
## GDP.per.cap                 0.7287       -0.784             0.481
## S.wiki                      0.7489       -0.776             0.696
##                           homicide.mean.per.cap infant.mortaility.per.cap
## Poverty.Rate.2012                        -0.163                    0.6799
## Poverty.Rate.2010                        -0.193                    0.6746
## Unemployment.2010.1                       0.290                   -0.3678
## Unemployment.2010.2                       0.213                   -0.3860
## Unemployment.2010.3                       0.259                   -0.4076
## Unemployment.2010.4                       0.105                   -0.3516
## Fertility.Rate.2010                       0.077                    0.3855
## Homicides..2011.                          0.884                   -0.0146
## Homicides..2010.                          0.889                    0.0684
## Infant.mortality.2006                    -0.138                    0.7747
## LE_2007_Men                               0.092                   -0.3005
## LE_2007_Women                             0.042                   -0.2471
## Lit.boys                                  0.113                   -0.4952
## Lit.girls                                 0.101                   -0.5397
## GDP.Per.capita.2007.USD                   0.145                   -0.6554
## HDI2015                                   0.040                   -0.7730
## HDI2014                                   0.112                   -0.7910
## Population                               -0.103                    0.4864
## Achievement                               0.125                   -0.3385
## Euro                                      0.260                   -0.4475
## Afri                                      0.165                   -0.0039
## Amer                                     -0.306                    0.4699
## HDI.mean                                  0.080                   -0.7862
## poverty.mean                             -0.180                    0.6824
## unemployment.mean                         0.219                   -0.3867
## homicide.mean.per.cap                     1.000                   -0.0617
## infant.mortaility.per.cap                -0.062                    1.0000
## Fertility.Rate.2010.1                     0.077                    0.3855
## LE_2007_men                               0.092                   -0.3005
## LE_2007_women                             0.042                   -0.2471
## Lit.boys.1                                0.113                   -0.4952
## Lit.girls.1                               0.101                   -0.5397
## GDP.per.cap                               0.145                   -0.6554
## S.wiki                                    0.109                   -0.5336
##                           Fertility.Rate.2010.1 LE_2007_men LE_2007_women
## Poverty.Rate.2012                         0.435      -0.547        -0.565
## Poverty.Rate.2010                         0.411      -0.568        -0.588
## Unemployment.2010.1                      -0.157       0.544         0.526
## Unemployment.2010.2                      -0.203       0.533         0.488
## Unemployment.2010.3                      -0.173       0.524         0.497
## Unemployment.2010.4                      -0.122       0.451         0.451
## Fertility.Rate.2010                       1.000      -0.313        -0.378
## Homicides..2011.                          0.046      -0.035        -0.066
## Homicides..2010.                          0.041       0.104         0.034
## Infant.mortality.2006                     0.143      -0.297        -0.202
## LE_2007_Men                              -0.313       1.000         0.941
## LE_2007_Women                            -0.378       0.941         1.000
## Lit.boys                                 -0.387       0.720         0.699
## Lit.girls                                -0.451       0.694         0.668
## GDP.Per.capita.2007.USD                  -0.253       0.451         0.461
## HDI2015                                  -0.496       0.526         0.531
## HDI2014                                  -0.459       0.530         0.500
## Population                               -0.047      -0.295        -0.209
## Achievement                              -0.349       0.620         0.640
## Euro                                     -0.028       0.344         0.313
## Afri                                     -0.222       0.161         0.112
## Amer                                      0.072      -0.391        -0.349
## HDI.mean                                 -0.478       0.531         0.516
## poverty.mean                              0.426      -0.562        -0.581
## unemployment.mean                        -0.167       0.524         0.501
## homicide.mean.per.cap                     0.077       0.092         0.042
## infant.mortaility.per.cap                 0.385      -0.301        -0.247
## Fertility.Rate.2010.1                     1.000      -0.313        -0.378
## LE_2007_men                              -0.313       1.000         0.941
## LE_2007_women                            -0.378       0.941         1.000
## Lit.boys.1                               -0.387       0.720         0.699
## Lit.girls.1                              -0.451       0.694         0.668
## GDP.per.cap                              -0.253       0.451         0.461
## S.wiki                                   -0.434       0.717         0.693
##                           Lit.boys.1 Lit.girls.1 GDP.per.cap S.wiki
## Poverty.Rate.2012             -0.760      -0.755      -0.789 -0.771
## Poverty.Rate.2010             -0.764      -0.750      -0.768 -0.769
## Unemployment.2010.1            0.687       0.673       0.492  0.689
## Unemployment.2010.2            0.691       0.676       0.501  0.692
## Unemployment.2010.3            0.663       0.650       0.507  0.666
## Unemployment.2010.4            0.665       0.666       0.385  0.673
## Fertility.Rate.2010           -0.387      -0.451      -0.253 -0.434
## Homicides..2011.               0.029       0.014       0.194  0.023
## Homicides..2010.               0.075       0.053       0.193  0.066
## Infant.mortality.2006         -0.314      -0.357      -0.403 -0.350
## LE_2007_Men                    0.720       0.694       0.451  0.717
## LE_2007_Women                  0.699       0.668       0.461  0.693
## Lit.boys                       1.000       0.986       0.460  0.994
## Lit.girls                      0.986       1.000       0.435  0.998
## GDP.Per.capita.2007.USD        0.460       0.435       1.000  0.462
## HDI2015                        0.721       0.740       0.735  0.747
## HDI2014                        0.719       0.740       0.718  0.745
## Population                    -0.180      -0.200      -0.227 -0.199
## Achievement                    0.788       0.754       0.529  0.772
## Euro                           0.632       0.623       0.379  0.630
## Afri                           0.109       0.088       0.059  0.097
## Amer                          -0.684      -0.671      -0.408 -0.680
## HDI.mean                       0.723       0.743       0.729  0.749
## poverty.mean                  -0.768      -0.758      -0.784 -0.776
## unemployment.mean              0.693       0.682       0.481  0.696
## homicide.mean.per.cap          0.113       0.101       0.145  0.109
## infant.mortaility.per.cap     -0.495      -0.540      -0.655 -0.534
## Fertility.Rate.2010.1         -0.387      -0.451      -0.253 -0.434
## LE_2007_men                    0.720       0.694       0.451  0.717
## LE_2007_women                  0.699       0.668       0.461  0.693
## Lit.boys.1                     1.000       0.986       0.460  0.994
## Lit.girls.1                    0.986       1.000       0.435  0.998
## GDP.per.cap                    0.460       0.435       1.000  0.462
## S.wiki                         0.994       0.998       0.462  1.000
wtd.cors(d4)
##             S.wiki HDI.mean Achievement  Euro   Afri  Amer
## S.wiki       1.000    0.749        0.77  0.63  0.097 -0.68
## HDI.mean     0.749    1.000        0.56  0.63  0.042 -0.67
## Achievement  0.772    0.563        1.00  0.49  0.234 -0.56
## Euro         0.630    0.631        0.49  1.00 -0.339 -0.98
## Afri         0.097    0.042        0.23 -0.34  1.000  0.16
## Amer        -0.680   -0.670       -0.56 -0.98  0.160  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
fa_plot_loadings(s.fa)

ggsave("figures/S_self_all_noFD.png")
## Saving 7 x 5 in image
#selected
s2.fa = fa(s2)
fa_plot_loadings(s2.fa)

ggsave("figures/S_self_chosen_noFD.png")
## Saving 7 x 5 in image
#automatically selected
s3.fa = fa(s3)
fa_plot_loadings(s3.fa)

ggsave("figures/S_self_automatic_noFD.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)

ggsave("figures/S_self_all_Bartlett_noFD.png")
## Saving 7 x 5 in image
#selected
s2.fa = fa(s2, scores = "Bartlett")
fa_plot_loadings(s2.fa)

ggsave("figures/S_schosen_Bartlett_noFD.png")
## Saving 7 x 5 in image
#automatically selected
s3.fa = fa(s3, scores = "Bartlett")
fa_plot_loadings(s3.fa)

ggsave("figures/S_self_automatic_Bartlett_noFD.png")
## Saving 7 x 5 in image
#correlate loadings
load1 = data.frame(all = as.vector(s.fa$loadings)); rownames(load1) = rownames(s.fa$loadings)
load2 = data.frame(chosen = as.vector(s2.fa$loadings)); rownames(load2) = rownames(s2.fa$loadings)
load3 = data.frame(automatic = as.vector(s3.fa$loadings)); rownames(load3) = rownames(s3.fa$loadings)
loadings = merge_datasets(load1, load2)
loadings = merge_datasets(loadings, load3)
wtd.cors(loadings)
##           all chosen automatic
## all         1   1.00      1.00
## chosen      1   1.00      0.99
## automatic   1   0.99      1.00

Main results

#results
s$S.all = as.vector(s.fa$scores)
s$S.chosen = as.vector(s2.fa$scores)
s$S.automatic = as.vector(s3.fa$scores)
s$S.wiki = d4$S.wiki
s$HDI.mean = d4$HDI.mean
s$Cognitive.ability = d3$Achievement
#s$Euro = d3$Euro #saving this result for the admixture paper
#reorder and save
s = s[order(rownames(s)),] #to match up with admixture paper dataset
write.csv(wtd.cors(s)[48:53,48:53], "results/correlations_noFD.csv")
write.csv(s["S.chosen"], "S factor scores_noFD.csv")

#examine some correlations
wtd.cors(s[c("S.all", "S.chosen", "S.automatic", "S.wiki", "HDI.mean", "Cognitive.ability")]) %>% write_clipboard()
##                   S all S chosen S automatic S wiki HDI mean
## S all              1.00     0.99        0.99   0.93     0.85
## S chosen           0.99     1.00        0.98   0.93     0.88
## S automatic        0.99     0.98        1.00   0.91     0.89
## S wiki             0.93     0.93        0.91   1.00     0.75
## HDI mean           0.85     0.88        0.89   0.75     1.00
## Cognitive ability  0.78     0.80        0.79   0.77     0.56
##                   Cognitive ability
## S all                          0.78
## S chosen                       0.80
## S automatic                    0.79
## S wiki                         0.77
## HDI mean                       0.56
## Cognitive ability              1.00
#plots
#plot all 6 plots automatically
temp = s[str_detect(colnames(s),"S\\.")]
temp$HDI = s$HDI.mean

ggpairs(temp, axisLabels = "none")
## Warning: Removed 3 rows containing non-finite values (stat_density).
## Warning in (function (data, mapping, alignPercent = 0.6, method =
## "pearson", : Removed 3 rows containing missing values
## Warning in (function (data, mapping, alignPercent = 0.6, method =
## "pearson", : Removed 3 rows containing missing values
## Warning in (function (data, mapping, alignPercent = 0.6, method =
## "pearson", : Removed 3 rows containing missing values
## Warning in (function (data, mapping, alignPercent = 0.6, method =
## "pearson", : Removed 3 rows containing missing values
## Warning: Removed 3 rows containing missing values (geom_point).

## Warning: Removed 3 rows containing missing values (geom_point).

## Warning: Removed 3 rows containing missing values (geom_point).

## Warning: Removed 3 rows containing missing values (geom_point).

#Scatterplot with names
GG_scatter(s, "Cognitive.ability", "S.chosen")

ggsave("figures/CA_S_chosen_noFD.png")
## Saving 7 x 5 in image
#MCV
#S.all
fa_Jensens_method(s.fa, s, criterion = "Cognitive.ability") +
  xlab("Loading on S (all variables)") +
  ylab("Correlation with cognitive ability")
## Using Pearson correlations for the criterion-indicators relationships.

ggsave("figures/MCV_S_all_noFD.png")
## Saving 7 x 5 in image
#S.chosen
s2$ACH = d3$Achievement
fa_Jensens_method(s2.fa, s2, criterion = "ACH") +
  xlab("Loading on S (chosen variables)") +
  ylab("Correlation with cognitive ability")
## Using Pearson correlations for the criterion-indicators relationships.

ggsave("figures/MCV_S_chosen_noFD.png")
## Saving 7 x 5 in image
#S.automatic
s3$ACH = d3$Achievement
fa_Jensens_method(s3.fa, s3, criterion = "ACH") +
  xlab("Loading on S (automatically chosen variables)") +
  ylab("Correlation with cognitive ability")
## Using Pearson correlations for the criterion-indicators relationships.

ggsave("figures/MCV_S_automatic_noFD.png")
## Saving 7 x 5 in image
#S.wiki
fa_Jensens_method(S.fa, d3, criterion = "Achievement") +
  xlab("Loading on S (Wikipedia variables)") +
  ylab("Correlation with cognitive ability")
## Using Pearson correlations for the criterion-indicators relationships.

ggsave("figures/MCV_S_wiki_noFD.png")
## Saving 7 x 5 in image