Limpieza de data

  1. LIMPIEZA VARIABLE DEPENDIENTE

La variable dependiente es el porcentaje de los jóvenes en “edad oficial escolar secundaria” que se encuentran matriculados en este nivel educativo. La data fue obtenida del Banco Mundial y colocada en el GitHub del trabajo. Procedemos a traer la data, ver su estructura y los nombres de las columnas

library(rio)
schoollink='https://github.com/marianareinosov/trabajo-final-est/raw/master/datas%20originales/school%20enrollment.xls'
school_enrollment=import(schoollink)
str(school_enrollment)
## 'data.frame':    215 obs. of  2 variables:
##  $ Country Name         : chr  "Aruba" "Afghanistan" "Angola" "Albania" ...
##  $ School Enrollment (%): num  76.9 50.1 11.3 86.6 NA ...
names(school_enrollment)
## [1] "Country Name"          "School Enrollment (%)"

Cambiamos los nombres de las variables a unos más sencillas. Para referirnos al porcentaje de jóvenes matriculados en el nivel secundario se empleará el nombre “Matricula”

names(school_enrollment) = c("Pais", "Matricula")

La columna numérica (Matricula, la cual indicica porcentaje) tiene muchos decimales; se redondeará a solamente dos.

school_enrollment$Matricula = round(school_enrollment$Matricula, 2)

Existen algunos N.A que no nos interesa conservar; los eliminamos y creamos una nueva database que será la data final limpia de nuestra variable dependiente

inscripcionsecundaria = na.omit(school_enrollment)

Exportamos la data limpia. Para hacer esto, activamos la librería rio

#install.packages("rio")
library(rio)
export(inscripcionsecundaria, "inscripcionsecundaria.xlsx")

2. PRIMERA VARIABLE INDEPENDIENTE : PBI PER CAPITA

Traemos la data que se encuentra en el Github

linkGDP = "https://github.com/marianareinosov/trabajo-final-est/raw/master/datas%20originales/PCI.csv"
dataGDP=import(linkGDP)

Vemos los nombres de mis columnas y luego se cambian a unos más sencillos

names(dataGDP)
## [1] "Country/Area"                 "Year"                        
## [3] "Unit"                         "Gross Domestic Product (GDP)"
names(dataGDP) = c("Pais","Año","unidad","PBIPC")

PBIPC = PBI per capita expresado en dólares estadounidenses.

Eliminamos la columna de “unidad” y “año” ya que no serán necesarias con el objetivo de hacer un merge de estas variables.

dataGDP$unidad = NULL
dataGDP$Año = NULL

Redondeamos la segunda columna a 2 decimales.

dataGDP$`PBIPC` = round(dataGDP$PBIPC, 2)

Exportamos la data limpia.

export(dataGDP, "dataGDP.xlsx")

3. SEGUNDA VARIABLE INDEPENDIENTE: PORCENTAJE DE POBLACION VIVIENDO BAJO LA LINEA DE POBREZA NACIONAL

Scrappeamos la tabla de la página web

linkpobreza = "https://www.cia.gov/library/publications/resources/the-world-factbook/fields/221.html"
linkpathpobreza = '//*[@id="fieldListing"]'

Se trae la data al R. Para ello, activamos la librería htmltab

#install.packages("htmltab")
library(htmltab)
Pobreza = htmltab(doc = linkpobreza, 
              which =linkpathpobreza)
## No encoding supplied: defaulting to UTF-8.

Cambiamos los nombres de las columnas

names(Pobreza) = c("Pais", "Pobreza")
names(Pobreza)
## [1] "Pais"    "Pobreza"

Pobreza = Porcentaje de la poblacion que vive bajo la linea de pobreza nacional

Para limpiar la base de datos, solo extraemos el número de la columna “Pobreza”. Utilizamos la función parse number, para la cual activamos la libreria readr.

#install.packages("readr")
library(readr)
Pobreza$Pobreza = parse_number(Pobreza$Pobreza)
## Warning: 1 parsing failure.
## row col expected actual
## 119  -- a number      -

Elimino los N.A

Pobreza = na.omit(Pobreza)

Exporto la data limpia

export(Pobreza, "Pobreza.xlsx")

4. JUNTO EN UNA TABLA LA VARIABLE DEPENDIENTE CON LAS OTRAS DOS INDEPENDIENTES

Primero, juntamos las dos variables independientes trabajadas hasta este punto. Para esto, utilizaremos la función merge.

dataeconomia=merge(dataGDP,Pobreza,all.x=T,all.y=T)

Ahora, juntamos esta nueva tabla con la de la variable dependiente.

dataecovd=merge(inscripcionsecundaria,dataeconomia,all.x=T,all.y=F)

Exportamos la data

export(dataecovd,"datafinal.xlsx")

##LIMPIEZA DE DATA: FACTORES DE RIESGO ### Primera data Comenzamos con la data de Adolescent pregnancy. Colocamos esta data sin limpiar en el repositorio de Github. Fue descargada del sitio de la OMS.

enlaceAP="https://github.com/alessiasibille17/Trabajo_Stad/raw/master/bases_originales/Adolescent%20pregnancy.xlsx"

Hora de traerla

library(rio)
dataAP=import(enlaceAP)
## New names:
## * `` -> ...2
## * `` -> ...3
## * `` -> ...4

Cambiamos los nombres, y nos deshacemos de la columna info (esta decia que se está midiendo la tasa de embarazos adolescentes por cada 1000 mujeres, entre las edades de 15-19)

names(dataAP)
## [1] "Applied filters:\nLocation type is Country\nLatestYearLabel is Latest\nLANGUAGE_CODE is en\nIndicatorCode is MDG_0000000003"
## [2] "...2"                                                                                                                       
## [3] "...3"                                                                                                                       
## [4] "...4"
names(dataAP) = c("country", "yearAP","info","rateper1000AP")
dataAP$info<-NULL

Vemos que hay dos filas que no nos proporcionan datos.

dataAP=dataAP[-c(1, 2, 169), ]
#Eliminamos la 169 porque figura Sudan (hasta el 2011, antes de que se separa en Sudán y Sudán del Sur). Dado que si tenemos un dato más actualizado de sólo Sudán, preferimos dejar este y no la data anterior a la separación de Sudán del Sur.

Veamos la estructura de esta base de datos.

class(dataAP$rateper1000AP) #está en character, que pase a ser num
## [1] "character"
dataAP$rateper1000AP=as.numeric(dataAP$rateper1000AP)

Ahora, veamos si es numérica.

class(dataAP$rateper1000AP)
## [1] "numeric"

Segunda data

Pasamos a limpiar la siguiente data:Porcentaje de la población entre 15-19 años que son actualmente consumidores de alcohol (2016). Como las anteriores, las bases de datos sin limpiar fueron descargadas de los repositorios de las Naciones Unidas (en este caso, también de la OMS).

enlaceAC="https://github.com/alessiasibille17/Trabajo_Stad/raw/master/bases_originales/alcohol_consumption.csv"
dataAC=import(enlaceAC)
names(dataAC) = c("country", "yearAC","totalAC","male","female")
#No necesitamos las columnas de female y male, sino sólo el total
dataAC$male <-NULL
dataAC$female <-NULL
#No necesitamos esas dos primeras filas. 
dataAC=dataAC[-c(1, 2), ]

#Sólo queremos quedarnos con los porcentajes, no con los intervalos. Viendo que cuentan con los puntos y sólo necesitamos el primer número, aplicaremos parse_number en la columna total
library(readr)
dataAC$totalAC=parse_number(dataAC$total)

Hora de hacer el merge

Procederemos a hacer el merge a partir de los países. Comenzaremos con nuestra data de Alcohol Consumption y Adolescent Pregnancy

DataACAP=merge(dataAC,dataAP,all.x=T,all.y=T)

Veamos si hay países duplicados

DataACAP[duplicated(DataACAP$country),]

Al parecer no. Ahora veamos si hay datos incompletos.

DataACAP[!complete.cases(DataACAP),]
#Hay países que son los mismos pero la escritura es distinta.
#Côte d’Ivoire por Côte d'Ivoire
dataAP[dataAP$country=='Côte d’Ivoire',"country"]="Côte d'Ivoire"
#The former Yugoslav Republic of Macedonia por Republic of North Macedonia
dataAP[dataAP$country=='The former Yugoslav Republic of Macedonia',"country"]="Republic of North Macedonia"

Volvemos a hacer el merge para que los cambios se actualicen

data_fdr=merge(dataAC,dataAP,all.x=T,all.y=T)
#Vemos si persisten estos casos de datos incompletos que sí figuraban, sólo que la escritura era distinta
data_fdr[!complete.cases(data_fdr),]

Vemos si los valores que usaremos están en numérico. Efectivamente, sí.

class(data_fdr$totalAC)
## [1] "numeric"
class(data_fdr$rateper1000AP)
## [1] "numeric"

¡Listo! tenemos nuestra data respecto a la variable latente: Factores de riesgo. Vamos a proceder a exportar todas las datas, primero independientemente y luego la data final.

write.csv(dataAC,"dataAC.csv",row.names=F)
write.csv(dataAP,"dataAP.csv",row.names=F)
write.csv(data_fdr,"data_fdr.csv",row.names=F)

##VARIABLE LATENTE: FACTORES SOCIODEMOGRÁFICOS ### Primera Variable: Porcentaje de población urbana POR PAÍS Para esto, primero importamos la data desde wikipedia (lugar donde se encuentra la tabla). De esta página, copiamos el link y el código xpath. Por cuestiones de practicidad, la data tendrá como nombre “urbano”.

library(htmltab)
url2 = "https://en.wikipedia.org/wiki/Urbanization_by_country"

urbano= htmltab(doc = url2, 
               which ='/html/body/div[3]/div[3]/div[5]/div[1]/table') #herramientas de desarrollador

Posteriormente, procedemos con la limpieza de la data “urbano”. Para ello procedemos a seleccionar solo las columnas que nos serán útiles y a la vez cambiamos el nombre de nuestras variables por unas más amigables (Pais y URBANO).

urbano=urbano[-138,] #para borrar la fila "world"
urbano = urbano[,c(2,3)]
names(urbano) = c("Pais", "URBANO")
summary(urbano)
##      Pais              URBANO         
##  Length:229         Length:229        
##  Class :character   Class :character  
##  Mode  :character   Mode  :character
str(urbano$URBANO)
##  chr [1:229] "100" "100" "100" "100" "100" "100" "100" "100" "100" "100" ...

Al ejecutar el código “str” nos damos cuenta de que la naturaleza de la variable es “character”. Por ello procedemos a cambiar su nauraleza a numérica.

urbano$URBANO= as.numeric(urbano$URBANO)

Asimismo, quitamos las “A” diferentes, ello lo realizamos con el comando gsub

urbano$Pais = gsub('Â',"",urbano$Pais)

También, quitamos los espacios de adelante, ya que estos podrían dificultarnos algunos pasos posteriores.

urbano$Pais=trimws(urbano$Pais,whitespace = "[\\h\\v]")

Por otra parte, procedemos a cambiar de nombres de los países, ya que hay unos que tienen una escritura particular o presentan entre paréntesis algunas referencias como: “Saint Pierre and Miquelon (France)”—> Saint Pierre and Miquelon

urbano[urbano$Pais=='Curaçao (Netherlands)',"Pais"]="Curacao"
urbano[urbano$Pais=='Wallis and Futuna (France)',"Pais"]="Wallis and Futuna"
urbano[urbano$Pais=='Saint Pierre and Miquelon (France)',"Pais"]="Saint Pierre and Miquelon"
urbano[urbano$Pais=='Saint Helena, Ascension and Tristan da Cunha (UK)',"Pais"]="SSaint Helena, Ascension and Tristan da Cunha"
urbano[urbano$Pais=='Anguilla (UK)',"Pais"]="Anguilla"
urbano[urbano$Pais=='Bermuda (UK)',"Pais"]="Bermuda"
urbano[urbano$Pais=='Cayman Islands (UK)',"Pais"]="Cayman Islands"
urbano[urbano$Pais=='Gibraltar (UK)',"Pais"]="Gibraltar"
urbano[urbano$Pais=='Turks and Caicos Islands (UK)',"Pais"]="Turks and Caicos Islands"
urbano[urbano$Pais=='Falkland Islands (UK)',"Pais"]="Falkland Islands"
urbano[urbano$Pais=='Isle of Man (UK)',"Pais"]="Isle of Man"
urbano[urbano$Pais=='British Virgin Islands (UK)',"Pais"]="British Virgin Islands"
urbano[urbano$Pais=='Hong Kong (China)',"Pais"]="Hong Kong"
urbano[urbano$Pais=='Macau (China)',"Pais"]="Macau"
urbano[urbano$Pais=='Guernsey (UK)',"Pais"]="Guernsey"
urbano[urbano$Pais=='Jersey (UK)',"Pais"]="Jersey"
urbano[urbano$Pais=='Montserrat (UK)',"Pais"]="Montserrat"
urbano[urbano$Pais=='Pitcairn Islands (UK)',"Pais"]="Pitcairn Islands"
urbano[urbano$Pais=='U.S. Virgin Islands (US)',"Pais"]="U.S. Virgin Islands"
urbano[urbano$Pais=='Guam (US)',"Pais"]="Guam"
urbano[urbano$Pais=='Puerto Rico (US)',"Pais"]="Puerto Rico"
urbano[urbano$Pais=='Northern Mariana Islands (US)',"Pais"]="Northern Mariana Islands"
urbano[urbano$Pais=='American Samoa (US)',"Pais"]="American Samoa"
urbano[urbano$Pais=='French Polynesia (France)',"Pais"]="French Polynesia"
urbano[urbano$Pais=='Sint Maarten (Netherlands)',"Pais"]="Sint Maarten"
urbano[urbano$Pais=='Aruba (Netherlands)',"Pais"]="Aruba"
urbano[urbano$Pais=='Greenland (Denmark)',"Pais"]="Greenland"
urbano[urbano$Pais=='Cook Islands (New Zealand)',"Pais"]="Cook Islands"
urbano[urbano$Pais=='Niue (New Zealand)',"Pais"]="Niue"
urbano[urbano$Pais=='Tokelau (New Zealand)',"Pais"]="Tokelau"
urbano[urbano$Pais=='Faroe Islands (Dennmark)',"Pais"]="Faroe Islands"

Segunda variable: Porcentaje de población femenina POR PAÍS

Esta variable la importamos directamente desde R, ya que el archivo es un excel desacargado en mi computadora. El archivo se puede encontrar en el github - Bases sucias - SEXO (descargar))

sexolink="https://github.com/EstefanyClareth/PROYECTO-ESTAD/raw/master/Bases%20sucias/SEXO.xlsx"
sexo=import(sexolink)

Cambiamos de nombre a las variables y recortamos aquellas columnas que no nos sirven mucho para este estudio.

sexo=sexo[-195,] #para borrar la fila "world"
sexo= sexo[,c(1,64)]
names(sexo) = c("Pais", "SEXO")
summary(sexo)
##      Pais                SEXO      
##  Length:199         Min.   :24.67  
##  Class :character   1st Qu.:49.67  
##  Mode  :character   Median :50.25  
##                     Mean   :49.87  
##                     3rd Qu.:50.91  
##                     Max.   :54.40
str(sexo$SEXO)
##  num [1:199] 52.6 48.7 50.5 49.1 48.2 ...

Cambiamos la estructura de la variable SEXO (de caracter a numérica)

sexo$SEXO= as.numeric(sexo$SEXO)

Luego procedemos a recortar los decimales.

sexo$SEXO= round(sexo$SEXO,2) 

Posteriormente, quitamos los espacios en blanco de adelante

sexo$Pais=trimws(sexo$Pais,whitespace = "[\\h\\v]")

Ahora juntamos las dos datas a través de la función merge (urbano y sexo)

sociodemo=merge(urbano,sexo) 

Finalmente exportamos las datas

export(sexo,"sexo.csv")
export(urbano,"urbano.csv")
export(sociodemo,"sociodemo.csv")

##LATENTE: INVERSIÓN DEL ESTADO EN EDUCACIÓN Scrappeamos la data que será usada para la variable de inversión del Estado en Educación a nivel global.

library(htmltab)
 url1= "https://datosmacro.expansion.com/estado/gasto/educacion" 
invereduc = htmltab(doc = url1, 
               which ='//*[@id="node-10961"]/div[4]/div/div[2]',
               encoding = "UTF-8") 

Eliminamos las columnas que no necesitamos

invereduc=invereduc[ ,c(-2:-4)]
invereduc=invereduc[ ,c(-4:-7)]
invereduc=invereduc[,-2]

Ahora, cambiamos los nombres de nuestras columnas:

names(invereduc)=c("Pais","gastoedu")

Eliminamos los porcentajes y aquellos símbolos que no se necesitan.

invereduc$Pais =gsub("\\+", "", invereduc$Pais)
invereduc$Pais =gsub("\\[]", "", invereduc$Pais)
invereduc$gastoedu =gsub("\\%", "", invereduc$gastoedu)
invereduc$gastoedu =gsub("\\,", ".", invereduc$gastoedu)
#tambien cambiamos las comas por los puntos 
invereduc$gastoedu =gsub("\\,", ".", invereduc$gastoedu)

Al juntar las datas nos damos cuentas que tenemos nombres repetidos, entonces cambiaremos los nombres en una data y luego volveremos a juntar.

#reemplazamos las vocales con tilde por vocales sin tilde
invereduc$Pais =gsub("í", "i", invereduc$Pais)
invereduc$Pais =gsub("á", "a", invereduc$Pais)
invereduc$Pais =gsub("é", "e", invereduc$Pais)
invereduc$Pais =gsub("ó", "o", invereduc$Pais)
invereduc$Pais =gsub("ú", "u", invereduc$Pais)

Verificamos nuestras variables

str(invereduc)
## 'data.frame':    191 obs. of  2 variables:
##  $ Pais    : chr  "España " "Alemania " "Reino Unido " "Francia " ...
##  $ gastoedu: chr  "4.21" "4.80" "5.49" "5.46" ...
#cambiamos nuestra variables a numericas
invereduc$gastoedu=as.numeric(invereduc$gastoedu)
#varificamos con un summary 
summary(invereduc)
##      Pais              gastoedu     
##  Length:191         Min.   : 0.720  
##  Class :character   1st Qu.: 3.145  
##  Mode  :character   Median : 4.170  
##                     Mean   : 4.455  
##                     3rd Qu.: 5.300  
##                     Max.   :12.840

Estudiantes por maestro

Ahora limpiamos la data de estudiantes por maestro

link2="https://github.com/Maritza1224/Trabajo-Grupal-estadistica/raw/master/Bases%20originales/API_SE.SEC.ENRL.TC.ZS_DS2_es_excel_v2_1348815.xls"
maestros=import(link2)
## New names:
## * `` -> ...3
## * `` -> ...4
## * `` -> ...5
## * `` -> ...6
## * `` -> ...7
## * ...

Eliminamos las columnas que no necesitamos

maestros= maestros[,-2:-54]

Eliminamos filas que no necesitamos

maestros=maestros[-1:-2,]
maestros=maestros[-1,]

Cambiamos de nombre a nuestros columnas:

names(maestros) = c("pais", "2010","2011","2012", "2013","2014","2015", "2016","2017","2018", "2019")
#eliminare la columna del 2019 ya que hay no encuentro datos 
maestros$'2019'=NULL
export(maestros,"maestrosxestu.xlsx")

En Excel juntamos los datos para tener el más reciente, ahora cambiamos nombres, borramos tildes y espacios en balnco

link3="https://github.com/Maritza1224/Trabajo-Grupal-estadistica/raw/master/Bases%20originales/maestroxestu1.xlsx?raw=true"
maestroxestu=import(link3)
names(maestroxestu)=c("Pais","profxes")
maestroxestu[!complete.cases(maestroxestu),]
#reemplazamos las vocales con tilde por vocales sin tilde
maestroxestu$Pais=gsub("í", "i", maestroxestu$Pais)
maestroxestu$Pais =gsub("á", "a", maestroxestu$Pais)
maestroxestu$Pais =gsub("é", "e", maestroxestu$Pais)
maestroxestu$Pais =gsub("ó", "o", maestroxestu$Pais)
maestroxestu$Pais =gsub("ú", "u", maestroxestu$Pais)
maestroxestu$Pais =gsub("Ã", "A", maestroxestu$Pais)
invereduc$Pais=trimws(invereduc$Pais,whitespace = "[\\h\\v]")
maestroxestu$Pais=trimws(maestroxestu$Pais,whitespace = "[\\h\\v]")
#juntamos la data de nuevo 
dataesteducacion=merge(invereduc,maestroxestu,all.x = T, all.y = T)
export(dataesteducacion,"estatalin11.xlsx")

MERGE DE DATAS

Importamos las bases de datos ##Variable dependiente y factores económicos

library(rio)
Linkmariana="https://github.com/marianareinosov/trabajo-final-est/raw/master/datas%20limpias/datafinal.xlsx"
datafinal=import(Linkmariana)
#columnas: Matricula, PBIPC y Pobreza

Factores de riesgo

linkAle="https://github.com/alessiasibille17/Trabajo_Stad/raw/master/bases_limpias/datafdrfinal.csv"
datariesgo=import(linkAle)
names(datariesgo)[1]='Pais'
#columnas: totalAC y rateper1000AP

Factores sociodemográficos

linkEstef="https://github.com/EstefanyClareth/PROYECTO-ESTAD/raw/master/BASES%20LIMPIAS/sociodemo.csv"
datasociodemo=import(linkEstef)
#columna= URBANO y SEXO

Presencia del Estado en educación

linkMaritza="https://raw.githubusercontent.com/Maritza1224/Trabajo-Grupal-estadistica/master/Bases%20Finales-Limpiadas/estatalin11.csv"
dataedues=import(linkMaritza)
#columna= gastoedu y profxes

MERGE

En este punto realizamos el merge de las variables limpiadas por separado. Primero juntamos aquella que contenía factores económicos y la variable dependiente con la de factores sociodemográficos, luego esta data mergeada con la de gasto en educación y, finalmente, el conjunto de todas las variables ya mencionadas con la data de factores de riesgo.

data1=merge(datafinal,datasociodemo,all.x=T,all.y=T)
data2=merge(data1,dataedues,all.x=T,all.y=T)
mergefinal=merge(data2,datariesgo,all.x=T,all.y=T)

Cambios a realizar

Vemos que hay países que no se han juntado debido a que los nombres tienen alguna diferencia. Procederemos a uniformizarlos para que se pueda realizar el merge de manera correcta.

#Afganistan a Afghanistan
dataedues[dataedues$Pais=='Afganistan',"Pais"]="Afghanistan"
#Alemania a Germany
dataedues[dataedues$Pais=='Alemania',"Pais"]="Germany"
# Antigua y Barbuda a Antigua and Barbuda   
dataedues[dataedues$Pais=='Antigua y Barbuda',"Pais"]="Antigua and Barbuda"
#Azerbaiyan a Azerbaijan
dataedues[dataedues$Pais=='Azerbaiyan',"Pais"]="Azerbaijan"
#Bahamas, The a Bahamas
datafinal[datafinal$Pais=='Bahamas, The',"Pais"]="Bahamas"
#Bahrein a Bahrain
dataedues[dataedues$Pais=='Bahrein',"Pais"]="Bahrain"
#Bielorrusia a Belarus. AQUÍ NO CAMBIA. CHECAR PQ NO HACE MATCH EN LA MISMA DATA
dataedues[dataedues$Pais=='Bielorrusia',"Pais"]="Belarus"
#Belgica a Belgium
dataedues[dataedues$Pais=='Belgica',"Pais"]="Belgium"
#Belice a Belize
dataedues[dataedues$Pais=='Belice',"Pais"]="Belize"
#Bermudas a Bermuda
dataedues[dataedues$Pais=='Bermudas',"Pais"]="Bermuda"
#Bolivia (Plurinational State of)   a Bolivia
datariesgo[datariesgo$Pais=='Bolivia (Plurinational State of)',"Pais"]="Bolivia"
#Bosnia y Herzegovina   a Bosnia and Herzegovina
dataedues[dataedues$Pais=='Bosnia y Herzegovina',"Pais"]="Bosnia and Herzegovina"
#Brasil a Brazil
dataedues[dataedues$Pais=='Brasil',"Pais"]="Brazil"
#Brunei a Brunei Darussalam 
dataedues[dataedues$Pais=='Brunei',"Pais"]="Brunei Darussalam"
#Butan a Bhutan MISMO PROBLEMA QUE CON BIELORRUSIA
dataedues[dataedues$Pais=='Butan',"Pais"]="Bhutan"
#Camboya a Cambodia
dataedues[dataedues$Pais=='Camboya',"Pais"]="Cambodia"
#Camerun a Cameroon
dataedues[dataedues$Pais=='Camerun',"Pais"]="Cameroon"
#Comoras a Comoros
dataedues[dataedues$Pais=='Comoras',"Pais"]="Comoros"
#Cote d'Ivoire y Costa de Marfil,  Côte d'Ivoire a Ivory Coast MISMO PROBLEMA QUE CON BIELORRUSIA
datafinal[datafinal$Pais=="Cote d'Ivoire","Pais"]="Côte d'Ivoire"
dataedues[dataedues$Pais=='Costa de Marfil',"Pais"]="Côte d'Ivoire"
#Croacia a Croatia
dataedues[dataedues$Pais=='Croacia',"Pais"]="Croatia"
#Czechia a Czech Republic
datariesgo[datariesgo$Pais=='Czechia',"Pais"]="Czech Republic"
#Chipre a Cyprus
dataedues[dataedues$Pais=='Chipre',"Pais"]="Cyprus"
#Dinamarca a Denmark
dataedues[dataedues$Pais=='Dinamarca',"Pais"]="Denmark"
#Egipto y Egypt, Arab Rep. a Egypt
dataedues[dataedues$Pais=='Egipto',"Pais"]="Egypt"
datafinal[datafinal$Pais=="Egypt, Arab Rep.","Pais"]="Egypt"
#Fiyi a Fiji
dataedues[dataedues$Pais=='Fiyi',"Pais"]="Fiji"
#Estados Unidos a United States
dataedues[dataedues$Pais=='Estados Unidos',"Pais"]="United States"
#Finlandia a Finland    
dataedues[dataedues$Pais=='Finlandia',"Pais"]="Finland"
#Francia a France
dataedues[dataedues$Pais=='Francia',"Pais"]="France"
#Grecia a Greece
dataedues[dataedues$Pais=='Grecia',"Pais"]="Greece"
#Granada a Grenada
dataedues[dataedues$Pais=='Granada',"Pais"]="Grenada"
#Hungria a Hungary
dataedues[dataedues$Pais=='Hungria',"Pais"]="Hungary"
#Iran (Islamic Republic of) y Iran, Islamic Rep. a Iran
datariesgo[datariesgo$Pais=='Iran (Islamic Republic of)',"Pais"]="Iran"
datafinal[datafinal$Pais=="Iran, Islamic Rep.","Pais"]="Iran"
#Islandia a Iceland
dataedues[dataedues$Pais=='Islandia',"Pais"]="Iceland"
#Irlanda a Ireland
dataedues[dataedues$Pais=='Irlanda',"Pais"]="Ireland"
#Italia a Italy
dataedues[dataedues$Pais=='Italia',"Pais"]="Italy"
#Japon a Japan
dataedues[dataedues$Pais=='Japon',"Pais"]="Japan"
#Jordania a Jordan
dataedues[dataedues$Pais=='Jordania',"Pais"]="Jordan"

Seguimos cambiando los nombres

#Kazajistan a Kazakhstan
dataedues[dataedues$Pais=='Kazajistan',"Pais"]="Kazakhstan"
#Kyrgyz Republic y Kirguistan a Kyrgyzstan
datafinal[datafinal$Pais=="Kyrgyz Republic","Pais"]="Kyrgyzstan"
dataedues[dataedues$Pais=='Kirguistan',"Pais"]="Kyrgyzstan"
#Corea del Sur, Korea, Rep. a Republic of Korea
datafinal[datafinal$Pais=="Korea, Rep.","Pais"]="Republic of Korea"
dataedues[dataedues$Pais=='Corea del Sur',"Pais"]="Republic of Korea"
#Lao PDR    y Lao People's Democratic Republic a Laos
datafinal[datafinal$Pais=="Lao PDR","Pais"]="Laos"
datariesgo[datariesgo$Pais=="Lao People's Democratic Republic","Pais"]="Laos"
#Letonia a Latvia
dataedues[dataedues$Pais=='Letonia',"Pais"]="Latvia"
#Lituania a Lithuania
dataedues[dataedues$Pais=='Lituania',"Pais"]="Lithuania"
#Luxemburgo a Luxembourg
dataedues[dataedues$Pais=='Luxemburgo',"Pais"]="Luxembourg"
#Malasia a Malaysia
dataedues[dataedues$Pais=='Malasia',"Pais"]="Malaysia"
#Islas Marshall a Marshall Islands
dataedues[dataedues$Pais=='Islas Marshall',"Pais"]="Marshall Islands"
#Mauricio a Mauritius
dataedues[dataedues$Pais=='Mauricio',"Pais"]="Mauritius"
#Moldavia, Republic of Moldova y Republica de Moldova a Moldova
dataedues[dataedues$Pais=='Moldavia',"Pais"]="Moldova"
dataedues[dataedues$Pais=='Republica de Moldova',"Pais"]="Moldova"
datariesgo[datariesgo$Pais=="Republic of Moldova","Pais"]="Moldova"
#Marruecos a Morocco
dataedues[dataedues$Pais=='Marruecos',"Pais"]="Morocco"
#Paises Bajos a Netherlands
dataedues[dataedues$Pais=='Paises Bajos',"Pais"]="Netherlands"
#Etiopia a Ethiopia
dataedues[dataedues$Pais=='Etiopia',"Pais"]="Ethiopia"
#Noruega a Norway
dataedues[dataedues$Pais=='Noruega',"Pais"]="Norway"
#Nueva Zelanda  a New Zealand   
dataedues[dataedues$Pais=='Nueva Zelanda',"Pais"]="New Zealand"
#Papua Nueva Guinea a Papua New Guinea
dataedues[dataedues$Pais=='Papua Nueva Guinea',"Pais"]="Papua New Guinea"
#Polonia a Poland
dataedues[dataedues$Pais=='Polonia',"Pais"]="Poland"
#Filipinas a Philippines
dataedues[dataedues$Pais=='Filipinas',"Pais"]="Philippines"
#Catar a Qatar
dataedues[dataedues$Pais=='Catar',"Pais"]="Qatar"
# Siria y Republica Arabe Siria a Syrian Arab Republic
dataedues[dataedues$Pais=='Siria',"Pais"]="Syrian Arab Republic"
dataedues[dataedues$Pais=='Republica Arabe Siria ',"Pais"]="Syrian Arab Republic"
#Rumania a Romania
dataedues[dataedues$Pais=='Rumania',"Pais"]="Romania"
#Ruanda a Rwanda
dataedues[dataedues$Pais=='Ruanda',"Pais"]="Rwanda"
#Rusia a Russian Federation
dataedues[dataedues$Pais=='Rusia',"Pais"]="Russian Federation"
#Republica Centroafricana a Central African Republic
dataedues[dataedues$Pais=='Republica Centroafricana',"Pais"]="Central African Republic"
#Republica Checa a Czech Republic
dataedues[dataedues$Pais=='Republica Checa',"Pais"]="Czech Republic"
#Republica Dominicana a Dominican Republic
dataedues[dataedues$Pais=='Republica Dominicana',"Pais"]="Dominican Republic"
#Sierra Leona   a Sierra Leone
dataedues[dataedues$Pais=='Sierra Leona',"Pais"]="Sierra Leone"
#Arabia Saudita a Saudi Arabia
dataedues[dataedues$Pais=='Arabia Saudita',"Pais"]="Saudi Arabia"

Seguimos haciendo match con los nombres.

#Santo Tome y Principe a    Sao Tome and Principe
dataedues[dataedues$Pais=='Santo Tome y Principe',"Pais"]="Sao Tome and Principe"
#Singapur a Singapore
dataedues[dataedues$Pais=='Singapur',"Pais"]="Singapore"
#España a Spain
dataedues[dataedues$Pais=='España',"Pais"]="Spain"
#Republica Eslovaca, Eslovaquia, Slovak Republic a Slovakia
dataedues[dataedues$Pais=='Republica Eslovaca',"Pais"]="Slovakia"
dataedues[dataedues$Pais=='Eslovaquia',"Pais"]="Slovakia"
datafinal[datafinal$Pais=="Slovak Republic","Pais"]="Slovakia"
#Eslovenia a Slovenia
dataedues[dataedues$Pais=='Eslovenia',"Pais"]="Slovenia"
#Suecia a Sweden
dataedues[dataedues$Pais=='Suecia',"Pais"]="Sweden"
#Suiza a Switzerland
dataedues[dataedues$Pais=='Suiza',"Pais"]="Switzerland"
#Sudafrica a South Africa   
dataedues[dataedues$Pais=='Sudafrica',"Pais"]="South Africa"
#Tayikistan a Tajikistan
dataedues[dataedues$Pais=='Tayikistan',"Pais"]="Tajikistan"
#Tailandia a Thailand
dataedues[dataedues$Pais=='Tailandia',"Pais"]="Thailand"
#Turquia a Turkey
dataedues[dataedues$Pais=='Turquia',"Pais"]="Turkey"
#Ucrania a Ukraine
dataedues[dataedues$Pais=='Ucrania',"Pais"]="Ukraine"
#Emiratos Árabes Unidos a United Arab Emirates  
dataedues[dataedues$Pais=='Emiratos Árabes Unidos',"Pais"]="United Arab Emirates"
#Reino Unido y United Kingdom of Great Britain and Northern Ireland a United Kingdom
dataedues[dataedues$Pais=='Reino Unido',"Pais"]="United Kingdom"
datariesgo[datariesgo$Pais=="United Kingdom of Great Britain and Northern Ireland","Pais"]="United Kingdom"
#United States of America    a United States
datariesgo[datariesgo$Pais=="United States of America","Pais"]="United States"
#Venezuela, RB y Venezuela (Bolivarian Republic of) a Venezuela
datafinal[datafinal$Pais=="Venezuela, RB","Pais"]="Venezuela"
datariesgo[datariesgo$Pais=="Venezuela (Bolivarian Republic of)","Pais"]="Venezuela"
#Yemen, Rep. a Yemen
datafinal[datafinal$Pais=="Yemen, Rep.","Pais"]="Yemen"
#Yibuti a Djibouti
dataedues[dataedues$Pais=='Yibuti',"Pais"]="Djibouti"
#Zimbabue a Zimbabwe
dataedues[dataedues$Pais=='Zimbabue',"Pais"]="Zimbabwe"
#Saint Lucia, Santa Lucia a St. Lucia
datariesgo[datariesgo$Pais=="Saint Lucia","Pais"]="St. Lucia"
dataedues[dataedues$Pais=='Santa Lucia',"Pais"]="St. Lucia"
#Sudan del Sur al South Sudan
dataedues[dataedues$Pais=='Sudan del Sur',"Pais"]="South Sudan"
#Timor Oriental a Timor-Leste
dataedues[dataedues$Pais=='Timor Oriental',"Pais"]="Timor-Leste"
#Birmania - Myanmar a Myanmar
dataedues[dataedues$Pais=='Birmania - Myanmar',"Pais"]="Myanmar"
#Argelia a Algeria
dataedues[dataedues$Pais=='Argelia',"Pais"]="Algeria"
#Guinea Ecuatorial a Equatorial Guinea
dataedues[dataedues$Pais=='Guinea Ecuatorial',"Pais"]="Equatorial Guinea"
#Kenia a Kenya
dataedues[dataedues$Pais=='Kenia',"Pais"]="Kenya"
#United Republic of Tanzania a Tanzania
datariesgo[datariesgo$Pais=="United Republic of Tanzania","Pais"]="Tanzania"
#Trinidad y Tobago a Trinidad and Tobago
dataedues[dataedues$Pais=='Trinidad y Tobago',"Pais"]="Trinidad and Tobago"
#Maldivas a Maldives
dataedues[dataedues$Pais=='Maldivas',"Pais"]="Maldives"
#Libano a Lebanon
dataedues[dataedues$Pais=='Libano',"Pais"]="Lebanon"
#Libia a Libya
dataedues[dataedues$Pais=='Libia',"Pais"]="Libya"
#Macedonia del Norte, Republic of North Macedonia a North Macedonia
dataedues[dataedues$Pais=='Macedonia del Norte',"Pais"]="North Macedonia"
datariesgo[datariesgo$Pais=="Republic of North Macedonia","Pais"]="North Macedonia"
#Saint Kitts y Nevis, Saint Kitts and Nevis a St. Kitts and Nevis
dataedues[dataedues$Pais=='Saint Kitts y Nevis',"Pais"]="St. Kitts and Nevis"
datariesgo[datariesgo$Pais=="Saint Kitts and Nevis","Pais"]="St. Kitts and Nevis"
#Saint Vincent and the Grenadines a St. Vincent and the Grenadines
datariesgo[datariesgo$Pais=="Saint Vincent and the Grenadines","Pais"]="St. Vincent and the Grenadines"
#Estado de Palestina a State of Palestine
dataedues[dataedues$Pais=='Estado de Palestina',"Pais"]="State of Palestine"
#Tunez a Tunisia
dataedues[dataedues$Pais=='Tunez',"Pais"]="Tunisia"
#Islas Salomon a Solomon Islands
dataedues[dataedues$Pais=='Islas Salomon',"Pais"]="Solomon Islands"
#Micronesia (Federated States of), Estados Federados de Micronesia a Federated States of Micronesia
datariesgo[datariesgo$Pais=="Micronesia (Federated States of)","Pais"]="Federated States of Micronesia"
dataedues[dataedues$Pais=='Estados Federados de Micronesia',"Pais"]="Federated States of Micronesia"
#Republica Democratica del Congo a Democratic Republic of the Congo
dataedues[dataedues$Pais=='Republica Democratica del Congo',"Pais"]="Democratic Republic of the Congo"
#Republica del Congo a Congo
dataedues[dataedues$Pais=='Republica del Congo',"Pais"]="Congo"
#Viet Nam a Vietnam
datariesgo[datariesgo$Pais=="Viet Nam","Pais"]="Vietnam"

Después de realizar estos cambios, mergeamos de nuevo la data.

data1=merge(datafinal,datasociodemo,all.x=T,all.y=T)
data2=merge(data1,dataedues,all.x=T,all.y=T)
mergefinal=merge(data2,datariesgo,all.x=T,all.y=T)

Verificamos los cambios realizados.

mergefinal[!complete.cases(mergefinal),]

Ahora importamos la data mergeada

write.csv(mergefinal,"mergefinal.csv",row.names=F)

#Análisis univariado y bivariado Importamos la data desde un repositorio de Github

library(rio)
link="https://github.com/alessiasibille17/Trabajo_Stad/raw/master/entrega2_final/mergefinal.xlsx"
datamerge=import(link)

##ANÁLISIS UNIVARIADO

#Antes que nada, colocamos los nombres de los países en row.names.
row.names(datamerge)=datamerge$Pais
#Activamos las librerías que usaremos.
library(DescTools)
library(psych)
## 
## Attaching package: 'psych'
## The following objects are masked from 'package:DescTools':
## 
##     AUC, ICC, SD
#Eliminamos la columna con los países, pues estos ya se encuentran en los row names.
datamerge$Pais= NULL

VARIABLE - MATRICULA

#Identificando la variable 
str(datamerge)
## 'data.frame':    207 obs. of  9 variables:
##  $ Matricula    : num  50.1 86.6 NA NA 11.3 ...
##  $ PBIPC        : num  552 5224 NA NA 3437 ...
##  $ Pobreza      : num  54.5 14.3 NA NA 36.6 NA 25.7 32 NA NA ...
##  $ URBANO       : num  26 62.1 73.7 NA 66.8 24.4 92.1 63.3 43.7 86.2 ...
##  $ SEXO         : num  48.7 49.1 49.5 NA 50.5 ...
##  $ gastoedu     : num  4.06 2.47 4.34 3.23 3.42 2.52 5.46 2.71 NA 5.27 ...
##  $ profxes      : num  33.5 11.2 NA 8.02 26.77 ...
##  $ totalAC      : num  0.3 37.7 1.5 64.2 33.5 35.3 54.5 16.3 NA 69.3 ...
##  $ rateper1000AP: num  62 15.9 9.7 2.7 163 27.7 54.4 21.2 NA 10.1 ...
class(datamerge$Matricula)
## [1] "numeric"
summary(datamerge$Matricula)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##    5.48   57.52   82.07   72.01   90.89   99.84      44
table(datamerge$Matricula)
## 
##  5.48 11.29 12.72 15.69 18.86 19.28 20.07 26.55 27.52 29.85 29.93 30.81 30.98 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
##    31  31.5 32.21 32.38 34.24 35.87  37.4 37.67 37.82  40.2 41.01 41.35 41.58 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
##  41.7 41.77 43.78 45.99 46.58 47.59 48.42  48.5 48.73 48.94 50.14 50.36 55.85 
##     1     1     2     1     1     1     1     1     1     1     1     1     1 
## 57.24 57.79 60.01 61.63 61.83 61.87  62.5  62.6 62.74 63.79 64.06 64.49 65.23 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
## 65.56 65.88 66.54 66.55 66.73 68.11  70.2 70.43 70.61 71.15 71.81 71.93 72.21 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
## 72.77 73.24 73.97 75.92 76.55 76.95 77.27 77.47 77.96 78.73 80.06 81.16 81.31 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
## 81.38 81.73 82.07 82.34 82.45 82.65 82.78 82.85 83.22 83.58 84.18 84.31 84.39 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
## 84.52 84.67 84.76  85.3 85.33 85.52 85.68 85.94 86.53 86.61    87 87.23 87.73 
##     1     1     1     1     1     1     1     1     1     1     1     2     1 
## 87.74 88.21 88.53 88.65 88.79 89.06 89.07 89.28 89.31 89.47 90.19 90.52 90.68 
##     2     1     1     1     1     1     1     1     1     1     1     1     1 
##  90.8 90.86 90.92 91.04 91.27 92.07 92.28 92.39 92.45  92.8 92.96 93.16 93.35 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
## 93.63  93.8 93.84 93.89 94.08 94.36 94.66 94.67 94.95 95.34 95.61 95.64 95.69 
##     1     1     1     1     1     1     2     1     1     1     1     1     1 
## 95.95  96.1 96.19 96.36 96.86 96.88 97.13    98 98.01 98.43 98.64 98.66 99.06 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
## 99.78 99.81 99.84 
##     1     1     1
#Análisis estadístico 
median(datamerge$Matricula,na.rm=T)
## [1] 82.07
mean(datamerge$Matricula,na.rm=T)
## [1] 72.01429
Mode(datamerge$Matricula,na.rm=T)
## [1] 43.78 87.23 87.74 94.66
## attr(,"freq")
## [1] 2
sd(datamerge$Matricula,na.rm=T)
## [1] 23.95137
table(datamerge$Matricula)
## 
##  5.48 11.29 12.72 15.69 18.86 19.28 20.07 26.55 27.52 29.85 29.93 30.81 30.98 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
##    31  31.5 32.21 32.38 34.24 35.87  37.4 37.67 37.82  40.2 41.01 41.35 41.58 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
##  41.7 41.77 43.78 45.99 46.58 47.59 48.42  48.5 48.73 48.94 50.14 50.36 55.85 
##     1     1     2     1     1     1     1     1     1     1     1     1     1 
## 57.24 57.79 60.01 61.63 61.83 61.87  62.5  62.6 62.74 63.79 64.06 64.49 65.23 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
## 65.56 65.88 66.54 66.55 66.73 68.11  70.2 70.43 70.61 71.15 71.81 71.93 72.21 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
## 72.77 73.24 73.97 75.92 76.55 76.95 77.27 77.47 77.96 78.73 80.06 81.16 81.31 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
## 81.38 81.73 82.07 82.34 82.45 82.65 82.78 82.85 83.22 83.58 84.18 84.31 84.39 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
## 84.52 84.67 84.76  85.3 85.33 85.52 85.68 85.94 86.53 86.61    87 87.23 87.73 
##     1     1     1     1     1     1     1     1     1     1     1     2     1 
## 87.74 88.21 88.53 88.65 88.79 89.06 89.07 89.28 89.31 89.47 90.19 90.52 90.68 
##     2     1     1     1     1     1     1     1     1     1     1     1     1 
##  90.8 90.86 90.92 91.04 91.27 92.07 92.28 92.39 92.45  92.8 92.96 93.16 93.35 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
## 93.63  93.8 93.84 93.89 94.08 94.36 94.66 94.67 94.95 95.34 95.61 95.64 95.69 
##     1     1     1     1     1     1     2     1     1     1     1     1     1 
## 95.95  96.1 96.19 96.36 96.86 96.88 97.13    98 98.01 98.43 98.64 98.66 99.06 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
## 99.78 99.81 99.84 
##     1     1     1
prop.table(table(datamerge$Matricula))*100
## 
##      5.48     11.29     12.72     15.69     18.86     19.28     20.07     26.55 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##     27.52     29.85     29.93     30.81     30.98        31      31.5     32.21 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##     32.38     34.24     35.87      37.4     37.67     37.82      40.2     41.01 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##     41.35     41.58      41.7     41.77     43.78     45.99     46.58     47.59 
## 0.6134969 0.6134969 0.6134969 0.6134969 1.2269939 0.6134969 0.6134969 0.6134969 
##     48.42      48.5     48.73     48.94     50.14     50.36     55.85     57.24 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##     57.79     60.01     61.63     61.83     61.87      62.5      62.6     62.74 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##     63.79     64.06     64.49     65.23     65.56     65.88     66.54     66.55 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##     66.73     68.11      70.2     70.43     70.61     71.15     71.81     71.93 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##     72.21     72.77     73.24     73.97     75.92     76.55     76.95     77.27 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##     77.47     77.96     78.73     80.06     81.16     81.31     81.38     81.73 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##     82.07     82.34     82.45     82.65     82.78     82.85     83.22     83.58 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##     84.18     84.31     84.39     84.52     84.67     84.76      85.3     85.33 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##     85.52     85.68     85.94     86.53     86.61        87     87.23     87.73 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 1.2269939 0.6134969 
##     87.74     88.21     88.53     88.65     88.79     89.06     89.07     89.28 
## 1.2269939 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##     89.31     89.47     90.19     90.52     90.68      90.8     90.86     90.92 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##     91.04     91.27     92.07     92.28     92.39     92.45      92.8     92.96 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##     93.16     93.35     93.63      93.8     93.84     93.89     94.08     94.36 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##     94.66     94.67     94.95     95.34     95.61     95.64     95.69     95.95 
## 1.2269939 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##      96.1     96.19     96.36     96.86     96.88     97.13        98     98.01 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##     98.43     98.64     98.66     99.06     99.78     99.81     99.84 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969
#Gráfico de la variable matrícula
boxplot(datamerge$Matricula)

graficomatricula <- (datamerge$Matricula)
hist(graficomatricula, col= rainbow(10), 
     xlab="Países",
     ylab="Porcentaje de alumnos matriculados en la escuela secundaria",
     main=" ALUMNOS MATRICULADOS POR PAÍS")

#Gráfico de la variable matricula en boxplot
boxplot(datamerge$Matricula, main="BOXPLOT DE ALUMNOS MATRICULADOS POR PAÍS", col="Yellow",
        xlab="país", ylab="Porcentaje de alumnos matriculados en la escuela secundaria")

#Para visualizar los descriptivos de manera más clara
library(table1)
## Warning: package 'table1' was built under R version 4.0.3
## 
## Attaching package: 'table1'
## The following objects are masked from 'package:base':
## 
##     units, units<-
table1::label(datamerge$Matricula) <- "Porcentaje de alumnos matriculados en el nivel secundario"
table1(~Matricula, data = datamerge)
Overall
(N=207)
Porcentaje de alumnos matriculados en el nivel secundario
Mean (SD) 72.0 (24.0)
Median [Min, Max] 82.1 [5.48, 99.8]
Missing 44 (21.3%)
table1
## function (x, ...) 
## {
##     UseMethod("table1")
## }
## <bytecode: 0x000000001a002a90>
## <environment: namespace:table1>

VARIABLE PBI-PERCAPITA

#Identificando la variable 
str(datamerge)
## 'data.frame':    207 obs. of  9 variables:
##  $ Matricula    : num  50.1 86.6 NA NA 11.3 ...
##   ..- attr(*, "label")= chr "Porcentaje de alumnos matriculados en el nivel secundario"
##  $ PBIPC        : num  552 5224 NA NA 3437 ...
##  $ Pobreza      : num  54.5 14.3 NA NA 36.6 NA 25.7 32 NA NA ...
##  $ URBANO       : num  26 62.1 73.7 NA 66.8 24.4 92.1 63.3 43.7 86.2 ...
##  $ SEXO         : num  48.7 49.1 49.5 NA 50.5 ...
##  $ gastoedu     : num  4.06 2.47 4.34 3.23 3.42 2.52 5.46 2.71 NA 5.27 ...
##  $ profxes      : num  33.5 11.2 NA 8.02 26.77 ...
##  $ totalAC      : num  0.3 37.7 1.5 64.2 33.5 35.3 54.5 16.3 NA 69.3 ...
##  $ rateper1000AP: num  62 15.9 9.7 2.7 163 27.7 54.4 21.2 NA 10.1 ...
class(datamerge$PBIPC)
## [1] "numeric"
summary(datamerge$PBIPC)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##     294    2040    6798   18564   23419  179258      65
table(datamerge$PBIPC)
## 
##    293.96    396.63    440.25    480.71    498.94     527.4    536.11    551.87 
##         1         1         1         1         1         1         1         1 
##    571.27    654.76    735.11    735.73    747.72    773.05    820.17    826.62 
##         1         1         1         1         1         1         1         1 
##     900.1    906.54     937.6     981.3    990.56   1208.44   1248.02   1330.39 
##         1         1         1         1         1         1         1         1 
##   1354.45   1400.53   1501.72   1534.49   1554.98    1670.8   1683.77   1730.44 
##         1         1         1         1         1         1         1         1 
##   1948.11   1985.43    2028.9   2035.53   2054.76   2201.58   2500.11   2681.43 
##         1         1         1         1         1         1         1         1 
##   2956.92   3037.22   3048.59   3102.73   3272.95    3437.3    3523.8   3635.41 
##         1         1         1         1         1         1         1         1 
##    3666.9   3893.49   4000.62   4058.24   4189.69   4212.13    4237.8   4249.57 
##         1         1         1         1         1         1         1         1 
##   4396.67   4549.02   4717.72   4884.74   4885.81   4900.76   5223.81   5354.25 
##         1         1         1         1         1         1         1         1 
##   5794.58   6003.72   6267.03   6311.72   6344.87   6369.23   6649.64   6947.25 
##         1         1         1         1         1         1         1         1 
##   7208.78   7273.56   7650.09   7691.35   8771.69   8821.82    8920.7   9367.92 
##         1         1         1         1         1         1         1         1 
##   9387.81   9694.85    9789.5  10485.91  11221.98  11373.35  11394.14   11687.6 
##         1         1         1         1         1         1         1         1 
##  11875.86  12026.55  12280.84  14674.02     15444  15575.08  15923.36  16264.02 
##         1         1         1         1         1         1         1         1 
##  16377.86  16726.98  17278.06  17745.87  17851.58  19072.78  19082.52   20731.2 
##         1         1         1         1         1         1         1         1 
##   23217.2  23241.89  23477.73  24133.55   26005.1  28967.58  30262.49  30405.83 
##         1         1         1         1         1         1         1         1 
##  31627.23   33122.8  33271.16  34248.84  34388.51  41358.09  43004.95  43836.15 
##         1         1         1         1         1         1         1         1 
##  44214.91  46192.38  47292.97   47513.7  48472.71  48511.26  50135.72  51230.28 
##         1         1         1         1         1         1         1         1 
##  53583.14  55766.81  58392.71  61833.71  62720.88  62917.94  68793.66   76867.3 
##         1         1         1         1         1         1         1         1 
##   79414.6  81335.65  82708.51 101207.85 117369.54 179258.25 
##         1         1         1         1         1         1
#Análisis estadístico 
median(datamerge$PBIPC,na.rm=T)
## [1] 6798.445
mean(datamerge$PBIPC,na.rm=T)
## [1] 18563.8
Mode(datamerge$PBIPC,na.rm=T)
## [1] NA
## attr(,"freq")
## [1] 1
sd(datamerge$PBIPC,na.rm=T)
## [1] 26672.1
table(datamerge$PBIPC)
## 
##    293.96    396.63    440.25    480.71    498.94     527.4    536.11    551.87 
##         1         1         1         1         1         1         1         1 
##    571.27    654.76    735.11    735.73    747.72    773.05    820.17    826.62 
##         1         1         1         1         1         1         1         1 
##     900.1    906.54     937.6     981.3    990.56   1208.44   1248.02   1330.39 
##         1         1         1         1         1         1         1         1 
##   1354.45   1400.53   1501.72   1534.49   1554.98    1670.8   1683.77   1730.44 
##         1         1         1         1         1         1         1         1 
##   1948.11   1985.43    2028.9   2035.53   2054.76   2201.58   2500.11   2681.43 
##         1         1         1         1         1         1         1         1 
##   2956.92   3037.22   3048.59   3102.73   3272.95    3437.3    3523.8   3635.41 
##         1         1         1         1         1         1         1         1 
##    3666.9   3893.49   4000.62   4058.24   4189.69   4212.13    4237.8   4249.57 
##         1         1         1         1         1         1         1         1 
##   4396.67   4549.02   4717.72   4884.74   4885.81   4900.76   5223.81   5354.25 
##         1         1         1         1         1         1         1         1 
##   5794.58   6003.72   6267.03   6311.72   6344.87   6369.23   6649.64   6947.25 
##         1         1         1         1         1         1         1         1 
##   7208.78   7273.56   7650.09   7691.35   8771.69   8821.82    8920.7   9367.92 
##         1         1         1         1         1         1         1         1 
##   9387.81   9694.85    9789.5  10485.91  11221.98  11373.35  11394.14   11687.6 
##         1         1         1         1         1         1         1         1 
##  11875.86  12026.55  12280.84  14674.02     15444  15575.08  15923.36  16264.02 
##         1         1         1         1         1         1         1         1 
##  16377.86  16726.98  17278.06  17745.87  17851.58  19072.78  19082.52   20731.2 
##         1         1         1         1         1         1         1         1 
##   23217.2  23241.89  23477.73  24133.55   26005.1  28967.58  30262.49  30405.83 
##         1         1         1         1         1         1         1         1 
##  31627.23   33122.8  33271.16  34248.84  34388.51  41358.09  43004.95  43836.15 
##         1         1         1         1         1         1         1         1 
##  44214.91  46192.38  47292.97   47513.7  48472.71  48511.26  50135.72  51230.28 
##         1         1         1         1         1         1         1         1 
##  53583.14  55766.81  58392.71  61833.71  62720.88  62917.94  68793.66   76867.3 
##         1         1         1         1         1         1         1         1 
##   79414.6  81335.65  82708.51 101207.85 117369.54 179258.25 
##         1         1         1         1         1         1
prop.table(table(datamerge$PBIPC))*100
## 
##    293.96    396.63    440.25    480.71    498.94     527.4    536.11    551.87 
## 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 
##    571.27    654.76    735.11    735.73    747.72    773.05    820.17    826.62 
## 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 
##     900.1    906.54     937.6     981.3    990.56   1208.44   1248.02   1330.39 
## 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 
##   1354.45   1400.53   1501.72   1534.49   1554.98    1670.8   1683.77   1730.44 
## 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 
##   1948.11   1985.43    2028.9   2035.53   2054.76   2201.58   2500.11   2681.43 
## 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 
##   2956.92   3037.22   3048.59   3102.73   3272.95    3437.3    3523.8   3635.41 
## 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 
##    3666.9   3893.49   4000.62   4058.24   4189.69   4212.13    4237.8   4249.57 
## 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 
##   4396.67   4549.02   4717.72   4884.74   4885.81   4900.76   5223.81   5354.25 
## 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 
##   5794.58   6003.72   6267.03   6311.72   6344.87   6369.23   6649.64   6947.25 
## 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 
##   7208.78   7273.56   7650.09   7691.35   8771.69   8821.82    8920.7   9367.92 
## 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 
##   9387.81   9694.85    9789.5  10485.91  11221.98  11373.35  11394.14   11687.6 
## 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 
##  11875.86  12026.55  12280.84  14674.02     15444  15575.08  15923.36  16264.02 
## 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 
##  16377.86  16726.98  17278.06  17745.87  17851.58  19072.78  19082.52   20731.2 
## 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 
##   23217.2  23241.89  23477.73  24133.55   26005.1  28967.58  30262.49  30405.83 
## 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 
##  31627.23   33122.8  33271.16  34248.84  34388.51  41358.09  43004.95  43836.15 
## 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 
##  44214.91  46192.38  47292.97   47513.7  48472.71  48511.26  50135.72  51230.28 
## 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 
##  53583.14  55766.81  58392.71  61833.71  62720.88  62917.94  68793.66   76867.3 
## 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 
##   79414.6  81335.65  82708.51 101207.85 117369.54 179258.25 
## 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254 0.7042254
#Para visualizar los descriptivos de manera más clara
table1::label(datamerge$PBIPC) <- "PBI per cápita (nominal) por país"
table1(~PBIPC, data = datamerge, )
Overall
(N=207)
PBI per cápita (nominal) por país
Mean (SD) 18600 (26700)
Median [Min, Max] 6800 [294, 179000]
Missing 65 (31.4%)
#Grafico de la variable PBIPC
graficoPBIPC <- (datamerge$PBIPC)
hist(graficoPBIPC, col= rainbow(10), 
     xlab="PBI per cápita (nominal)",
     main="PBI PER CÁPITA POR PAÍS")

#Gráfico de la variable PBIPERCAPITA en boxplot.
boxplot(datamerge$PBIPC, main="BOXPLOT DE PBI PER CAPITA POR PAIS ", col="Red",xlab="países",ylab="PBI per cápita (nominal)")

### VARIABLE-NIVEL DE POBREZA

#identificando la variable 
str(datamerge)
## 'data.frame':    207 obs. of  9 variables:
##  $ Matricula    : num  50.1 86.6 NA NA 11.3 ...
##   ..- attr(*, "label")= chr "Porcentaje de alumnos matriculados en el nivel secundario"
##  $ PBIPC        : num  552 5224 NA NA 3437 ...
##   ..- attr(*, "label")= chr "PBI per cápita (nominal) por país"
##  $ Pobreza      : num  54.5 14.3 NA NA 36.6 NA 25.7 32 NA NA ...
##  $ URBANO       : num  26 62.1 73.7 NA 66.8 24.4 92.1 63.3 43.7 86.2 ...
##  $ SEXO         : num  48.7 49.1 49.5 NA 50.5 ...
##  $ gastoedu     : num  4.06 2.47 4.34 3.23 3.42 2.52 5.46 2.71 NA 5.27 ...
##  $ profxes      : num  33.5 11.2 NA 8.02 26.77 ...
##  $ totalAC      : num  0.3 37.7 1.5 64.2 33.5 35.3 54.5 16.3 NA 69.3 ...
##  $ rateper1000AP: num  62 15.9 9.7 2.7 163 27.7 54.4 21.2 NA 10.1 ...
class(datamerge$Pobreza)
## [1] "numeric"
summary(datamerge$Pobreza)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##    2.60   14.40   23.00   28.02   38.60   72.30      86
table(datamerge$Pobreza)
## 
##  2.6    3  3.8  4.2  4.9  5.7  6.6  6.7  7.2    8  8.2  8.6  8.8  8.9    9  9.2 
##    1    1    2    1    1    1    1    1    1    1    1    1    1    1    1    1 
##  9.3  9.4  9.6  9.7 10.9   11   12 13.4 13.9   14 14.2 14.3 14.4 14.9   15 15.1 
##    1    1    1    1    1    1    1    1    1    1    2    1    1    1    3    2 
## 16.3 16.6 16.7 17.1 17.6   19 19.5 21.1 21.5 21.6 21.7 21.9   22 22.2 22.4 22.5 
##    1    1    1    1    1    1    2    2    1    1    1    2    1    2    1    1 
## 22.7 22.8   23 23.4 24.2 24.3 25.2 25.5 25.7 26.3   28   29 29.5 29.6 29.9   30 
##    1    1    2    1    1    1    1    1    1    1    1    1    1    3    1    2 
## 30.5   31 31.5   32 32.7   35   36 36.1 36.2 36.6   37   38 38.6 39.1 39.3 40.1 
##    1    2    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
##   41 41.8 44.8 45.4 46.1 46.2 46.3 46.5 46.7   47   50 50.7 54.1 54.5 55.1   57 
##    1    1    1    1    1    1    1    1    2    1    1    1    1    1    1    1 
## 59.3   62   63 64.6   66 66.2   70 70.2 70.7 72.3 
##    1    1    1    1    1    1    1    1    1    1
#Análisis estadístico 
median(datamerge$Pobreza,na.rm=T)
## [1] 23
mean(datamerge$Pobreza,na.rm=T)
## [1] 28.01818
Mode(datamerge$Pobreza,na.rm=T)
## [1] 15.0 29.6
## attr(,"freq")
## [1] 3
sd(datamerge$Pobreza,na.rm=T)
## [1] 17.65422
table(datamerge$Pobreza)
## 
##  2.6    3  3.8  4.2  4.9  5.7  6.6  6.7  7.2    8  8.2  8.6  8.8  8.9    9  9.2 
##    1    1    2    1    1    1    1    1    1    1    1    1    1    1    1    1 
##  9.3  9.4  9.6  9.7 10.9   11   12 13.4 13.9   14 14.2 14.3 14.4 14.9   15 15.1 
##    1    1    1    1    1    1    1    1    1    1    2    1    1    1    3    2 
## 16.3 16.6 16.7 17.1 17.6   19 19.5 21.1 21.5 21.6 21.7 21.9   22 22.2 22.4 22.5 
##    1    1    1    1    1    1    2    2    1    1    1    2    1    2    1    1 
## 22.7 22.8   23 23.4 24.2 24.3 25.2 25.5 25.7 26.3   28   29 29.5 29.6 29.9   30 
##    1    1    2    1    1    1    1    1    1    1    1    1    1    3    1    2 
## 30.5   31 31.5   32 32.7   35   36 36.1 36.2 36.6   37   38 38.6 39.1 39.3 40.1 
##    1    2    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
##   41 41.8 44.8 45.4 46.1 46.2 46.3 46.5 46.7   47   50 50.7 54.1 54.5 55.1   57 
##    1    1    1    1    1    1    1    1    2    1    1    1    1    1    1    1 
## 59.3   62   63 64.6   66 66.2   70 70.2 70.7 72.3 
##    1    1    1    1    1    1    1    1    1    1
prop.table(table(datamerge$Pobreza))*100
## 
##       2.6         3       3.8       4.2       4.9       5.7       6.6       6.7 
## 0.8264463 0.8264463 1.6528926 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 
##       7.2         8       8.2       8.6       8.8       8.9         9       9.2 
## 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 
##       9.3       9.4       9.6       9.7      10.9        11        12      13.4 
## 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 
##      13.9        14      14.2      14.3      14.4      14.9        15      15.1 
## 0.8264463 0.8264463 1.6528926 0.8264463 0.8264463 0.8264463 2.4793388 1.6528926 
##      16.3      16.6      16.7      17.1      17.6        19      19.5      21.1 
## 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 1.6528926 1.6528926 
##      21.5      21.6      21.7      21.9        22      22.2      22.4      22.5 
## 0.8264463 0.8264463 0.8264463 1.6528926 0.8264463 1.6528926 0.8264463 0.8264463 
##      22.7      22.8        23      23.4      24.2      24.3      25.2      25.5 
## 0.8264463 0.8264463 1.6528926 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 
##      25.7      26.3        28        29      29.5      29.6      29.9        30 
## 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 2.4793388 0.8264463 1.6528926 
##      30.5        31      31.5        32      32.7        35        36      36.1 
## 0.8264463 1.6528926 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 
##      36.2      36.6        37        38      38.6      39.1      39.3      40.1 
## 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 
##        41      41.8      44.8      45.4      46.1      46.2      46.3      46.5 
## 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 
##      46.7        47        50      50.7      54.1      54.5      55.1        57 
## 1.6528926 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 
##      59.3        62        63      64.6        66      66.2        70      70.2 
## 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 0.8264463 
##      70.7      72.3 
## 0.8264463 0.8264463
#Para visualizar los descriptivos de manera más clara
table1::label(datamerge$Pobreza) <- "Porcentaje de la población bajo la línea nacional de pobreza"
table1::table1(~Pobreza, data = datamerge, )
Overall
(N=207)
Porcentaje de la población bajo la línea nacional de pobreza
Mean (SD) 28.0 (17.7)
Median [Min, Max] 23.0 [2.60, 72.3]
Missing 86 (41.5%)
#Gráfico de la variable Pobreza 
graficopobreza <- (datamerge$Pobreza)
hist(graficopobreza, col= rainbow(10), 
     main="PORCENTAJE DE POBREZA POR PAÍS",
     xlab="Porcentaje de la población bajo la línea nacional de pobreza",ylab="Países")

#Gráfico de la variable Pobreza en boxplot
boxplot(datamerge$Pobreza, main="BOXPLOT DE POBREZA ", col="Blue",
        xlab="países", ylab="Porcentaje de la población bajo la línea nacional de pobreza")

### VARIABLE-URBANO

#Identificando la variable 
str(datamerge)
## 'data.frame':    207 obs. of  9 variables:
##  $ Matricula    : num  50.1 86.6 NA NA 11.3 ...
##   ..- attr(*, "label")= chr "Porcentaje de alumnos matriculados en el nivel secundario"
##  $ PBIPC        : num  552 5224 NA NA 3437 ...
##   ..- attr(*, "label")= chr "PBI per cápita (nominal) por país"
##  $ Pobreza      : num  54.5 14.3 NA NA 36.6 NA 25.7 32 NA NA ...
##   ..- attr(*, "label")= chr "Porcentaje de la población bajo la línea nacional de pobreza"
##  $ URBANO       : num  26 62.1 73.7 NA 66.8 24.4 92.1 63.3 43.7 86.2 ...
##  $ SEXO         : num  48.7 49.1 49.5 NA 50.5 ...
##  $ gastoedu     : num  4.06 2.47 4.34 3.23 3.42 2.52 5.46 2.71 NA 5.27 ...
##  $ profxes      : num  33.5 11.2 NA 8.02 26.77 ...
##  $ totalAC      : num  0.3 37.7 1.5 64.2 33.5 35.3 54.5 16.3 NA 69.3 ...
##  $ rateper1000AP: num  62 15.9 9.7 2.7 163 27.7 54.4 21.2 NA 10.1 ...
class(datamerge$URBANO)
## [1] "numeric"
summary(datamerge$URBANO)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   13.30   42.55   59.50   59.79   79.60  100.00      44
table(datamerge$URBANO)
## 
## 13.3 13.7 16.6 17.4 18.7 20.2 20.6 21.7 23.1 23.5 24.2 24.4 24.7   25 25.5   26 
##    1    1    1    2    1    1    1    1    1    1    2    1    1    1    1    1 
## 26.8 27.5   28   29 29.4 30.6 31.1 31.2 32.2 34.9 35.2 35.3 36.5 37.1 37.2 37.3 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 38.2 38.5 40.7 40.8 41.3 42.2 42.3 42.8 42.9 43.7 43.9 44.2 44.6   46 46.1 47.4 
##    1    1    1    1    1    1    1    2    1    1    1    1    1    1    1    1 
## 48.1 48.4   49 50.4 51.4 51.8   52 52.1 52.5 53.2 55.1 55.3 55.6 56.3 56.4 56.6 
##    1    1    1    1    1    1    2    1    1    1    1    1    1    1    3    1 
## 57.1 57.2 57.3 57.5 57.6 57.7 58.4 58.5 58.7   59 59.5   60 61.4   62 62.1 62.2 
##    1    1    1    1    2    1    1    1    1    1    1    1    1    1    1    1 
## 63.3 63.5 63.7 64.2 66.1 66.3 66.8 67.4 67.5   68 68.3 68.4 68.7 69.2 69.6 70.1 
##    1    1    1    1    1    1    2    1    1    1    1    1    1    1    2    1 
## 70.9   71 71.9 73.1 73.4 73.7 73.9 74.1 75.7 76.1 77.2 77.5 78.1 78.3 79.5 79.7 
##    2    1    1    1    1    1    1    1    1    1    2    1    1    1    1    1 
## 80.7 80.8   81 81.4 81.6 82.5 82.7   83 83.9 84.3 85.5 86.2 86.3 86.7   87 87.1 
##    2    2    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 87.7   88 88.1 88.9 89.1 89.5 90.1 91.4 91.5 91.8 92.1 92.2 92.6 93.6 93.9 94.7 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 94.9 95.5 98.1 99.2  100 
##    1    1    1    1    2
#Análisis estadístico 
median(datamerge$URBANO,na.rm=T)
## [1] 59.5
mean(datamerge$URBANO,na.rm=T)
## [1] 59.78834
Mode(datamerge$URBANO,na.rm=T)
## [1] 56.4
## attr(,"freq")
## [1] 3
sd(datamerge$URBANO,na.rm=T)
## [1] 22.95692
table(datamerge$URBANO)
## 
## 13.3 13.7 16.6 17.4 18.7 20.2 20.6 21.7 23.1 23.5 24.2 24.4 24.7   25 25.5   26 
##    1    1    1    2    1    1    1    1    1    1    2    1    1    1    1    1 
## 26.8 27.5   28   29 29.4 30.6 31.1 31.2 32.2 34.9 35.2 35.3 36.5 37.1 37.2 37.3 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 38.2 38.5 40.7 40.8 41.3 42.2 42.3 42.8 42.9 43.7 43.9 44.2 44.6   46 46.1 47.4 
##    1    1    1    1    1    1    1    2    1    1    1    1    1    1    1    1 
## 48.1 48.4   49 50.4 51.4 51.8   52 52.1 52.5 53.2 55.1 55.3 55.6 56.3 56.4 56.6 
##    1    1    1    1    1    1    2    1    1    1    1    1    1    1    3    1 
## 57.1 57.2 57.3 57.5 57.6 57.7 58.4 58.5 58.7   59 59.5   60 61.4   62 62.1 62.2 
##    1    1    1    1    2    1    1    1    1    1    1    1    1    1    1    1 
## 63.3 63.5 63.7 64.2 66.1 66.3 66.8 67.4 67.5   68 68.3 68.4 68.7 69.2 69.6 70.1 
##    1    1    1    1    1    1    2    1    1    1    1    1    1    1    2    1 
## 70.9   71 71.9 73.1 73.4 73.7 73.9 74.1 75.7 76.1 77.2 77.5 78.1 78.3 79.5 79.7 
##    2    1    1    1    1    1    1    1    1    1    2    1    1    1    1    1 
## 80.7 80.8   81 81.4 81.6 82.5 82.7   83 83.9 84.3 85.5 86.2 86.3 86.7   87 87.1 
##    2    2    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 87.7   88 88.1 88.9 89.1 89.5 90.1 91.4 91.5 91.8 92.1 92.2 92.6 93.6 93.9 94.7 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 94.9 95.5 98.1 99.2  100 
##    1    1    1    1    2
prop.table(table(datamerge$URBANO))*100
## 
##      13.3      13.7      16.6      17.4      18.7      20.2      20.6      21.7 
## 0.6134969 0.6134969 0.6134969 1.2269939 0.6134969 0.6134969 0.6134969 0.6134969 
##      23.1      23.5      24.2      24.4      24.7        25      25.5        26 
## 0.6134969 0.6134969 1.2269939 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##      26.8      27.5        28        29      29.4      30.6      31.1      31.2 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##      32.2      34.9      35.2      35.3      36.5      37.1      37.2      37.3 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##      38.2      38.5      40.7      40.8      41.3      42.2      42.3      42.8 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 1.2269939 
##      42.9      43.7      43.9      44.2      44.6        46      46.1      47.4 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##      48.1      48.4        49      50.4      51.4      51.8        52      52.1 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 1.2269939 0.6134969 
##      52.5      53.2      55.1      55.3      55.6      56.3      56.4      56.6 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 1.8404908 0.6134969 
##      57.1      57.2      57.3      57.5      57.6      57.7      58.4      58.5 
## 0.6134969 0.6134969 0.6134969 0.6134969 1.2269939 0.6134969 0.6134969 0.6134969 
##      58.7        59      59.5        60      61.4        62      62.1      62.2 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##      63.3      63.5      63.7      64.2      66.1      66.3      66.8      67.4 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 1.2269939 0.6134969 
##      67.5        68      68.3      68.4      68.7      69.2      69.6      70.1 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 1.2269939 0.6134969 
##      70.9        71      71.9      73.1      73.4      73.7      73.9      74.1 
## 1.2269939 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##      75.7      76.1      77.2      77.5      78.1      78.3      79.5      79.7 
## 0.6134969 0.6134969 1.2269939 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##      80.7      80.8        81      81.4      81.6      82.5      82.7        83 
## 1.2269939 1.2269939 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##      83.9      84.3      85.5      86.2      86.3      86.7        87      87.1 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##      87.7        88      88.1      88.9      89.1      89.5      90.1      91.4 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##      91.5      91.8      92.1      92.2      92.6      93.6      93.9      94.7 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##      94.9      95.5      98.1      99.2       100 
## 0.6134969 0.6134969 0.6134969 0.6134969 1.2269939
#Para visualizar los descriptivos de manera más clara
table1::label(datamerge$URBANO) <- "Porcentaje de urbanización por país"
table1::table1(~URBANO, data = datamerge, )
Overall
(N=207)
Porcentaje de urbanización por país
Mean (SD) 59.8 (23.0)
Median [Min, Max] 59.5 [13.3, 100]
Missing 44 (21.3%)
#Gráfico de la variable urbano
graficourbano <- (datamerge$URBANO)
hist(graficourbano, col= rainbow(10), 
     xlab="Países",
     ylab="Porcentaje de urbanización",
     main="PORCENTAJE DE URBANIZACIÓN POR PAÍS")

#Gráfico de la variable URBANO en boxplot
boxplot(datamerge$URBANO, main="BOXPLOT PORCENTAJE DE URBANIZACIÓN POR PAÍS ", col="light pink",
        xlab="países", ylab="Porcentaje de urbanización")

### VARIABLE-SEXO

#Identificando la variable 
str(datamerge)
## 'data.frame':    207 obs. of  9 variables:
##  $ Matricula    : num  50.1 86.6 NA NA 11.3 ...
##   ..- attr(*, "label")= chr "Porcentaje de alumnos matriculados en el nivel secundario"
##  $ PBIPC        : num  552 5224 NA NA 3437 ...
##   ..- attr(*, "label")= chr "PBI per cápita (nominal) por país"
##  $ Pobreza      : num  54.5 14.3 NA NA 36.6 NA 25.7 32 NA NA ...
##   ..- attr(*, "label")= chr "Porcentaje de la población bajo la línea nacional de pobreza"
##  $ URBANO       : num  26 62.1 73.7 NA 66.8 24.4 92.1 63.3 43.7 86.2 ...
##   ..- attr(*, "label")= chr "Porcentaje de urbanización por país"
##  $ SEXO         : num  48.7 49.1 49.5 NA 50.5 ...
##  $ gastoedu     : num  4.06 2.47 4.34 3.23 3.42 2.52 5.46 2.71 NA 5.27 ...
##  $ profxes      : num  33.5 11.2 NA 8.02 26.77 ...
##  $ totalAC      : num  0.3 37.7 1.5 64.2 33.5 35.3 54.5 16.3 NA 69.3 ...
##  $ rateper1000AP: num  62 15.9 9.7 2.7 163 27.7 54.4 21.2 NA 10.1 ...
class(datamerge$SEXO)
## [1] "numeric"
summary(datamerge$SEXO)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   24.67   49.75   50.33   49.81   50.99   54.40      44
table(datamerge$SEXO)
## 
## 24.67 30.74 33.98 35.73  36.7 39.08 42.27 44.41 46.92 47.41 47.66 48.03 48.54 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
##  48.6 48.66 48.67 48.69 48.95 49.08 49.09 49.15 49.17  49.3 49.32 49.33 49.34 
##     1     1     1     1     1     1     1     1     1     1     1     2     1 
## 49.38  49.4 49.42 49.47 49.48 49.49  49.5 49.53 49.56  49.6 49.65 49.69 49.73 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
## 49.75 49.76 49.79  49.8 49.87 49.88 49.92 49.93 49.95 49.96 49.97 49.98 49.99 
##     2     2     1     2     1     1     2     1     1     1     2     1     1 
##    50 50.02 50.03 50.04 50.06 50.08 50.11 50.12 50.14  50.2 50.22 50.23 50.25 
##     1     1     1     3     1     4     1     2     1     2     1     1     1 
## 50.26 50.28 50.31 50.33 50.34 50.35 50.38 50.39  50.4 50.41 50.42 50.43 50.49 
##     1     1     1     1     1     1     1     2     1     1     1     1     1 
##  50.5 50.52 50.53 50.56 50.61 50.62 50.65 50.66 50.69  50.7 50.71 50.72 50.74 
##     1     1     1     1     3     1     1     1     2     2     2     1     2 
## 50.76 50.79 50.83 50.84 50.85 50.87 50.91 50.92 50.98 51.01 51.02 51.09 51.12 
##     2     1     1     1     2     1     1     1     1     1     1     1     1 
## 51.17 51.19 51.23 51.24  51.3 51.34 51.36 51.43 51.44 51.49 51.54  51.6 51.64 
##     1     1     1     1     1     1     1     1     1     1     2     1     2 
##  51.7 51.72 51.76 51.81 51.82 52.01 52.07 52.32 52.42 52.55  52.7 52.73 52.96 
##     1     1     1     1     1     1     1     2     1     2     1     1     1 
## 53.15 53.45 53.68 53.74 53.96 54.06  54.4 
##     1     1     1     1     1     1     1
#Análisis estadistico 
median(datamerge$SEXO,na.rm=T)
## [1] 50.33
mean(datamerge$SEXO,na.rm=T)
## [1] 49.80791
Mode(datamerge$SEXO,na.rm=T)
## [1] 50.08
## attr(,"freq")
## [1] 4
sd(datamerge$SEXO,na.rm=T)
## [1] 3.625772
table(datamerge$SEXO)
## 
## 24.67 30.74 33.98 35.73  36.7 39.08 42.27 44.41 46.92 47.41 47.66 48.03 48.54 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
##  48.6 48.66 48.67 48.69 48.95 49.08 49.09 49.15 49.17  49.3 49.32 49.33 49.34 
##     1     1     1     1     1     1     1     1     1     1     1     2     1 
## 49.38  49.4 49.42 49.47 49.48 49.49  49.5 49.53 49.56  49.6 49.65 49.69 49.73 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
## 49.75 49.76 49.79  49.8 49.87 49.88 49.92 49.93 49.95 49.96 49.97 49.98 49.99 
##     2     2     1     2     1     1     2     1     1     1     2     1     1 
##    50 50.02 50.03 50.04 50.06 50.08 50.11 50.12 50.14  50.2 50.22 50.23 50.25 
##     1     1     1     3     1     4     1     2     1     2     1     1     1 
## 50.26 50.28 50.31 50.33 50.34 50.35 50.38 50.39  50.4 50.41 50.42 50.43 50.49 
##     1     1     1     1     1     1     1     2     1     1     1     1     1 
##  50.5 50.52 50.53 50.56 50.61 50.62 50.65 50.66 50.69  50.7 50.71 50.72 50.74 
##     1     1     1     1     3     1     1     1     2     2     2     1     2 
## 50.76 50.79 50.83 50.84 50.85 50.87 50.91 50.92 50.98 51.01 51.02 51.09 51.12 
##     2     1     1     1     2     1     1     1     1     1     1     1     1 
## 51.17 51.19 51.23 51.24  51.3 51.34 51.36 51.43 51.44 51.49 51.54  51.6 51.64 
##     1     1     1     1     1     1     1     1     1     1     2     1     2 
##  51.7 51.72 51.76 51.81 51.82 52.01 52.07 52.32 52.42 52.55  52.7 52.73 52.96 
##     1     1     1     1     1     1     1     2     1     2     1     1     1 
## 53.15 53.45 53.68 53.74 53.96 54.06  54.4 
##     1     1     1     1     1     1     1
prop.table(table(datamerge$SEXO))*100
## 
##     24.67     30.74     33.98     35.73      36.7     39.08     42.27     44.41 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##     46.92     47.41     47.66     48.03     48.54      48.6     48.66     48.67 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##     48.69     48.95     49.08     49.09     49.15     49.17      49.3     49.32 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##     49.33     49.34     49.38      49.4     49.42     49.47     49.48     49.49 
## 1.2269939 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##      49.5     49.53     49.56      49.6     49.65     49.69     49.73     49.75 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 1.2269939 
##     49.76     49.79      49.8     49.87     49.88     49.92     49.93     49.95 
## 1.2269939 0.6134969 1.2269939 0.6134969 0.6134969 1.2269939 0.6134969 0.6134969 
##     49.96     49.97     49.98     49.99        50     50.02     50.03     50.04 
## 0.6134969 1.2269939 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 1.8404908 
##     50.06     50.08     50.11     50.12     50.14      50.2     50.22     50.23 
## 0.6134969 2.4539877 0.6134969 1.2269939 0.6134969 1.2269939 0.6134969 0.6134969 
##     50.25     50.26     50.28     50.31     50.33     50.34     50.35     50.38 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##     50.39      50.4     50.41     50.42     50.43     50.49      50.5     50.52 
## 1.2269939 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##     50.53     50.56     50.61     50.62     50.65     50.66     50.69      50.7 
## 0.6134969 0.6134969 1.8404908 0.6134969 0.6134969 0.6134969 1.2269939 1.2269939 
##     50.71     50.72     50.74     50.76     50.79     50.83     50.84     50.85 
## 1.2269939 0.6134969 1.2269939 1.2269939 0.6134969 0.6134969 0.6134969 1.2269939 
##     50.87     50.91     50.92     50.98     51.01     51.02     51.09     51.12 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##     51.17     51.19     51.23     51.24      51.3     51.34     51.36     51.43 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##     51.44     51.49     51.54      51.6     51.64      51.7     51.72     51.76 
## 0.6134969 0.6134969 1.2269939 0.6134969 1.2269939 0.6134969 0.6134969 0.6134969 
##     51.81     51.82     52.01     52.07     52.32     52.42     52.55      52.7 
## 0.6134969 0.6134969 0.6134969 0.6134969 1.2269939 0.6134969 1.2269939 0.6134969 
##     52.73     52.96     53.15     53.45     53.68     53.74     53.96     54.06 
## 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 0.6134969 
##      54.4 
## 0.6134969
#Para visualizar los descriptivos de manera más clara
table1::label(datamerge$SEXO) <- "Porcentaje de población femenina"
table1::table1(~SEXO, data = datamerge, )
Overall
(N=207)
Porcentaje de población femenina
Mean (SD) 49.8 (3.63)
Median [Min, Max] 50.3 [24.7, 54.4]
Missing 44 (21.3%)
#Grafico de la variable sexo
graficosexo <- (datamerge$SEXO)
hist(graficosexo, col= rainbow(10), 
     xlab="Porcentaje de población femenina",
     ylab="Países",
     main="PORCENTAJE DE POBLACIÓN FEMENINA POR PAÍS")

#Grafico de la variable SEXO en boxplot
boxplot(datamerge$SEXO, main="BOXPLOT PORCENTAJE DE POBLACIÓN FEMENINA POR PAÍS ", col="orchid",
        xlab="países", ylab="Porcentaje de población femenina")

### VARIABLE - GASTO EN EDUCACION

#Identificando la variable 
str(datamerge)
## 'data.frame':    207 obs. of  9 variables:
##  $ Matricula    : num  50.1 86.6 NA NA 11.3 ...
##   ..- attr(*, "label")= chr "Porcentaje de alumnos matriculados en el nivel secundario"
##  $ PBIPC        : num  552 5224 NA NA 3437 ...
##   ..- attr(*, "label")= chr "PBI per cápita (nominal) por país"
##  $ Pobreza      : num  54.5 14.3 NA NA 36.6 NA 25.7 32 NA NA ...
##   ..- attr(*, "label")= chr "Porcentaje de la población bajo la línea nacional de pobreza"
##  $ URBANO       : num  26 62.1 73.7 NA 66.8 24.4 92.1 63.3 43.7 86.2 ...
##   ..- attr(*, "label")= chr "Porcentaje de urbanización por país"
##  $ SEXO         : num  48.7 49.1 49.5 NA 50.5 ...
##   ..- attr(*, "label")= chr "Porcentaje de población femenina"
##  $ gastoedu     : num  4.06 2.47 4.34 3.23 3.42 2.52 5.46 2.71 NA 5.27 ...
##  $ profxes      : num  33.5 11.2 NA 8.02 26.77 ...
##  $ totalAC      : num  0.3 37.7 1.5 64.2 33.5 35.3 54.5 16.3 NA 69.3 ...
##  $ rateper1000AP: num  62 15.9 9.7 2.7 163 27.7 54.4 21.2 NA 10.1 ...
class(datamerge$gastoedu)
## [1] "numeric"
summary(datamerge$gastoedu)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   0.720   3.145   4.170   4.455   5.300  12.840      16
table(datamerge$gastoedu)
## 
##  0.72  0.98  1.11  1.28  1.45  1.46  1.89  1.93  1.97  1.99  2.11  2.13  2.16 
##     1     1     2     1     1     1     1     1     1     1     1     2     1 
##  2.22  2.23  2.24  2.26  2.33  2.43  2.47  2.49  2.52  2.56  2.57  2.58  2.61 
##     1     1     1     1     1     2     2     1     2     1     1     1     1 
##  2.63  2.65  2.67  2.71  2.75  2.78  2.85  2.86   2.9  2.93  2.94  2.97  3.05 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
##  3.06   3.1  3.11  3.14  3.15  3.16  3.17  3.19  3.23   3.3  3.32  3.39  3.42 
##     1     1     1     1     2     1     1     1     2     1     1     1     1 
##  3.44  3.55  3.58  3.59   3.6  3.64  3.68   3.7  3.72  3.73  3.74  3.76  3.79 
##     1     1     1     1     1     1     1     1     3     1     2     2     1 
##  3.83  3.84  3.85  3.88   3.9  3.91  3.96  3.99  4.01  4.04  4.06  4.07  4.08 
##     1     1     1     1     1     1     3     1     1     1     1     1     2 
##  4.09  4.12  4.13  4.17  4.21  4.29  4.34  4.37  4.42  4.43   4.5  4.53  4.56 
##     1     1     1     1     1     1     2     1     1     1     1     1     1 
##  4.59   4.6  4.64  4.65  4.66  4.67   4.7  4.71  4.72  4.74  4.79   4.8  4.83 
##     1     1     1     1     1     1     1     2     1     1     1     2     1 
##  4.84  4.88  4.91  4.92  4.96     5  5.01  5.11  5.13  5.14  5.15  5.16  5.17 
##     1     1     2     1     1     1     1     1     1     1     2     1     2 
##   5.2  5.23  5.25  5.27  5.28  5.32   5.4  5.41  5.43  5.46  5.48  5.49   5.5 
##     1     1     1     2     1     1     1     2     1     2     1     1     1 
##  5.51  5.56  5.59   5.6  5.68  5.85  5.89  6.03  6.04  6.08  6.16  6.24  6.25 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
##  6.29  6.44  6.51  6.55   6.6  6.64  6.67  6.87   6.9  7.03  7.13  7.14  7.29 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
##  7.38  7.46  7.58  7.63  7.67  7.98  9.63  9.86 11.99 12.24 12.46 12.84 
##     1     1     1     1     1     1     1     1     1     1     1     1
#Análisis estadístico 
median(datamerge$gastoedu,na.rm=T)
## [1] 4.17
mean(datamerge$gastoedu,na.rm=T)
## [1] 4.454869
Mode(datamerge$gastoedu,na.rm=T)
## [1] 3.72 3.96
## attr(,"freq")
## [1] 3
sd(datamerge$gastoedu,na.rm=T)
## [1] 1.985327
table(datamerge$gastoedu)
## 
##  0.72  0.98  1.11  1.28  1.45  1.46  1.89  1.93  1.97  1.99  2.11  2.13  2.16 
##     1     1     2     1     1     1     1     1     1     1     1     2     1 
##  2.22  2.23  2.24  2.26  2.33  2.43  2.47  2.49  2.52  2.56  2.57  2.58  2.61 
##     1     1     1     1     1     2     2     1     2     1     1     1     1 
##  2.63  2.65  2.67  2.71  2.75  2.78  2.85  2.86   2.9  2.93  2.94  2.97  3.05 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
##  3.06   3.1  3.11  3.14  3.15  3.16  3.17  3.19  3.23   3.3  3.32  3.39  3.42 
##     1     1     1     1     2     1     1     1     2     1     1     1     1 
##  3.44  3.55  3.58  3.59   3.6  3.64  3.68   3.7  3.72  3.73  3.74  3.76  3.79 
##     1     1     1     1     1     1     1     1     3     1     2     2     1 
##  3.83  3.84  3.85  3.88   3.9  3.91  3.96  3.99  4.01  4.04  4.06  4.07  4.08 
##     1     1     1     1     1     1     3     1     1     1     1     1     2 
##  4.09  4.12  4.13  4.17  4.21  4.29  4.34  4.37  4.42  4.43   4.5  4.53  4.56 
##     1     1     1     1     1     1     2     1     1     1     1     1     1 
##  4.59   4.6  4.64  4.65  4.66  4.67   4.7  4.71  4.72  4.74  4.79   4.8  4.83 
##     1     1     1     1     1     1     1     2     1     1     1     2     1 
##  4.84  4.88  4.91  4.92  4.96     5  5.01  5.11  5.13  5.14  5.15  5.16  5.17 
##     1     1     2     1     1     1     1     1     1     1     2     1     2 
##   5.2  5.23  5.25  5.27  5.28  5.32   5.4  5.41  5.43  5.46  5.48  5.49   5.5 
##     1     1     1     2     1     1     1     2     1     2     1     1     1 
##  5.51  5.56  5.59   5.6  5.68  5.85  5.89  6.03  6.04  6.08  6.16  6.24  6.25 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
##  6.29  6.44  6.51  6.55   6.6  6.64  6.67  6.87   6.9  7.03  7.13  7.14  7.29 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
##  7.38  7.46  7.58  7.63  7.67  7.98  9.63  9.86 11.99 12.24 12.46 12.84 
##     1     1     1     1     1     1     1     1     1     1     1     1
prop.table(table(datamerge$gastoedu))*100
## 
##      0.72      0.98      1.11      1.28      1.45      1.46      1.89      1.93 
## 0.5235602 0.5235602 1.0471204 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 
##      1.97      1.99      2.11      2.13      2.16      2.22      2.23      2.24 
## 0.5235602 0.5235602 0.5235602 1.0471204 0.5235602 0.5235602 0.5235602 0.5235602 
##      2.26      2.33      2.43      2.47      2.49      2.52      2.56      2.57 
## 0.5235602 0.5235602 1.0471204 1.0471204 0.5235602 1.0471204 0.5235602 0.5235602 
##      2.58      2.61      2.63      2.65      2.67      2.71      2.75      2.78 
## 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 
##      2.85      2.86       2.9      2.93      2.94      2.97      3.05      3.06 
## 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 
##       3.1      3.11      3.14      3.15      3.16      3.17      3.19      3.23 
## 0.5235602 0.5235602 0.5235602 1.0471204 0.5235602 0.5235602 0.5235602 1.0471204 
##       3.3      3.32      3.39      3.42      3.44      3.55      3.58      3.59 
## 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 
##       3.6      3.64      3.68       3.7      3.72      3.73      3.74      3.76 
## 0.5235602 0.5235602 0.5235602 0.5235602 1.5706806 0.5235602 1.0471204 1.0471204 
##      3.79      3.83      3.84      3.85      3.88       3.9      3.91      3.96 
## 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 1.5706806 
##      3.99      4.01      4.04      4.06      4.07      4.08      4.09      4.12 
## 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 1.0471204 0.5235602 0.5235602 
##      4.13      4.17      4.21      4.29      4.34      4.37      4.42      4.43 
## 0.5235602 0.5235602 0.5235602 0.5235602 1.0471204 0.5235602 0.5235602 0.5235602 
##       4.5      4.53      4.56      4.59       4.6      4.64      4.65      4.66 
## 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 
##      4.67       4.7      4.71      4.72      4.74      4.79       4.8      4.83 
## 0.5235602 0.5235602 1.0471204 0.5235602 0.5235602 0.5235602 1.0471204 0.5235602 
##      4.84      4.88      4.91      4.92      4.96         5      5.01      5.11 
## 0.5235602 0.5235602 1.0471204 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 
##      5.13      5.14      5.15      5.16      5.17       5.2      5.23      5.25 
## 0.5235602 0.5235602 1.0471204 0.5235602 1.0471204 0.5235602 0.5235602 0.5235602 
##      5.27      5.28      5.32       5.4      5.41      5.43      5.46      5.48 
## 1.0471204 0.5235602 0.5235602 0.5235602 1.0471204 0.5235602 1.0471204 0.5235602 
##      5.49       5.5      5.51      5.56      5.59       5.6      5.68      5.85 
## 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 
##      5.89      6.03      6.04      6.08      6.16      6.24      6.25      6.29 
## 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 
##      6.44      6.51      6.55       6.6      6.64      6.67      6.87       6.9 
## 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 
##      7.03      7.13      7.14      7.29      7.38      7.46      7.58      7.63 
## 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 
##      7.67      7.98      9.63      9.86     11.99     12.24     12.46     12.84 
## 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602 0.5235602
#Para visualizar los descriptivos de manera más clara
table1::label(datamerge$gastoedu) <- "Porcentaje del PBI invertido en educación por parte del Estado"
table1::table1(~PBIPC, data = datamerge, )
Overall
(N=207)
PBI per cápita (nominal) por país
Mean (SD) 18600 (26700)
Median [Min, Max] 6800 [294, 179000]
Missing 65 (31.4%)
#Grafico de la variable urbano
graficogastoedu <- (datamerge$gastoedu)
hist(graficogastoedu, col= rainbow(10),xlab="Porcentaje de inversión en educación por parte del Estado", main="PORCENTAJE DE INVERSIÓN ESTATAL EN EDUCACIÓN POR PAÍS")

#Gráfico de la variable gasatoedu en boxplot
boxplot(datamerge$gastoedu, main="BOXPLOT DE PORCENTAJE DE INVERSIÓN ESTATAL EN EDUCACIÓN POR PAÍS", col="light green",xlab="países", ylab="Porcentaje de inversión en educación por parte del Estado")

VARIABLE-ESTUDIANTES POR PROFESOS EN SECUNDARIA

#Identificando la variable 
str(datamerge)
## 'data.frame':    207 obs. of  9 variables:
##  $ Matricula    : num  50.1 86.6 NA NA 11.3 ...
##   ..- attr(*, "label")= chr "Porcentaje de alumnos matriculados en el nivel secundario"
##  $ PBIPC        : num  552 5224 NA NA 3437 ...
##   ..- attr(*, "label")= chr "PBI per cápita (nominal) por país"
##  $ Pobreza      : num  54.5 14.3 NA NA 36.6 NA 25.7 32 NA NA ...
##   ..- attr(*, "label")= chr "Porcentaje de la población bajo la línea nacional de pobreza"
##  $ URBANO       : num  26 62.1 73.7 NA 66.8 24.4 92.1 63.3 43.7 86.2 ...
##   ..- attr(*, "label")= chr "Porcentaje de urbanización por país"
##  $ SEXO         : num  48.7 49.1 49.5 NA 50.5 ...
##   ..- attr(*, "label")= chr "Porcentaje de población femenina"
##  $ gastoedu     : num  4.06 2.47 4.34 3.23 3.42 2.52 5.46 2.71 NA 5.27 ...
##   ..- attr(*, "label")= chr "Porcentaje del PBI invertido en educación por parte del Estado"
##  $ profxes      : num  33.5 11.2 NA 8.02 26.77 ...
##  $ totalAC      : num  0.3 37.7 1.5 64.2 33.5 35.3 54.5 16.3 NA 69.3 ...
##  $ rateper1000AP: num  62 15.9 9.7 2.7 163 27.7 54.4 21.2 NA 10.1 ...
class(datamerge$profxes)
## [1] "numeric"
summary(datamerge$profxes)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   5.841   9.954  13.580  16.401  20.581  72.310      51
table(datamerge$profxes)
## 
##  5.84099  6.33229  6.73221  6.95898  7.11247  7.33711  7.57537  7.58836 
##        1        1        1        1        1        1        1        1 
##  7.67398  7.80821   7.9222    7.946  8.01599  8.01689  8.26843   8.2712 
##        1        1        1        1        1        1        1        1 
##  8.30834  8.31131  8.54364  8.55985  8.56276  8.57685  8.64286  8.74033 
##        1        1        1        1        1        1        1        1 
##  8.76378  8.82794  8.98821  9.09854   9.1229  9.18187  9.29704  9.32983 
##        1        1        1        1        1        1        1        1 
##  9.51599  9.54885  9.55752  9.63133  9.69943  9.82943  9.86318  9.98461 
##        1        1        1        1        1        1        1        1 
## 10.01652 10.21867 10.23948 10.32977 10.49312 10.64648 10.69423  10.7789 
##        1        1        1        1        1        1        1        1 
## 10.81456  10.9653  10.9886 10.99168 11.04303 11.06981 11.11967 11.14556 
##        1        1        1        1        1        1        1        1 
## 11.19927 11.22247 11.29034 11.40208 11.47558 11.52893 11.54847 11.56883 
##        1        1        1        1        1        1        1        1 
## 11.97424 11.97658 12.07981 12.26127 12.42779 12.48097 12.63651 12.65841 
##        1        1        1        1        1        1        1        1 
## 12.81206  12.9392 13.07043 13.25879 13.26544 13.57979  13.5809 13.62495 
##        1        1        1        1        1        1        1        1 
## 13.62875  13.8727 14.20042 14.49262 14.51694  14.5488 14.62452 15.04762 
##        1        1        1        1        1        1        1        1 
## 15.16281 15.42052 15.43893 15.54522 16.01642 16.61873 16.65963 16.69828 
##        1        1        1        1        1        1        1        1 
## 16.72317 16.72391 16.85759 17.15997 17.34797 17.43224 17.52875 17.93859 
##        1        1        1        1        1        1        1        1 
## 18.36688 18.39079  18.4041 18.49627 18.64652 18.88356 19.00886 19.25706 
##        1        1        1        1        1        1        1        1 
##  19.2926 19.29784 20.29138 20.39658   20.568 20.62112 20.86254 21.46821 
##        1        1        1        1        1        1        1        1 
## 22.04465 22.48353 23.11995 23.19708 23.88062     24.8 24.82051 25.34293 
##        1        1        1        1        1        1        1        1 
## 25.41709 25.91073  25.9167 25.92408 25.94603 26.24584 26.59842 26.76619 
##        1        1        1        1        1        1        1        1 
## 27.13412 27.24679 27.28114 27.47489 27.55579 27.61705 28.24773 28.52287 
##        1        1        1        1        1        1        1        1 
## 28.82411 29.73171 30.83047 31.63737 33.13554 33.50124  34.2964 35.02165 
##        1        1        1        1        1        1        1        1 
## 35.09524 36.54379 40.35064 72.31002 
##        1        1        1        1
#Análisis estadístico 
median(datamerge$profxes,na.rm=T)
## [1] 13.58034
mean(datamerge$profxes,na.rm=T)
## [1] 16.40087
Mode(datamerge$profxes,na.rm=T)
## [1] NA
## attr(,"freq")
## [1] 1
sd(datamerge$profxes,na.rm=T)
## [1] 8.939118
table(datamerge$profxes)
## 
##  5.84099  6.33229  6.73221  6.95898  7.11247  7.33711  7.57537  7.58836 
##        1        1        1        1        1        1        1        1 
##  7.67398  7.80821   7.9222    7.946  8.01599  8.01689  8.26843   8.2712 
##        1        1        1        1        1        1        1        1 
##  8.30834  8.31131  8.54364  8.55985  8.56276  8.57685  8.64286  8.74033 
##        1        1        1        1        1        1        1        1 
##  8.76378  8.82794  8.98821  9.09854   9.1229  9.18187  9.29704  9.32983 
##        1        1        1        1        1        1        1        1 
##  9.51599  9.54885  9.55752  9.63133  9.69943  9.82943  9.86318  9.98461 
##        1        1        1        1        1        1        1        1 
## 10.01652 10.21867 10.23948 10.32977 10.49312 10.64648 10.69423  10.7789 
##        1        1        1        1        1        1        1        1 
## 10.81456  10.9653  10.9886 10.99168 11.04303 11.06981 11.11967 11.14556 
##        1        1        1        1        1        1        1        1 
## 11.19927 11.22247 11.29034 11.40208 11.47558 11.52893 11.54847 11.56883 
##        1        1        1        1        1        1        1        1 
## 11.97424 11.97658 12.07981 12.26127 12.42779 12.48097 12.63651 12.65841 
##        1        1        1        1        1        1        1        1 
## 12.81206  12.9392 13.07043 13.25879 13.26544 13.57979  13.5809 13.62495 
##        1        1        1        1        1        1        1        1 
## 13.62875  13.8727 14.20042 14.49262 14.51694  14.5488 14.62452 15.04762 
##        1        1        1        1        1        1        1        1 
## 15.16281 15.42052 15.43893 15.54522 16.01642 16.61873 16.65963 16.69828 
##        1        1        1        1        1        1        1        1 
## 16.72317 16.72391 16.85759 17.15997 17.34797 17.43224 17.52875 17.93859 
##        1        1        1        1        1        1        1        1 
## 18.36688 18.39079  18.4041 18.49627 18.64652 18.88356 19.00886 19.25706 
##        1        1        1        1        1        1        1        1 
##  19.2926 19.29784 20.29138 20.39658   20.568 20.62112 20.86254 21.46821 
##        1        1        1        1        1        1        1        1 
## 22.04465 22.48353 23.11995 23.19708 23.88062     24.8 24.82051 25.34293 
##        1        1        1        1        1        1        1        1 
## 25.41709 25.91073  25.9167 25.92408 25.94603 26.24584 26.59842 26.76619 
##        1        1        1        1        1        1        1        1 
## 27.13412 27.24679 27.28114 27.47489 27.55579 27.61705 28.24773 28.52287 
##        1        1        1        1        1        1        1        1 
## 28.82411 29.73171 30.83047 31.63737 33.13554 33.50124  34.2964 35.02165 
##        1        1        1        1        1        1        1        1 
## 35.09524 36.54379 40.35064 72.31002 
##        1        1        1        1
prop.table(table(datamerge$profxes))*100
## 
##   5.84099   6.33229   6.73221   6.95898   7.11247   7.33711   7.57537   7.58836 
## 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 
##   7.67398   7.80821    7.9222     7.946   8.01599   8.01689   8.26843    8.2712 
## 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 
##   8.30834   8.31131   8.54364   8.55985   8.56276   8.57685   8.64286   8.74033 
## 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 
##   8.76378   8.82794   8.98821   9.09854    9.1229   9.18187   9.29704   9.32983 
## 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 
##   9.51599   9.54885   9.55752   9.63133   9.69943   9.82943   9.86318   9.98461 
## 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 
##  10.01652  10.21867  10.23948  10.32977  10.49312  10.64648  10.69423   10.7789 
## 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 
##  10.81456   10.9653   10.9886  10.99168  11.04303  11.06981  11.11967  11.14556 
## 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 
##  11.19927  11.22247  11.29034  11.40208  11.47558  11.52893  11.54847  11.56883 
## 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 
##  11.97424  11.97658  12.07981  12.26127  12.42779  12.48097  12.63651  12.65841 
## 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 
##  12.81206   12.9392  13.07043  13.25879  13.26544  13.57979   13.5809  13.62495 
## 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 
##  13.62875   13.8727  14.20042  14.49262  14.51694   14.5488  14.62452  15.04762 
## 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 
##  15.16281  15.42052  15.43893  15.54522  16.01642  16.61873  16.65963  16.69828 
## 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 
##  16.72317  16.72391  16.85759  17.15997  17.34797  17.43224  17.52875  17.93859 
## 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 
##  18.36688  18.39079   18.4041  18.49627  18.64652  18.88356  19.00886  19.25706 
## 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 
##   19.2926  19.29784  20.29138  20.39658    20.568  20.62112  20.86254  21.46821 
## 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 
##  22.04465  22.48353  23.11995  23.19708  23.88062      24.8  24.82051  25.34293 
## 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 
##  25.41709  25.91073   25.9167  25.92408  25.94603  26.24584  26.59842  26.76619 
## 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 
##  27.13412  27.24679  27.28114  27.47489  27.55579  27.61705  28.24773  28.52287 
## 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 
##  28.82411  29.73171  30.83047  31.63737  33.13554  33.50124   34.2964  35.02165 
## 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 0.6410256 
##  35.09524  36.54379  40.35064  72.31002 
## 0.6410256 0.6410256 0.6410256 0.6410256
#Para visualizar los descriptivos de manera más clara
table1::label(datamerge$profxes) <- "Promedio de estudiantes por maestro"
table1::table1(~profxes, data = datamerge, )
Overall
(N=207)
Promedio de estudiantes por maestro
Mean (SD) 16.4 (8.94)
Median [Min, Max] 13.6 [5.84, 72.3]
Missing 51 (24.6%)
#Grafico de la variable PROFEX
graficoprofxes <- (datamerge$profxes)
hist(graficoprofxes, col= rainbow(10), 
     ylab="Países",
     xlab="Cantidad de estudiantes por profesor",
     main="CANTIDAD DE ESTUDIANTES EN EDUCACIÓN SECUNDARIA POR PROFESOR POR PAÍSES")

#Grafico de la variable profex en boxplot
boxplot(datamerge$profxes, main="BOXPLOT DE CANTIDAD DE ESTUDIANTES EN EDUCACIÓN SECUNDARIA POR PROFESOR POR PAÍSES ", col="paleturquoise", xlab="países", ylab="Cantidad de estudiantes por profesor")

VARIABLE- PORCENTAJE DEL CONSUMO DE ALCOHOL DE LOS JÓVENES

#Identificando la variable 
str(datamerge)
## 'data.frame':    207 obs. of  9 variables:
##  $ Matricula    : num  50.1 86.6 NA NA 11.3 ...
##   ..- attr(*, "label")= chr "Porcentaje de alumnos matriculados en el nivel secundario"
##  $ PBIPC        : num  552 5224 NA NA 3437 ...
##   ..- attr(*, "label")= chr "PBI per cápita (nominal) por país"
##  $ Pobreza      : num  54.5 14.3 NA NA 36.6 NA 25.7 32 NA NA ...
##   ..- attr(*, "label")= chr "Porcentaje de la población bajo la línea nacional de pobreza"
##  $ URBANO       : num  26 62.1 73.7 NA 66.8 24.4 92.1 63.3 43.7 86.2 ...
##   ..- attr(*, "label")= chr "Porcentaje de urbanización por país"
##  $ SEXO         : num  48.7 49.1 49.5 NA 50.5 ...
##   ..- attr(*, "label")= chr "Porcentaje de población femenina"
##  $ gastoedu     : num  4.06 2.47 4.34 3.23 3.42 2.52 5.46 2.71 NA 5.27 ...
##   ..- attr(*, "label")= chr "Porcentaje del PBI invertido en educación por parte del Estado"
##  $ profxes      : num  33.5 11.2 NA 8.02 26.77 ...
##   ..- attr(*, "label")= chr "Promedio de estudiantes por maestro"
##  $ totalAC      : num  0.3 37.7 1.5 64.2 33.5 35.3 54.5 16.3 NA 69.3 ...
##  $ rateper1000AP: num  62 15.9 9.7 2.7 163 27.7 54.4 21.2 NA 10.1 ...
class(datamerge$totalAC)
## [1] "numeric"
summary(datamerge$totalAC)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##    0.10   12.90   23.60   28.96   45.20   86.40      18
table(datamerge$totalAC)
## 
##  0.1  0.2  0.3  0.5  0.6    1  1.1  1.3  1.4  1.5  1.7    2  2.5  2.6    3  3.3 
##    1    1    3    1    1    1    1    2    1    3    1    1    1    1    1    1 
##  3.5  3.8  6.6  7.4  7.9  8.2  8.5  9.1  9.8  9.9   10   11 11.5 11.7 11.8   12 
##    1    2    1    3    2    1    1    1    1    1    1    1    1    1    2    1 
## 12.4 12.5 12.6 12.8 12.9 13.1 13.3 13.8   14   15 15.3 15.4 15.9 16.2 16.3 16.5 
##    1    1    1    2    2    1    2    1    1    1    2    1    1    1    1    1 
## 16.8 16.9 17.1 17.2 17.5 17.6   18 18.3 18.4 18.7   19 19.2 19.3 19.4 19.5 19.6 
##    1    1    1    1    1    1    1    1    1    3    1    1    1    1    1    1 
## 20.4 20.5 20.8 20.9 21.1 22.4 22.6 22.7   23 23.4 23.6 23.7 24.4 24.5 24.7   25 
##    1    1    2    1    1    1    1    1    1    1    4    1    2    1    1    1 
## 25.2 25.5 26.1 26.4 26.8 27.3 27.4 28.2 28.7 29.1 29.8 31.3   32 32.2 32.5 33.2 
##    2    1    2    2    1    2    1    1    1    1    1    2    1    1    1    1 
## 33.5 34.4 34.9 35.3   36 36.9 37.3 37.5 37.7 38.5 39.4 39.5 40.4 40.6 41.2 41.4 
##    1    1    1    2    1    1    1    1    1    1    2    1    1    1    1    1 
## 43.9 45.2 45.5 47.3 47.4 49.4 50.5 50.8 51.7 52.3 52.9 53.4 54.1 54.4 54.5 54.6 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 55.2 55.3 55.6 56.5 56.6 57.1 57.2   58 59.2 59.3 59.6 59.9 60.9 61.9   62 62.3 
##    1    1    1    1    1    1    1    2    1    1    1    1    1    1    1    2 
## 63.8 63.9 64.2 64.6 65.3 65.4 66.2 68.1 68.8 69.3 70.2 70.6 71.4   72 86.4 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1
#Análisis estadístico 
median(datamerge$totalAC,na.rm=T)
## [1] 23.6
mean(datamerge$totalAC,na.rm=T)
## [1] 28.9582
Mode(datamerge$totalAC,na.rm=T)
## [1] 23.6
## attr(,"freq")
## [1] 4
sd(datamerge$totalAC,na.rm=T)
## [1] 20.83547
table(datamerge$totalAC)
## 
##  0.1  0.2  0.3  0.5  0.6    1  1.1  1.3  1.4  1.5  1.7    2  2.5  2.6    3  3.3 
##    1    1    3    1    1    1    1    2    1    3    1    1    1    1    1    1 
##  3.5  3.8  6.6  7.4  7.9  8.2  8.5  9.1  9.8  9.9   10   11 11.5 11.7 11.8   12 
##    1    2    1    3    2    1    1    1    1    1    1    1    1    1    2    1 
## 12.4 12.5 12.6 12.8 12.9 13.1 13.3 13.8   14   15 15.3 15.4 15.9 16.2 16.3 16.5 
##    1    1    1    2    2    1    2    1    1    1    2    1    1    1    1    1 
## 16.8 16.9 17.1 17.2 17.5 17.6   18 18.3 18.4 18.7   19 19.2 19.3 19.4 19.5 19.6 
##    1    1    1    1    1    1    1    1    1    3    1    1    1    1    1    1 
## 20.4 20.5 20.8 20.9 21.1 22.4 22.6 22.7   23 23.4 23.6 23.7 24.4 24.5 24.7   25 
##    1    1    2    1    1    1    1    1    1    1    4    1    2    1    1    1 
## 25.2 25.5 26.1 26.4 26.8 27.3 27.4 28.2 28.7 29.1 29.8 31.3   32 32.2 32.5 33.2 
##    2    1    2    2    1    2    1    1    1    1    1    2    1    1    1    1 
## 33.5 34.4 34.9 35.3   36 36.9 37.3 37.5 37.7 38.5 39.4 39.5 40.4 40.6 41.2 41.4 
##    1    1    1    2    1    1    1    1    1    1    2    1    1    1    1    1 
## 43.9 45.2 45.5 47.3 47.4 49.4 50.5 50.8 51.7 52.3 52.9 53.4 54.1 54.4 54.5 54.6 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 55.2 55.3 55.6 56.5 56.6 57.1 57.2   58 59.2 59.3 59.6 59.9 60.9 61.9   62 62.3 
##    1    1    1    1    1    1    1    2    1    1    1    1    1    1    1    2 
## 63.8 63.9 64.2 64.6 65.3 65.4 66.2 68.1 68.8 69.3 70.2 70.6 71.4   72 86.4 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1
prop.table(table(datamerge$totalAC))*100
## 
##       0.1       0.2       0.3       0.5       0.6         1       1.1       1.3 
## 0.5291005 0.5291005 1.5873016 0.5291005 0.5291005 0.5291005 0.5291005 1.0582011 
##       1.4       1.5       1.7         2       2.5       2.6         3       3.3 
## 0.5291005 1.5873016 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 
##       3.5       3.8       6.6       7.4       7.9       8.2       8.5       9.1 
## 0.5291005 1.0582011 0.5291005 1.5873016 1.0582011 0.5291005 0.5291005 0.5291005 
##       9.8       9.9        10        11      11.5      11.7      11.8        12 
## 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 1.0582011 0.5291005 
##      12.4      12.5      12.6      12.8      12.9      13.1      13.3      13.8 
## 0.5291005 0.5291005 0.5291005 1.0582011 1.0582011 0.5291005 1.0582011 0.5291005 
##        14        15      15.3      15.4      15.9      16.2      16.3      16.5 
## 0.5291005 0.5291005 1.0582011 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 
##      16.8      16.9      17.1      17.2      17.5      17.6        18      18.3 
## 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 
##      18.4      18.7        19      19.2      19.3      19.4      19.5      19.6 
## 0.5291005 1.5873016 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 
##      20.4      20.5      20.8      20.9      21.1      22.4      22.6      22.7 
## 0.5291005 0.5291005 1.0582011 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 
##        23      23.4      23.6      23.7      24.4      24.5      24.7        25 
## 0.5291005 0.5291005 2.1164021 0.5291005 1.0582011 0.5291005 0.5291005 0.5291005 
##      25.2      25.5      26.1      26.4      26.8      27.3      27.4      28.2 
## 1.0582011 0.5291005 1.0582011 1.0582011 0.5291005 1.0582011 0.5291005 0.5291005 
##      28.7      29.1      29.8      31.3        32      32.2      32.5      33.2 
## 0.5291005 0.5291005 0.5291005 1.0582011 0.5291005 0.5291005 0.5291005 0.5291005 
##      33.5      34.4      34.9      35.3        36      36.9      37.3      37.5 
## 0.5291005 0.5291005 0.5291005 1.0582011 0.5291005 0.5291005 0.5291005 0.5291005 
##      37.7      38.5      39.4      39.5      40.4      40.6      41.2      41.4 
## 0.5291005 0.5291005 1.0582011 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 
##      43.9      45.2      45.5      47.3      47.4      49.4      50.5      50.8 
## 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 
##      51.7      52.3      52.9      53.4      54.1      54.4      54.5      54.6 
## 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 
##      55.2      55.3      55.6      56.5      56.6      57.1      57.2        58 
## 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 1.0582011 
##      59.2      59.3      59.6      59.9      60.9      61.9        62      62.3 
## 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 1.0582011 
##      63.8      63.9      64.2      64.6      65.3      65.4      66.2      68.1 
## 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 
##      68.8      69.3      70.2      70.6      71.4        72      86.4 
## 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005 0.5291005
#Para visualizar los descriptivos de manera más clara
table1::label(datamerge$totalAC) <- "Porcentaje de jóvenes que consumen alcohol"
table1::table1(~totalAC, data = datamerge, )
Overall
(N=207)
Porcentaje de jóvenes que consumen alcohol
Mean (SD) 29.0 (20.8)
Median [Min, Max] 23.6 [0.100, 86.4]
Missing 18 (8.7%)
#Gráfico de la variable urbano
graficototalAC <- (datamerge$totalAC)
hist(graficototalAC, col= rainbow(10), 
     xlab="Porcentaje de jovenes que consumen alcohol",
     ylab="Países",
     main="PORCENTAJE DE JOVENES QUE CONSUMEN ALCOHOL POR PAÍS")

#Gráfico de la variable totalAC en boxplot
boxplot(datamerge$totalAC, main="BOXPLOT DE PORCENTAJE DE JÓVENES QUE CONSUMEN ALCOHOL POR PAÍS  ", col="Skyblue",
        xlab="países", ylab="Porcentaje de jovenes que consumen alcohol")

VARIABLE- TASA DE NATALIDAD DE ADOLESCENTES POR PAÍS (EMBARAZOS A TEMPRANA EDAD)

#Identificando la variable 
str(datamerge)
## 'data.frame':    207 obs. of  9 variables:
##  $ Matricula    : num  50.1 86.6 NA NA 11.3 ...
##   ..- attr(*, "label")= chr "Porcentaje de alumnos matriculados en el nivel secundario"
##  $ PBIPC        : num  552 5224 NA NA 3437 ...
##   ..- attr(*, "label")= chr "PBI per cápita (nominal) por país"
##  $ Pobreza      : num  54.5 14.3 NA NA 36.6 NA 25.7 32 NA NA ...
##   ..- attr(*, "label")= chr "Porcentaje de la población bajo la línea nacional de pobreza"
##  $ URBANO       : num  26 62.1 73.7 NA 66.8 24.4 92.1 63.3 43.7 86.2 ...
##   ..- attr(*, "label")= chr "Porcentaje de urbanización por país"
##  $ SEXO         : num  48.7 49.1 49.5 NA 50.5 ...
##   ..- attr(*, "label")= chr "Porcentaje de población femenina"
##  $ gastoedu     : num  4.06 2.47 4.34 3.23 3.42 2.52 5.46 2.71 NA 5.27 ...
##   ..- attr(*, "label")= chr "Porcentaje del PBI invertido en educación por parte del Estado"
##  $ profxes      : num  33.5 11.2 NA 8.02 26.77 ...
##   ..- attr(*, "label")= chr "Promedio de estudiantes por maestro"
##  $ totalAC      : num  0.3 37.7 1.5 64.2 33.5 35.3 54.5 16.3 NA 69.3 ...
##   ..- attr(*, "label")= chr "Porcentaje de jóvenes que consumen alcohol"
##  $ rateper1000AP: num  62 15.9 9.7 2.7 163 27.7 54.4 21.2 NA 10.1 ...
class(datamerge$rateper1000AP)
## [1] "numeric"
summary(datamerge$rateper1000AP)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##    1.00   12.53   38.60   50.94   75.97  229.00      13
table(datamerge$rateper1000AP)
## 
##     1   1.4   2.4   2.5   2.7   2.8   2.9   3.4     4   4.1   4.4   4.6   4.9 
##     2     1     1     1     1     1     2     1     2     1     2     1     1 
##   5.4   5.7   5.9     6   6.3   6.7   7.1   7.2   7.7     8   8.5   8.6   8.7 
##     1     1     1     1     1     1     1     1     1     1     1     2     1 
##   8.9   9.1   9.2   9.3   9.7   9.8   9.9    10  10.1  10.5  10.7  10.9    11 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
##  11.1  11.7  12.1  12.4  12.5  12.6  13.3  13.6  13.8  14.2  15.1  15.2  15.9 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
##  16.1  18.8  18.9    19  19.1    20  20.9    21  21.2  21.4  21.5  22.9  23.1 
##     1     1     1     1     1     1     1     2     1     1     1     1     1 
##    24  25.6  26.4  26.6  26.8    27  27.7    28  28.4    29    30  30.1  32.3 
##     1     1     1     1     1     1     1     2     1     1     1     1     1 
##  32.6  33.2  33.8  33.9  35.8  35.9    36  37.8    38  38.1  38.2    39  39.2 
##     1     1     1     1     1     1     2     1     1     1     1     1     1 
##  40.9    41  41.9    44    45    46  46.1    48  48.4    49  49.7    50  50.4 
##     1     1     1     2     1     1     1     1     1     1     1     1     1 
##    51  51.2  51.7  51.8    52  52.3  52.7    54  54.3  54.4  54.8  56.7  57.4 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
##  58.2    61    62  63.9  64.3    67  67.2    68  68.3  70.3  70.5    71  71.1 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
##    72  73.7    74  75.1  75.9    76  77.5  77.6    78  78.9  79.5    80  82.1 
##     1     1     2     1     1     1     1     1     1     1     1     1     1 
##  83.4    84  84.5    86  86.8  87.1  88.2  88.7    91    92    94  94.5    96 
##     1     1     1     1     1     1     1     2     1     2     2     1     1 
## 101.3   106 106.4   108 111.3   119   120   123 123.3 131.5 132.3   135 137.6 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
## 138.1 138.9 150.3   152   154 158.1   163   164   176 179.4   180   229 
##     1     1     1     1     1     1     1     1     1     1     1     1
#Análisis estadístico 
median(datamerge$rateper1000AP,na.rm=T)
## [1] 38.6
mean(datamerge$rateper1000AP,na.rm=T)
## [1] 50.94278
Mode(datamerge$rateper1000AP,na.rm=T)
##  [1]  1.0  2.9  4.0  4.4  8.6 21.0 28.0 36.0 44.0 74.0 88.7 92.0 94.0
## attr(,"freq")
## [1] 2
sd(datamerge$rateper1000AP,na.rm=T)
## [1] 45.1498
table(datamerge$rateper1000AP)
## 
##     1   1.4   2.4   2.5   2.7   2.8   2.9   3.4     4   4.1   4.4   4.6   4.9 
##     2     1     1     1     1     1     2     1     2     1     2     1     1 
##   5.4   5.7   5.9     6   6.3   6.7   7.1   7.2   7.7     8   8.5   8.6   8.7 
##     1     1     1     1     1     1     1     1     1     1     1     2     1 
##   8.9   9.1   9.2   9.3   9.7   9.8   9.9    10  10.1  10.5  10.7  10.9    11 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
##  11.1  11.7  12.1  12.4  12.5  12.6  13.3  13.6  13.8  14.2  15.1  15.2  15.9 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
##  16.1  18.8  18.9    19  19.1    20  20.9    21  21.2  21.4  21.5  22.9  23.1 
##     1     1     1     1     1     1     1     2     1     1     1     1     1 
##    24  25.6  26.4  26.6  26.8    27  27.7    28  28.4    29    30  30.1  32.3 
##     1     1     1     1     1     1     1     2     1     1     1     1     1 
##  32.6  33.2  33.8  33.9  35.8  35.9    36  37.8    38  38.1  38.2    39  39.2 
##     1     1     1     1     1     1     2     1     1     1     1     1     1 
##  40.9    41  41.9    44    45    46  46.1    48  48.4    49  49.7    50  50.4 
##     1     1     1     2     1     1     1     1     1     1     1     1     1 
##    51  51.2  51.7  51.8    52  52.3  52.7    54  54.3  54.4  54.8  56.7  57.4 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
##  58.2    61    62  63.9  64.3    67  67.2    68  68.3  70.3  70.5    71  71.1 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
##    72  73.7    74  75.1  75.9    76  77.5  77.6    78  78.9  79.5    80  82.1 
##     1     1     2     1     1     1     1     1     1     1     1     1     1 
##  83.4    84  84.5    86  86.8  87.1  88.2  88.7    91    92    94  94.5    96 
##     1     1     1     1     1     1     1     2     1     2     2     1     1 
## 101.3   106 106.4   108 111.3   119   120   123 123.3 131.5 132.3   135 137.6 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
## 138.1 138.9 150.3   152   154 158.1   163   164   176 179.4   180   229 
##     1     1     1     1     1     1     1     1     1     1     1     1
prop.table(table(datamerge$rateper1000AP))*100
## 
##         1       1.4       2.4       2.5       2.7       2.8       2.9       3.4 
## 1.0309278 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 1.0309278 0.5154639 
##         4       4.1       4.4       4.6       4.9       5.4       5.7       5.9 
## 1.0309278 0.5154639 1.0309278 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 
##         6       6.3       6.7       7.1       7.2       7.7         8       8.5 
## 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 
##       8.6       8.7       8.9       9.1       9.2       9.3       9.7       9.8 
## 1.0309278 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 
##       9.9        10      10.1      10.5      10.7      10.9        11      11.1 
## 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 
##      11.7      12.1      12.4      12.5      12.6      13.3      13.6      13.8 
## 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 
##      14.2      15.1      15.2      15.9      16.1      18.8      18.9        19 
## 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 
##      19.1        20      20.9        21      21.2      21.4      21.5      22.9 
## 0.5154639 0.5154639 0.5154639 1.0309278 0.5154639 0.5154639 0.5154639 0.5154639 
##      23.1        24      25.6      26.4      26.6      26.8        27      27.7 
## 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 
##        28      28.4        29        30      30.1      32.3      32.6      33.2 
## 1.0309278 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 
##      33.8      33.9      35.8      35.9        36      37.8        38      38.1 
## 0.5154639 0.5154639 0.5154639 0.5154639 1.0309278 0.5154639 0.5154639 0.5154639 
##      38.2        39      39.2      40.9        41      41.9        44        45 
## 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 1.0309278 0.5154639 
##        46      46.1        48      48.4        49      49.7        50      50.4 
## 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 
##        51      51.2      51.7      51.8        52      52.3      52.7        54 
## 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 
##      54.3      54.4      54.8      56.7      57.4      58.2        61        62 
## 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 
##      63.9      64.3        67      67.2        68      68.3      70.3      70.5 
## 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 
##        71      71.1        72      73.7        74      75.1      75.9        76 
## 0.5154639 0.5154639 0.5154639 0.5154639 1.0309278 0.5154639 0.5154639 0.5154639 
##      77.5      77.6        78      78.9      79.5        80      82.1      83.4 
## 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 
##        84      84.5        86      86.8      87.1      88.2      88.7        91 
## 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 1.0309278 0.5154639 
##        92        94      94.5        96     101.3       106     106.4       108 
## 1.0309278 1.0309278 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 
##     111.3       119       120       123     123.3     131.5     132.3       135 
## 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 
##     137.6     138.1     138.9     150.3       152       154     158.1       163 
## 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639 
##       164       176     179.4       180       229 
## 0.5154639 0.5154639 0.5154639 0.5154639 0.5154639
#Para visualizar los descriptivos de manera más clara
table1::label(datamerge$rateper1000AP) <- "Porcentaje de natalidad por cada 1000 mujeres de 15 a 19 años"
table1::table1(~rateper1000AP, data = datamerge, )
Overall
(N=207)
Porcentaje de natalidad por cada 1000 mujeres de 15 a 19 años
Mean (SD) 50.9 (45.1)
Median [Min, Max] 38.6 [1.00, 229]
Missing 13 (6.3%)
#Grafico de la variable rater1000AP
graficorateper1000AP<- (datamerge$rateper1000AP)
hist(graficorateper1000AP, col= rainbow(10), 
     xlab="Tasa de natalidad por cada 1000 mujeres de 15 a 19 años",
     ylab="Países",
     main="TASA DE NATALIDAD POR 1000 MUJERES DE 15 A 19 AÑOS POR PAÍS")

#Grafico de la variable rateper1000AP en boxplot
boxplot(datamerge$rateper1000AP, main="BOXPLOT DE NATALIDAD POR 1000 MUJERES DE 15 A 19 AÑOS POR PAÍS", col="goldenrod",xlab="países", ylab="Tasa de natalidad por 1000 mujeres de 15 a 19 años")

ANÁLISIS BIVARIADO

V. EXPLICADA = MATRICULA VARIABLES EXPLICATIVAS:

A)v. EXPLICATIVA1= PBIPC

attach(datamerge)
## The following object is masked _by_ .GlobalEnv:
## 
##     Pobreza
plot(datamerge$Matricula,datamerge$PBIPC)

cor.test(datamerge$Matricula, datamerge$PBIPC)
## 
##  Pearson's product-moment correlation
## 
## data:  datamerge$Matricula and datamerge$PBIPC
## t = 6.0444, df = 140, p-value = 1.288e-08
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.3137040 0.5764519
## sample estimates:
##       cor 
## 0.4549229

B)v. EXPLICATIVA2= Pobreza

plot(datamerge$Matricula, datamerge$Pobreza)

cor.test(datamerge$Matricula, datamerge$Pobreza)
## 
##  Pearson's product-moment correlation
## 
## data:  datamerge$Matricula and datamerge$Pobreza
## t = -10.674, df = 119, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.7804528 -0.5951926
## sample estimates:
##        cor 
## -0.6993865

C)v. EXPLICATIVA3= URBANO

plot(datamerge$Matricula, datamerge$URBANO)

cor.test(datamerge$Matricula, datamerge$URBANO)
## 
##  Pearson's product-moment correlation
## 
## data:  datamerge$Matricula and datamerge$URBANO
## t = 9.4097, df = 130, p-value = 2.355e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.5224676 0.7281876
## sample estimates:
##      cor 
## 0.636515

D)v. EXPLICATIVA4= SEXO

plot(datamerge$Matricula, datamerge$SEXO)

cor.test(datamerge$Matricula, datamerge$SEXO)
## 
##  Pearson's product-moment correlation
## 
## data:  datamerge$Matricula and datamerge$SEXO
## t = -0.94575, df = 130, p-value = 0.346
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.25000532  0.08947202
## sample estimates:
##         cor 
## -0.08266421

E)v. EXPLICATIVA5= GASTOEDU

plot(datamerge$Matricula,datamerge$gastoedu)

cor.test(datamerge$Matricula, datamerge$gastoedu)
## 
##  Pearson's product-moment correlation
## 
## data:  datamerge$Matricula and datamerge$gastoedu
## t = 2.6088, df = 153, p-value = 0.009988
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.05035626 0.35254504
## sample estimates:
##       cor 
## 0.2063662

F) v. EXPLICATIVA6= PROFXES

plot(datamerge$Matricula,datamerge$profxes)

cor.test(datamerge$Matricula,datamerge$profxes)
## 
##  Pearson's product-moment correlation
## 
## data:  datamerge$Matricula and datamerge$profxes
## t = -10.505, df = 141, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.7456619 -0.5593027
## sample estimates:
##        cor 
## -0.6626172

G) v. EXPLICATIVA7= totalAC

plot(datamerge$Matricula,datamerge$totalAC)

cor.test(datamerge$Matricula,datamerge$totalAC)
## 
##  Pearson's product-moment correlation
## 
## data:  datamerge$Matricula and datamerge$totalAC
## t = 8.6096, df = 151, p-value = 8.955e-15
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.4567218 0.6713638
## sample estimates:
##       cor 
## 0.5738146

H) v. EXPLICATIVA8= rateper1000AP

plot(datamerge$Matricula,datamerge$rateper1000AP)

cor.test(datamerge$Matricula,datamerge$rateper1000AP)
## 
##  Pearson's product-moment correlation
## 
## data:  datamerge$Matricula and datamerge$rateper1000AP
## t = -18.885, df = 154, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.8776083 -0.7811665
## sample estimates:
##        cor 
## -0.8357201

ANÁLISIS FACTORIAL EXPLORATORIO: VERIFICAR LATENTES

  1. Importar data (ya limpia) La data ya estaba importada.
#library(rio)
#link="https://github.com/alessiasibille17/Trabajo_Stad/raw/master/entrega2_final/mergefinal.xlsx"
#datamerge=import(link)
  1. Preparación de data
datamerge=na.omit(datamerge)
#subdata con que se va a analizar la factorización/clusterización
subdata1=datamerge[,c(2:9)]
  1. FACTORIZACIÓN

Creamos un data frame especial para el análisis de factorización ya que en la data “subdata” está incluida la variable Sexo, la cual es de control.

subdataefa=datamerge[,c(2:4, 6:9)]

3.1 Matriz de correlaciones

library(polycor)
## Warning: package 'polycor' was built under R version 4.0.3
## 
## Attaching package: 'polycor'
## The following object is masked from 'package:psych':
## 
##     polyserial
corMatrix=polycor::hetcor(subdataefa)$correlations

3.2 Verificamos si el análisis factorial será util dados los datos disponibles

library(psych)
KMO(corMatrix)$MSA
## [1] 0.8239962

MSA es 0.82… >0.06 así que OK

3.3 Para ver como cada variable contribuye al “adequacy”:

KMO(corMatrix)$MSAi
##         PBIPC       Pobreza        URBANO      gastoedu       profxes 
##     0.7894311     0.8157053     0.8882222     0.8883019     0.8491775 
##       totalAC rateper1000AP 
##     0.8042819     0.7991507

Todas OK >0.78

3.4 Sólo falta confirmar que la matriz de correlación cumple los dos requisitos solicitados: a) Hnula: La matriz de correlacion es una matriz identidad

cortest.bartlett(corMatrix,n=nrow(subdataefa))$p.value>0.05
## [1] FALSE
  1. Hnula: La matriz de correlacion es una matriz singular.
matrixcalc::is.singular.matrix(corMatrix)
## [1] FALSE

Ambas FALSE, todo bien en este sentido.

3.5 Cuántas variables latentes se sugiere

#install.packages("see")
library(see)
## Warning: package 'see' was built under R version 4.0.3
sugerencia=parameters::n_factors(corMatrix)
plot(sugerencia)

Recomienda solo 1 factor; no responde con lo propuesto en la teoría.

3.6 Gráfico

library(GPArotation)
## Warning: package 'GPArotation' was built under R version 4.0.3
resfa <- fa(subdataefa,
            nfactors = 1,
            rotate = "varimax")

fa.diagram(resfa)

Pone todas en una misma latente, pero la variable GastoEdu sale con 0.4. Antes salía en el aporte 0.88

CLUSTERIZACIÓN

Traemos la data

#Subdata para poder realizar la clusterización
subdata=datamerge[,-1]
#Calcular distancia
library(cluster)
g.dist = daisy(subdata, metric="gower",stand=T) 

#Cluster de partición... Cuántos debería haber? 
library(factoextra)
## Loading required package: ggplot2
## 
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
## 
##     %+%, alpha
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
#para partición
fviz_nbclust(subdata, pam,diss=g.dist,method = "gap_stat",k.max = 10,verbose = F)

#para jerarquización
fviz_nbclust(subdata, hcut,diss=g.dist,method = "gap_stat",k.max = 10,verbose = F) 

Ambos métodos recomiendan 5 clusters.

#creación de clusters
res.pam = pam(g.dist,5,cluster.only = F) #particion
res.agnes = hcut(g.dist, k = 5,hc_func='agnes',hc_method = "ward.D") #aglomerativa
res.diana = hcut(g.dist, k = 5,hc_func='diana') #divisivo

##Gráficos width: para saber cual es el método más apropiado
fviz_silhouette(res.pam)
##   cluster size ave.sil.width
## 1       1   21          0.23
## 2       2   26          0.05
## 3       3   20          0.29
## 4       4   10          0.41
## 5       5   18          0.14

fviz_silhouette(res.agnes)
##   cluster size ave.sil.width
## 1       1   21          0.10
## 2       2   33          0.16
## 3       3   12          0.17
## 4       4   20          0.31
## 5       5    9          0.44

fviz_silhouette(res.diana)
##   cluster size ave.sil.width
## 1       1   13          0.15
## 2       2   22          0.13
## 3       3   18          0.14
## 4       4   29          0.33
## 5       5   13          0.10

Lo que se observa es que el método jerárquico aglomerativo es el más adecuado ya que tiene el mayor valor de width (0.21 frente al 0.19 del método particionante y divisivo)

Creo columnas

subdata$clusterPT=res.pam$cluster #particionante
subdata$clustAGLO=res.diana$cluster #aglomerativo  
subdata$clustDIV=res.diana$cluster #divisivo
library(plyr) 
agg= aggregate(as.matrix(cbind(subdata[,c(1:8)]))~ clustAGLO, data=subdata,
          FUN=plyr::each(MD = median, Media = mean))
# convertir en data frame, y 
tablaResumen=t(as.data.frame(agg))
tablaResumen
##                            [,1]        [,2]        [,3]         [,4]
## clustAGLO              1.000000    2.000000    3.000000     4.000000
## PBIPC.MD            1730.440000 7110.405000  695.245000 23241.890000
## PBIPC.Media         2084.003077 7891.393636 1122.970000 29721.704828
## Pobreza.MD            29.600000   19.300000   52.400000    15.100000
## Pobreza.Media         31.730769   19.136364   53.372222    16.513793
## URBANO.MD             29.400000   67.900000   37.800000    75.700000
## URBANO.Media          31.069231   68.754545   36.983333    75.713793
## SEXO.MD               49.760000   50.340000   50.415000    51.230000
## SEXO.Media            49.645385   50.309545   50.568889    51.431379
## gastoedu.MD            2.650000    4.460000    4.625000     4.840000
## gastoedu.Media         2.960769    4.466818    4.248889     4.983448
## profxes.MD            28.247730   13.890660   25.794385     9.699430
## profxes.Media         26.585812   15.523024   27.088423    10.456869
## totalAC.MD             8.200000   24.350000   13.650000    58.000000
## totalAC.Media         10.130769   23.409091   16.238889    58.551724
## rateper1000AP.MD      62.000000   39.350000  134.950000    10.500000
## rateper1000AP.Media   53.961538   40.518182  129.877778    14.717241
##                            [,5]
## clustAGLO              5.000000
## PBIPC.MD            2500.110000
## PBIPC.Media         3109.073077
## Pobreza.MD            30.000000
## Pobreza.Media         29.246154
## URBANO.MD             57.200000
## URBANO.Media          48.976923
## SEXO.MD               49.990000
## SEXO.Media            50.207692
## gastoedu.MD            4.340000
## gastoedu.Media         4.832308
## profxes.MD            18.404100
## profxes.Media         19.315377
## totalAC.MD            18.300000
## totalAC.Media         18.961538
## rateper1000AP.MD      74.000000
## rateper1000AP.Media   73.907692
# data.frame equivalente a ese elemento
widths.aglomerativo=data.frame(res.agnes $silinfo$widths)
# Creamos un vector que sea el nombre de la región. Lo jalamos del nombre de la fila.
widths.aglomerativo$Id=row.names(widths.aglomerativo)
# Creamos un objeto que sea los nombres de aquellos casos cuyos widths sean menor a 0. 
malos.widths.aglomerativo=widths.aglomerativo[widths.aglomerativo$sil_width<0,'Id']
malos.widths.aglomerativo
## [1] "Tonga"        "Guatemala"    "Burkina Faso" "Eritrea"      "Benin"       
## [6] "Malta"
#cantidad de casos
length(malos.widths.aglomerativo)
## [1] 6

Son 6 casos mal asignados en el método aglomerativo: Tonga, Guatemala, Burkina Faso, Eritrea, Benins y Malta

Viendo qué países corresponden a cada cluster

#crear esta columna
subdata$Id=row.names(subdata)
#Ahora pedimos
subdata[subdata$clustAGLO==1,'Id']
##  [1] "Afghanistan"      "Bangladesh"       "Comoros"          "Eritrea"         
##  [5] "Ethiopia"         "India"            "Mauritania"       "Pakistan"        
##  [9] "Papua New Guinea" "Philippines"      "Rwanda"           "Sri Lanka"       
## [13] "Tonga"
subdata[subdata$clustAGLO==2,'Id']
##  [1] "Albania"            "Armenia"            "Brazil"            
##  [4] "Colombia"           "Costa Rica"         "Djibouti"          
##  [7] "Dominican Republic" "Ecuador"            "Georgia"           
## [10] "Jamaica"            "Jordan"             "Kazakhstan"        
## [13] "Malaysia"           "Mauritius"          "Mexico"            
## [16] "Panama"             "Peru"               "Seychelles"        
## [19] "South Africa"       "Thailand"           "Turkey"            
## [22] "Uzbekistan"
subdata[subdata$clustAGLO==3,'Id']
##  [1] "Angola"                   "Burkina Faso"            
##  [3] "Burundi"                  "Central African Republic"
##  [5] "Chad"                     "Guatemala"               
##  [7] "Guinea"                   "Lesotho"                 
##  [9] "Liberia"                  "Madagascar"              
## [11] "Malawi"                   "Mali"                    
## [13] "Mozambique"               "Niger"                   
## [15] "Senegal"                  "Sierra Leone"            
## [17] "Togo"                     "Zimbabwe"
subdata[subdata$clustAGLO==4,'Id']
##  [1] "Argentina"     "Austria"       "Belarus"       "Belgium"      
##  [5] "Bulgaria"      "Chile"         "Croatia"       "Denmark"      
##  [9] "Estonia"       "France"        "Germany"       "Greece"       
## [13] "Hungary"       "Italy"         "Latvia"        "Lithuania"    
## [17] "Malta"         "Netherlands"   "Poland"        "Portugal"     
## [21] "Romania"       "Serbia"        "Slovenia"      "Spain"        
## [25] "Sweden"        "Switzerland"   "Ukraine"       "United States"
## [29] "Uruguay"
subdata[subdata$clustAGLO==5,'Id']
##  [1] "Belize"      "Benin"       "Bhutan"      "Cameroon"    "El Salvador"
##  [6] "Fiji"        "Ghana"       "Guyana"      "Honduras"    "Nepal"      
## [11] "Nicaragua"   "Paraguay"    "Tajikistan"
library(ggrepel)
subdata$clustAGLO=res.agnes$cluster
fviz_cluster(object = list(data=g.dist, cluster = subdata$clustAGLO),
             geom = c("text"), 
             ellipse = FALSE,labelsize = 5,
             repel = T)

REGRESIÓN LINEAL MULTIVARIADA

CREACIÓN DE MODELOS

Modelo1: utilizamos todas las variables independientes consideradas según la teoría

#Modelo1
modelo1=lm(Matricula~PBIPC+Pobreza +URBANO+SEXO+gastoedu+ profxes+ totalAC+rateper1000AP, data=datamerge)
summary(modelo1)
## 
## Call:
## lm(formula = Matricula ~ PBIPC + Pobreza + URBANO + SEXO + gastoedu + 
##     profxes + totalAC + rateper1000AP, data = datamerge)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -29.8148  -4.4753  -0.2367   5.9235  25.8838 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   -4.955e+01  5.045e+01  -0.982  0.32880    
## PBIPC         -8.090e-05  1.202e-04  -0.673  0.50282    
## Pobreza       -2.862e-01  9.999e-02  -2.863  0.00528 ** 
## URBANO         8.636e-02  7.299e-02   1.183  0.24005    
## SEXO           2.658e+00  1.004e+00   2.649  0.00961 ** 
## gastoedu       8.785e-01  9.126e-01   0.963  0.33844    
## profxes       -3.876e-01  1.537e-01  -2.522  0.01351 *  
## totalAC        1.724e-01  1.103e-01   1.563  0.12167    
## rateper1000AP -2.712e-01  3.722e-02  -7.286 1.43e-10 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 11.1 on 86 degrees of freedom
## Multiple R-squared:  0.8312, Adjusted R-squared:  0.8155 
## F-statistic: 52.93 on 8 and 86 DF,  p-value: < 2.2e-16

Podemos decir que el modelo de regresión 1 es válido porque el p-value de ANOVA es menor a 0.05 (2.2e-16 → estadísticamente significativo). En ese sentido, se rechaza la hipótesis nula inicial y se acepta la validez del modelo. El valor del R cuadrado ajustado de 0.82 explicará un 82% de la variabilidad de la variable dependiente (tasa de matrícula escolar secundaria).

modelo2: 4 variables independientes que más aportan

modelo2=lm(Matricula~Pobreza +SEXO+ profxes+ rateper1000AP, data=datamerge)
summary(modelo2)
## 
## Call:
## lm(formula = Matricula ~ Pobreza + SEXO + profxes + rateper1000AP, 
##     data = datamerge)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -27.9224  -4.9782  -0.3097   5.7935  26.0919 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   -74.28989   45.66824  -1.627 0.107291    
## Pobreza        -0.34754    0.09812  -3.542 0.000632 ***
## SEXO            3.50727    0.89231   3.931 0.000166 ***
## profxes        -0.52902    0.14555  -3.635 0.000463 ***
## rateper1000AP  -0.28610    0.03646  -7.847 8.42e-12 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 11.37 on 90 degrees of freedom
## Multiple R-squared:  0.8146, Adjusted R-squared:  0.8064 
## F-statistic: 98.88 on 4 and 90 DF,  p-value: < 2.2e-16

Podemos decir que el modelo de regresión 2 es válido porque el p-value de ANOVA es menor a 0.05 (2.2e-16 → estadísticamente significativo). En ese sentido, se rechaza la hipótesis nula inicial y se acepta la validez del modelo.El valor del R cuadrado ajustado de 0.81 explicará un 81% de la variabilidad de la variable dependiente (Tasa de matrícula escolar secundaria)

Modelo 3:el modelo 2 pero se le añade la variable “URBANO”

modelo3=lm(Matricula~Pobreza +SEXO+ profxes+ rateper1000AP +URBANO, data=datamerge)
summary(modelo3)
## 
## Call:
## lm(formula = Matricula ~ Pobreza + SEXO + profxes + rateper1000AP + 
##     URBANO, data = datamerge)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -30.3077  -4.2454  -0.2027   6.2011  29.4677 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   -80.33207   44.94625  -1.787 0.077294 .  
## Pobreza        -0.29119    0.10012  -2.908 0.004586 ** 
## SEXO            3.39816    0.87793   3.871 0.000207 ***
## profxes        -0.42432    0.15159  -2.799 0.006281 ** 
## rateper1000AP  -0.28191    0.03586  -7.861 8.39e-12 ***
## URBANO          0.13772    0.06636   2.075 0.040860 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 11.17 on 89 degrees of freedom
## Multiple R-squared:  0.8232, Adjusted R-squared:  0.8133 
## F-statistic: 82.87 on 5 and 89 DF,  p-value: < 2.2e-16

Podemos decir que el modelo de regresión 3 es válido porque el p-value de ANOVA es menor a 0.05 (2.2e-16 → estadísticamente significativo). En ese sentido, se rechaza la hipótesis nula inicial y se acepta la validez del modelo. El valor del R cuadrado ajustado de 0.81 explicará un 81% de la variabilidad de la variable dependiente (Tasa de matrícula escolar secundaria).

modelo 4: igual que el modelo 3 pero se le agrega la variable “gastoedu”

modelo4=lm(Matricula~Pobreza +SEXO+ profxes+ rateper1000AP +URBANO+gastoedu, data=datamerge)
summary(modelo4)
## 
## Call:
## lm(formula = Matricula ~ Pobreza + SEXO + profxes + rateper1000AP + 
##     URBANO + gastoedu, data = datamerge)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -30.7823  -4.3666  -0.0655   6.4787  27.3904 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   -85.54503   45.06071  -1.898  0.06092 .  
## Pobreza        -0.29848    0.10008  -2.982  0.00370 ** 
## SEXO            3.42733    0.87630   3.911  0.00018 ***
## profxes        -0.43395    0.15146  -2.865  0.00521 ** 
## rateper1000AP  -0.27496    0.03626  -7.582 3.28e-11 ***
## URBANO          0.12101    0.06770   1.787  0.07730 .  
## gastoedu        1.05671    0.89248   1.184  0.23959    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 11.14 on 88 degrees of freedom
## Multiple R-squared:  0.826,  Adjusted R-squared:  0.8141 
## F-statistic: 69.61 on 6 and 88 DF,  p-value: < 2.2e-16

Podemos decir que el modelo de regresión 4 es válido porque el p-value de ANOVA es menor a 0.05 (2.2e-16 → estadísticamente significativo). En ese sentido, se rechaza la hipótesis nula inicial y se acepta la validez del modelo. El valor del R cuadrado ajustado de 0.81 explicará un 81% de la variabilidad de la variable dependiente (Tasa de matrícula escolar secundaria).

Comparación de modelos

library(stargazer)
## 
## Please cite as:
##  Hlavac, Marek (2018). stargazer: Well-Formatted Regression and Summary Statistics Tables.
##  R package version 5.2.2. https://CRAN.R-project.org/package=stargazer
#tabla anova
tanova=anova(modelo1, modelo2, modelo3, modelo4)
stargazer(tanova,type = 'text',summary = F,title = "Table de Análisis de Varianza")
## 
## Table de Análisis de Varianza
## ===============================================
##   Res.Df    RSS     Df Sum of Sq    F   Pr(> F)
## -----------------------------------------------
## 1   86   10,601.960                            
## 2   90   11,640.950 -4 -1,038.986 2.107  0.087 
## 3   89   11,103.700 1   537.247   4.358  0.040 
## 4   88   10,929.580 1   174.117   1.412  0.238 
## -----------------------------------------------
#tabla stargazer
stargazer(modelo1, modelo2, modelo3, modelo4, type="text")
## 
## ===============================================================================================================
##                                                         Dependent variable:                                    
##                     -------------------------------------------------------------------------------------------
##                                                              Matricula                                         
##                              (1)                    (2)                    (3)                    (4)          
## ---------------------------------------------------------------------------------------------------------------
## PBIPC                      -0.0001                                                                             
##                            (0.0001)                                                                            
##                                                                                                                
## Pobreza                   -0.286***              -0.348***              -0.291***              -0.298***       
##                            (0.100)                (0.098)                (0.100)                (0.100)        
##                                                                                                                
## URBANO                      0.086                                        0.138**                 0.121*        
##                            (0.073)                                       (0.066)                (0.068)        
##                                                                                                                
## SEXO                       2.658***               3.507***               3.398***               3.427***       
##                            (1.004)                (0.892)                (0.878)                (0.876)        
##                                                                                                                
## gastoedu                    0.878                                                                1.057         
##                            (0.913)                                                              (0.892)        
##                                                                                                                
## profxes                    -0.388**              -0.529***              -0.424***              -0.434***       
##                            (0.154)                (0.146)                (0.152)                (0.151)        
##                                                                                                                
## totalAC                     0.172                                                                              
##                            (0.110)                                                                             
##                                                                                                                
## rateper1000AP             -0.271***              -0.286***              -0.282***              -0.275***       
##                            (0.037)                (0.036)                (0.036)                (0.036)        
##                                                                                                                
## Constant                   -49.547                -74.290                -80.332*               -85.545*       
##                            (50.450)               (45.668)               (44.946)               (45.061)       
##                                                                                                                
## ---------------------------------------------------------------------------------------------------------------
## Observations                  95                     95                     95                     95          
## R2                          0.831                  0.815                  0.823                  0.826         
## Adjusted R2                 0.815                  0.806                  0.813                  0.814         
## Residual Std. Error    11.103 (df = 86)       11.373 (df = 90)       11.170 (df = 89)       11.144 (df = 88)   
## F Statistic         52.928*** (df = 8; 86) 98.884*** (df = 4; 90) 82.875*** (df = 5; 89) 69.608*** (df = 6; 88)
## ===============================================================================================================
## Note:                                                                               *p<0.1; **p<0.05; ***p<0.01

Lo que se puede apreciar gracias a la tabla anova es que ninguna de los modelos permite rechazar la hipótesis nula de que “los modelos no difieren”. A excepción del modelo 3 que sí cuenta con un p value menor a 0.05 por lo que indicaría que sería el único que sí tiene una diferencia significativa: el modelo 3 sí reduce el error al incluir una variable más Por otro lado, gracias a la tabla stargazer se puede observar también que el modelo 3 es el más apropiado por contar con un valor del R2 de 0.81, y porque todas sus variables independientemente sí aportan al modelo (p value menor a 0.05), a diferencia del modelo 1 y 4.

#SUPUESTOS

##PRUEBAS DE VALIDEZ DEL MODELO 1 1.1 Linealidad. La linea roja debe tender a ser horizontal

plot(modelo1, 1)

La línea roja dista considerablemente en los extremos de la línea horizontal, por lo tanto se concluye que no hay linealidad.

1.2 Homocedasticidad. Línea roja debe tender a ser horizontal, O la prueba de Breusch-Pagan debe tener un p-value mayor a 0.05 para comprobar homocedasticidad

plot(modelo1, 3)

library(lmtest)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
bptest(modelo1) #H0: el modelo es homocedástico
## 
##  studentized Breusch-Pagan test
## 
## data:  modelo1
## BP = 16.967, df = 8, p-value = 0.03046

La línea no es horizontal y el p-value en el test Breusch-Pagan es menor a 0.05 (0.03046). Por lo tanto, se concluye que el modelo NO es homocedástico, es decir es heterocedástico

1.3 Normalidad de residuos. Puntos deben estar cerca a la diagonal, O la prueba de normalidad de los residuos debe tener un p-value mayor a 0.05

plot(modelo1, 2)

shapiro.test(modelo1$residuals) #H0: Tiene distribución normal
## 
##  Shapiro-Wilk normality test
## 
## data:  modelo1$residuals
## W = 0.98217, p-value = 0.2233

Los puntos no distan mucho de la línea diagonal y el p value del Shapiro Test es mayor a 0. 05 (0.2233); por lo tanto, se concluye que los residuos sí cuentan con distribución normal.

1.4 Multicolinealidad. Valor no debe ser >5. Si los predictores tienen una correlación muy alta entre sí, hay multicolinealidad, lo cual no es deseable:

library(DescTools)
VIF(modelo1)
##         PBIPC       Pobreza        URBANO          SEXO      gastoedu 
##      3.042545      2.162954      2.016485      1.380803      1.180817 
##       profxes       totalAC rateper1000AP 
##      1.846695      3.985895      2.496510

Se concluye que no tenemos multicolinealidad dado que los valores son menores a 5.

¿Cuáles son los valores influyentes?

plot(modelo1, 5)

checkreg1=as.data.frame(influence.measures(modelo1)$is.inf)
checkreg1[checkreg1$cook.d | checkreg1$hat,]

Caso que influye: Malawi

PRUEBAS DE VALIDEZ DEL MODELO 2

2.1 Linealidad. La linea roja debe tender a ser horizontal

plot(modelo2, 1)

La línea roja dista considerablemente en los extremos de la línea horizontal; por lo tanto, se concluye que no hay linealidad.

2.2 Homocedasticidad. Línea roja debe tender a ser horizontal, O la prueba de Breusch-Pagan debe tener un p-value mayor a 0.05 para comprobar homocedasticidad

plot(modelo2, 3)

library(lmtest)
bptest(modelo2) #H0: el modelo es homocedástico
## 
##  studentized Breusch-Pagan test
## 
## data:  modelo2
## BP = 17.817, df = 4, p-value = 0.00134

La línea no es horizontal y el p-value en el test Breusch-Pagan es menor a 0.05 (0.00134). Por lo tanto, se concluye que NO es homocedástico; es decir es heterocedástico.

2.3 Normalidad de residuos. Puntos deben estar cerca a la diagonal, O la prueba de normalidad de los residuos debe tener un p-value mayor a 0.05

plot(modelo2, 2)

shapiro.test(modelo2$residuals) #H0: Tiene distribución normal
## 
##  Shapiro-Wilk normality test
## 
## data:  modelo2$residuals
## W = 0.97988, p-value = 0.1518

Los puntos distan mucho de la línea diagonal y el p value del Shapiro Test es mayor a 0. 05 (se obtuvo un valor de 0.1518); por lo tanto, se concluye que los residuos cuentan con distribución normal.

2.4 Multicolinealidad. Valor no debe ser >5. Si los predictores tienen una correlación muy alta entre sí, hay multicolinealidad, lo cual no es deseable:

library(DescTools)
VIF(modelo2)
##       Pobreza          SEXO       profxes rateper1000AP 
##      1.984967      1.040465      1.578607      2.283722

Ninguno es mayor a 5, no hay multicolinealidad.

¿Cuáles son los valores influyentes?

plot(modelo2, 5)

checkreg2=as.data.frame(influence.measures(modelo2)$is.inf)
checkreg2[checkreg2$cook.d | checkreg2$hat,]

Caso que influye: Malawi

PRUEBAS DE VALIDEZ DEL MODELO 3

3.1 Linealidad. La linea roja debe tender a ser horizontal

plot(modelo3, 1)

La línea roja dista considerablemente en los extremos de la línea horizontal; por lo tanto, se concluye que no hay linealidad.

3.2 Homocedasticidad. Línea roja debe tender a ser horizontal, O la prueba de Breusch-Pagan debe tener un p-value mayor a 0.05 para comprobar homocedasticidad

plot(modelo3, 3)

library(lmtest)
bptest(modelo3) #H0: el modelo es homocedástico
## 
##  studentized Breusch-Pagan test
## 
## data:  modelo3
## BP = 15.331, df = 5, p-value = 0.009036

La línea no es horizontal y el p value en el test Breusch-Pagan es menor a 0.05 (0.009036); por lo tanto, se concluye que NO es homocedástico; es decir es heterocedástico.

3.3 Normalidad de residuos. Puntos deben estar cerca a la diagonal, O la prueba de normalidad de los residuos debe tener un p-value mayor a 0.05

plot(modelo3, 2)

shapiro.test(modelo3$residuals) #H0: Tiene distribución normal
## 
##  Shapiro-Wilk normality test
## 
## data:  modelo3$residuals
## W = 0.97258, p-value = 0.04333

Los puntos distan mucho de la línea diagonal, pero el p value del Shapiro Test es mayor a 0. 05 (0.1518). Por lo tanto, se acepta la hipótesis nula que decía que los residuos tienen una distribución normal.

3.4 Multicolinealidad. Valor no debe ser >5. Si los predictores tienen una correlación muy alta entre sí, hay multicolinealidad, lo cual no es deseable:

library(DescTools)
VIF(modelo3)
##       Pobreza          SEXO       profxes rateper1000AP        URBANO 
##      2.142587      1.044210      1.775255      2.290951      1.647039

Ninguno es mayor a 5, no hay multicolinealidad.

¿Cuáles son los valores influyentes?

plot(modelo3, 5)

checkreg3=as.data.frame(influence.measures(modelo3)$is.inf)
checkreg3
checkreg3[checkreg3$cook.d | checkreg3$hat,]

Caso que influye: Malawi

PRUEBAS DE VALIDEZ DEL MODELO 4

4.1 Linealidad. La linea roja debe tender a ser horizontal

plot(modelo4, 1)

La línea roja dista considerablemente en los extremos de la línea horizontal por lo tanto se concluye que no hay linealidad.

4.2 Homocedasticidad. Línea roja debe tender a ser horizontal, O la prueba de Breusch-Pagan debe tener un p-value mayor a 0.05 para comprobar homocedasticidad

plot(modelo4, 3)

library(lmtest)
bptest(modelo4) #H0: el modelo es homocedástico
## 
##  studentized Breusch-Pagan test
## 
## data:  modelo4
## BP = 15.27, df = 6, p-value = 0.01826

La línea no es horizontal y el p value en el test Breusch-Pagan es menor a 0.05 (0.01826); por lo tanto, se concluye que NO es homocedástico; es decir es heterocedástico.

4.3 Normalidad de residuos. Puntos deben estar cerca a la diagonal, O la prueba de normalidad de los residuos debe tener un p-value mayor a 0.05

plot(modelo4, 2)

shapiro.test(modelo4$residuals) #H0: Tiene distribución normal
## 
##  Shapiro-Wilk normality test
## 
## data:  modelo4$residuals
## W = 0.97614, p-value = 0.08001

Los puntos distan mucho de la línea diagonal y el p value del Shapiro Test es mayor a 0. 05 (0.08001); por lo tanto, se concluye que los residuos cuentan con una distribución normal.

4.4 Multicolinealidad. Valor no debe ser >5. Si los predictores tienen una correlación muy alta entre sí, hay multicolinealidad, lo cual no es deseable:

library(DescTools)
VIF(modelo4)
##       Pobreza          SEXO       profxes rateper1000AP        URBANO 
##      2.150725      1.045036      1.780391      2.352743      1.721786 
##      gastoedu 
##      1.120913

Se concluye que no tenemos multicolinealidad dado que los valores son menores a 5.

¿Cuáles son los valores influyentes?

plot(modelo4, 5)

checkreg4=as.data.frame(influence.measures(modelo4)$is.inf)
checkreg4[checkreg4$cook.d | checkreg4$hat,]

Caso que influye: Malawi

ECUACIÓN FINAL

La ecuación del modelo (modelo 3) elegido es: -80.33+(-0.29Pobreza)+(3.4sexo)+(-0.42proxfes)+(-0.28rater1000ap)+(0.14*urbano) +ϵ