Carga de datos
Link="https://en.wikipedia.org/wiki/Democracy_Index"
Path='//*[@id="mw-content-text"]/div[1]/table[2]'
Idemocracia=htmltab::htmltab(Link,Path)
Revisamos los nombres
names(Idemocracia)
## [1] "Rank >> Rank"
## [2] "Country >> Country"
## [3] "Score >> Score"
## [4] "Electoral processand pluralism >> Electoral processand pluralism"
## [5] "Functioning ofgovernment >> Functioning ofgovernment"
## [6] "Politicalparticipation >> Politicalparticipation"
## [7] "Politicalculture >> Politicalculture"
## [8] "Civilliberties >> Civilliberties"
## [9] "Regimetype >> Regimetype"
## [10] "Region >> Region"
## [11] "Changes fromlast year >> Changes fromlast year"
Eliminamos columnas
Idemocracia=Idemocracia[,-c(1,3,11)]
Cambiamos nombres
names(Idemocracia)=c("country","elec","funct","partic","cult","civil",
"regime","region")
Covertimos a numericos
str(Idemocracia)
## 'data.frame': 167 obs. of 8 variables:
## $ country: chr " Norway" " Iceland" " Sweden" " New Zealand" ...
## $ elec : chr "10.00" "10.00" "9.58" "10.00" ...
## $ funct : chr "9.64" "9.29" "9.64" "9.29" ...
## $ partic : chr "10.00" "8.89" "8.33" "8.89" ...
## $ cult : chr "10.00" "10.00" "10.00" "8.13" ...
## $ civil : chr "9.71" "9.71" "9.41" "10.00" ...
## $ regime : chr "Full democracy" "Full democracy" "Full democracy" "Full democracy" ...
## $ region : chr "Western Europe" "Western Europe" "Western Europe" "Asia & Australasia" ...
Idemocracia[,2:6]=lapply(Idemocracia[,2:6],as.numeric)
fcul=formula(cult ~ region)
aggregate(fcul, Idemocracia, mean)
## region cult
## 1 Asia & Australasia 5.493571
## 2 Eastern Europe 4.935357
## 3 Latin America 5.262917
## 4 Middle East & North Africa 4.753000
## 5 North America 8.440000
## 6 Sub-Saharan Africa 5.230227
## 7 Western Europe 8.097143
Respuesta: el promedio del indicador de cultura política de Europa Occidental NO esta por debajo de otras regiones.
ffunc=formula(funct ~ cult)
aggregate(ffunc, Idemocracia, mean)
## cult funct
## 1 1.25 2.500000
## 2 1.88 0.000000
## 3 2.50 3.107500
## 4 3.13 2.960000
## 5 3.75 3.168182
## 6 4.38 3.561724
## 7 5.00 3.500741
## 8 5.63 4.802333
## 9 6.25 5.265294
## 10 6.88 6.114167
## 11 7.50 7.285833
## 12 8.13 8.125000
## 13 8.75 8.858000
## 14 9.38 9.406667
## 15 10.00 9.107500
library(ggpubr)
## Loading required package: ggplot2
p1=ggscatter(Idemocracia,
x = "funct", y = "cult",
cor.coef = TRUE,
cor.method = "pearson") # spearman?
p1
Respuesta: Pearson
fcul2=formula(cult ~ partic)
aggregate(fcul2, Idemocracia, mean)
## partic cult
## 1 1.11 1.880000
## 2 1.67 4.376667
## 3 2.22 4.376667
## 4 2.78 4.436364
## 5 3.33 4.666154
## 6 3.89 4.810769
## 7 4.44 5.291538
## 8 5.00 5.210667
## 9 5.56 5.544000
## 10 6.11 5.579615
## 11 6.67 6.081364
## 12 7.22 5.004000
## 13 7.78 7.581250
## 14 8.33 8.215714
## 15 8.89 8.376000
## 16 10.00 10.000000
library(ggpubr)
p1=ggscatter(Idemocracia,
x = "cult", y = "partic",
cor.coef = TRUE,
cor.method = "pearson") # spearman?
p1
Respuesta: el coeficiente de correlacion entre ‘cultura politica’ y ‘participacion politica’ es de 0.6