Primero cargamos las bases
p1 <- a %>% inner_join(d, by = "directorio") %>% select(directorio,directorio_hog,localidad,estrato) %>%
inner_join(ing_gastos)
## Joining by: "directorio_hog"
p1 %>% group_by(estrato) %>% summarize(hogXestr = n(), prom_ingXestr = mean(ingreso,na.rm=T))
## Source: local data frame [7 x 3]
##
## estrato hogXestr prom_ingXestr
## 1 1 1245 1222946
## 2 2 6000 1552403
## 3 3 6324 2658245
## 4 4 1947 5799054
## 5 5 357 7750068
## 6 6 427 10728670
## 7 9 208 2530696
b. Calcule la mediana, la desviación, y el mad (estandarizado) por estrato. 0.25 pts
p1 %>% group_by(estrato) %>% summarize(med_ingXestr = median(ingreso,na.rm=T),
de_ingXestr = sd(ingreso,na.rm=T),
mad_ingXestr = mad(ingreso,na.rm=T))
## Source: local data frame [7 x 4]
##
## estrato med_ingXestr de_ingXestr mad_ingXestr
## 1 1 985000 925754.7 603171.1
## 2 2 1204750 1632698.8 822472.3
## 3 3 1929792 2663285.6 1489704.1
## 4 4 4400417 5532453.3 3546502.7
## 5 5 6375000 8056666.1 4274830.0
## 6 6 8000000 9406479.6 6670464.6
## 7 9 1415999 3321418.8 1283930.1
En primer lugar desarrollamos las funciones para desarrollar la asimetría de Bowley-Yule y la curtosis robusta.
A_BY = function(x,na.rm=F){
IQR_e <- IQR(x,na.rm=na.rm)
p25 <- quantile(x,probs = 0.25,na.rm=na.rm)
p75 <- quantile(x,probs = 0.75,na.rm=na.rm)
output <- (p75 - 2* median(x,na.rm=na.rm) + p25 ) / IQR_e
output
}
Curtosis_robusta <- function(x, na.rm = F){
p5 <- quantile(x, probs = 0.05, na.rm = na.rm)
p25 <- quantile(x, probs = 0.25, na.rm = na.rm)
p75 <- quantile(x,probs = 0.75, na.rm = na.rm)
p95 <- quantile(x, probs = 0.95, na.rm = na.rm)
num <- p95 - p5
den <- p75 - p25
output <- (num/den) - 2.438301 + 3
output
}
Utilizamos las funciones anteriores junto con las medidas de asimetría y curtosis clásicas del paquete moments.
library(moments)
p1 %>% group_by(estrato) %>% summarize(asimetria_ingXestr = skewness(ingreso,na.rm=T),
asimetriaBY_ingXestr = A_BY(ingreso,na.rm=T),
curtosis = kurtosis(ingreso,na.rm=T),
curtosis_robust_ingXestr = Curtosis_robusta(ingreso,na.rm=T))
## Source: local data frame [7 x 5]
##
## estrato asimetria_ingXestr asimetriaBY_ingXestr curtosis
## 1 1 3.037542 0.2752177 23.398974
## 2 2 8.456831 0.1664558 142.979240
## 3 3 4.465090 0.2658676 45.984414
## 4 4 5.634117 0.2519885 80.700927
## 5 5 6.892260 0.1852861 77.658644
## 6 6 2.096852 0.2290928 9.880912
## 7 9 4.238980 0.4161872 28.638535
## Variables not shown: curtosis_robust_ingXestr (dbl)
p2 <- saber2013 %>% filter(departamento %in% c("ANTIOQUIA", "BOGOTÁ" , "VALLE"))
ggplot(p2, aes(x=matematica)) + geom_density(aes(group=departamento, colour=departamento))
ggplot(saber2013, aes(x = factor(jornada))) + geom_bar(stat = "bin") + labs(x = "Jornada", y = "Frecuencia")
p3 <- saber2013 %>% mutate(puntaje_global = (matematica + quimica + fisica + biologia + filosofia + ingles + lenguaje + sociales) / 8) %>% mutate(Resultado = ifelse(puntaje_global< 60, "Reprobo",ifelse(puntaje_global >= 60, "Aprobó",NA)))
table(p3$Resultado)
##
## Aprobó Reprobo
## 189 11995
100 * prop.table(table(p3$Resultado))
##
## Aprobó Reprobo
## 1.551215 98.448785
p3b <- p3 %>% filter(naturaleza == "OFICIAL")
table(p3b$Resultado)
##
## Aprobó Reprobo
## 2 8248
100 * prop.table(table(p3b$Resultado))
##
## Aprobó Reprobo
## 0.02424242 99.97575758
proy %>% group_by(DPNOM) %>% summarize(POB_TOTAL = sum(P_2015)) %>% arrange(desc(POB_TOTAL))
## Source: local data frame [33 x 2]
##
## DPNOM POB_TOTAL
## 1 Bogotá, DC 7878783
## 2 Antioquia 6456299
## 3 Valle del Cauca 4613684
## 4 Cundinamarca 2680041
## 5 Atlántico 2460863
## 6 Bolívar 2097161
## 7 Santander 2061079
## 8 Nariño 1744228
## 9 Córdoba 1709644
## 10 Tolima 1408272
## .. ... ...
table(p3b$Resultado)
##
## Aprobó Reprobo
## 2 8248
100 * prop.table(table(p3b$Resultado))
##
## Aprobó Reprobo
## 0.02424242 99.97575758
p5 <- left_join(saber2013, proy, by = c("cod_municipio" = "DPMP")) %>% filter(P_2015 > 1000000)
¿Cuanto fue el promedio en matemáticas para estos municipios?
p5 %>% summarize(prom_matematicas = mean(matematica))
## prom_matematicas
## 1 46.42879
¿Cuanto fue promedio en matemáticas para todos los colegios del país? ¿Qué puede decir del desempeño de las ciudades más grandes del país (más de un millon de habitantes) con respecto a las demás ciudades? 0.2 pts
saber2013 %>% summarize(prom_matematicas = mean(matematica))
## prom_matematicas
## 1 44.2036
p6<- p3 %>% left_join(proy, by = c("cod_municipio" = "DPMP")) %>% mutate(Tam_munic = ifelse(P_2015 < 100000, "Pequeno",ifelse(P_2015 <= 500000,"Mediano",ifelse(P_2015 > 500000, "Grande",NA))))
¿Cuál fue el promedio y la mediana del puntaje global para cada una de las tipologías de municipios que usted recodificó?
p6 %>% group_by(Tam_munic) %>% summarize(n = n(), prom_puntajeglobal = mean(puntaje_global), mediana_puntajeglobal = median(puntaje_global))
## Source: local data frame [4 x 4]
##
## Tam_munic n prom_puntajeglobal mediana_puntajeglobal
## 1 Grande 3780 45.53228 44.33187
## 2 Mediano 2770 44.12262 43.06000
## 3 Pequeno 5633 42.26357 41.74000
## 4 NA 1 39.98875 39.98875
Los municipios más grandes tienen un mejor desempeño. Hay un municipios en el cual no se conoce la población:
subset(p6,is.na(Tam_munic),select = c(municipio,departamento))
## municipio departamento
## 9346 BELEN DE BAJIRA CHOCÓ
p7 <- resumen_jornada %>% gather(key = jornada, value = evaluados,
COMPLETA,MAÑANA,NOCHE,SABATINA_DOMINICAL,TARDE)
Saque el total de evaluados por departamento 0.5 pt
p7 %>% group_by(departamento) %>% summarize(total_evaluados = sum(evaluados,na.rm=T))
## Source: local data frame [33 x 2]
##
## departamento total_evaluados
## 1 AMAZONAS 754
## 2 ANTIOQUIA 72976
## 3 ARAUCA 2828
## 4 ATLÁNTICO 29198
## 5 BOGOTÁ 93689
## 6 BOLÍVAR 24840
## 7 BOYACÁ 17066
## 8 CALDAS 11766
## 9 CAQUETÁ 4028
## 10 CASANARE 5557
## .. ... ...
Ordenando:
p7 %>% group_by(departamento) %>% summarize(total_evaluados = sum(evaluados,na.rm=T)) %>% arrange(desc(total_evaluados))
## Source: local data frame [33 x 2]
##
## departamento total_evaluados
## 1 BOGOTÁ 93689
## 2 ANTIOQUIA 72976
## 3 VALLE 49058
## 4 CUNDINAMARCA 36099
## 5 ATLÁNTICO 29198
## 6 SANTANDER 26814
## 7 BOLÍVAR 24840
## 8 CÓRDOBA 18718
## 9 BOYACÁ 17066
## 10 NARIÑO 16889
## .. ... ...
Cuantos evaluados tienen Bogotá, Cali y Medellín, cuales son los dos municipios con menos evaluados, lleve a cabo un ordenamiento descendente para responde a esto. 0.5 pt
p7b <- p7 %>% group_by(municipio) %>% summarize(total_evaluados = sum(evaluados,na.rm=T)) %>% arrange(desc(total_evaluados))
tail(p7b)
## Source: local data frame [6 x 2]
##
## municipio total_evaluados
## 1 MURINDO 9
## 2 PISVA 8
## 3 JORDAN 7
## 4 BOJAYA (BELLAVISTA) 5
## 5 YAVARATE 4
## 6 MEDIO ATRATO 3
PUNTO 7 del GRUPO NOCTURNO
Calcule para la variable ingreso las siguientes estadísticas desagregadas por ingreso y localidad.
p7noche <- p1 %>% group_by(localidad, estrato) %>% summarize(min_ing = min(ingreso,na.rm=T), p25_ing = quantile(ingreso,0.25,na.rm=T),
prom_ing = mean(ingreso,na.rm=T), mediana_ing = median(ingreso,na.rm=T),
p75_ing = quantile(ingreso,0.75,na.rm=T), max_ing = max(ingreso,na.rm=T) )
p7noche <- merge(p7noche,localidad) %>% arrange(nom_loc)
p7noche
## localidad estrato min_ing p25_ing prom_ing mediana_ing p75_ing
## 1 15 2 140000.00 721875.0 1512749.3 1118083.3 1839417
## 2 15 3 50000.00 1001249.9 2617748.0 1800000.0 3015083
## 3 15 9 550000.00 1631750.0 2704347.0 2396000.0 3750000
## 4 12 3 75000.00 982708.3 2600219.9 1747666.7 3452248
## 5 12 4 150000.00 2364583.3 5457177.5 4016666.7 7340500
## 6 12 5 809999.00 3773333.3 7843504.1 6408791.2 12187500
## 7 12 9 1200000.00 1366666.7 1533333.3 1533333.3 1700000
## 8 7 1 60000.00 530000.0 1140252.5 755000.0 1330500
## 9 7 2 50000.00 771183.3 1486855.8 1231000.0 1841500
## 10 7 3 240000.00 1012500.0 2786992.7 2228000.0 3912083
## 11 7 9 258333.33 531500.0 1035942.3 839500.0 1234250
## 12 17 1 560000.00 729383.3 1339266.7 1050000.0 1678542
## 13 17 2 60000.00 586782.8 2114745.0 1171666.7 2435208
## 14 17 3 90000.00 1492500.0 3680475.8 2586916.7 4500000
## 15 17 9 150000.00 1100000.0 3556277.8 2200000.0 4535000
## 16 2 1 250000.00 956250.0 1626919.1 1595000.0 2114750
## 17 2 2 550000.00 883750.0 1796071.4 1542500.0 2723750
## 18 2 3 425000.00 1816666.7 4293266.5 3633333.3 6037500
## 19 2 4 84166.58 2191666.7 4934280.1 3768166.7 6682292
## 20 2 5 300000.00 3500000.0 6897646.4 6620000.0 9200000
## 21 2 6 83333.33 4000000.0 10281592.6 7010415.6 14000000
## 22 2 9 2009999.00 3964499.9 9470904.1 7497354.2 11540000
## 23 19 1 50000.00 640000.0 1195325.7 947000.0 1560000
## 24 19 2 50000.00 700000.0 1429863.8 1138166.7 1694167
## 25 19 3 100000.00 959999.0 1762978.6 1501666.5 2401667
## 26 10 2 130000.00 1000000.0 2074443.2 1600000.0 2500000
## 27 10 3 66333.00 1305916.7 3027305.3 2430381.7 3918958
## 28 10 4 1000000.00 3625000.0 5508875.0 5058333.3 6692500
## 29 10 9 270000.00 810350.0 1221079.9 1090366.7 1361999
## 30 9 2 83333.33 795625.0 1655423.6 1395633.3 1866833
## 31 9 3 66666.67 1248229.2 2833440.5 2095333.3 3527175
## 32 9 4 83333.33 3100000.0 6597666.8 4954000.0 8872667
## 33 9 5 2000000.00 3894000.0 5627133.3 4825000.0 6400000
## 34 9 9 666666.67 1810375.0 3682719.7 2978383.3 6270313
## 35 8 2 50000.00 900000.0 1698110.3 1457000.0 2050000
## 36 8 3 60000.00 1264949.9 2677523.3 2100000.0 3564875
## 37 8 4 1400000.00 2815000.0 5641745.1 4400000.0 6100000
## 38 8 9 150000.00 750000.0 2413186.2 1400000.0 4703333
## 39 14 2 60000.00 500000.0 1017932.8 800000.0 1207000
## 40 14 3 50000.00 900000.0 2312556.8 1625000.0 2953750
## 41 14 4 800000.00 2550000.0 5107261.1 4200000.0 6732167
## 42 16 3 50000.00 1146725.0 2548129.3 1945333.3 3196250
## 43 18 1 50000.00 585000.0 1204081.4 1100000.0 1591667
## 44 18 2 70000.00 660000.0 1380897.4 1106250.0 1699233
## 45 18 3 50000.00 763000.0 2132259.0 1350533.3 2521725
## 46 18 9 600000.00 848000.0 1317848.5 1130000.0 1700625
## 47 4 1 220000.00 700000.0 1299390.2 870000.0 1681667
## 48 4 2 50000.00 680000.0 1349441.3 1095000.0 1734583
## 49 4 3 300000.00 1032666.7 2290252.4 1556500.0 2738333
## 50 4 9 750000.00 900000.0 2149370.4 1828333.3 3206667
## 51 3 1 130000.00 800200.0 1327693.7 1080000.0 1504500
## 52 3 2 50000.00 694375.0 1545635.9 1202916.7 2010092
## 53 3 3 75000.00 1000000.0 2814105.4 1941666.7 3883333
## 54 3 4 75000.00 2865625.0 6247041.2 4656333.3 8406250
## 55 3 9 200000.00 539000.0 957318.2 897500.0 1012500
## 56 11 2 50833.33 809800.0 1645182.5 1321866.7 2028400
## 57 11 3 100833.25 1325916.7 2966387.9 2165591.7 3600000
## 58 11 4 533333.33 2872500.0 6137293.8 5300000.0 8207542
## 59 11 5 166666.67 3531250.0 6937350.5 6400000.0 9200000
## 60 11 6 7800000.00 10866666.7 18380952.4 14000000.0 23816667
## 61 11 9 685333.33 1198000.0 2578607.6 1316700.0 3005367
## 62 13 3 166666.67 1199750.0 3140574.1 2475166.6 4118750
## 63 13 4 71666.50 2439125.0 5728368.6 4214166.7 7358333
## 64 13 5 800000.00 2500000.0 6201261.1 4726833.3 6945000
## 65 6 2 80833.25 664666.7 1581495.8 1194583.3 1936667
## 66 6 3 95166.67 1114166.7 2383527.5 1804333.3 2801675
## 67 1 1 200000.00 762500.0 1185255.2 1038500.0 1461354
## 68 1 2 65000.00 730416.7 1565066.7 1398300.0 2121979
## 69 1 3 241666.67 1092500.0 2575362.2 1750000.0 3192833
## 70 1 4 150000.00 2308333.3 6292003.7 5000000.0 8200000
## 71 1 5 250000.00 4661666.7 9717660.7 7000000.0 11383333
## 72 1 6 966666.67 4941666.7 11166288.2 8750000.0 14500000
## 73 1 9 800000.00 2620000.0 4377685.2 4200000.0 4692500
## 74 5 1 50000.00 650000.0 1204843.0 985183.3 1517000
## 75 5 2 50000.00 700000.0 1427278.4 1149500.0 1769250
## 76 5 9 81666.67 260000.0 770562.3 535600.0 1135000
## max_ing nom_loc
## 1 8640000 Antonio Nari\xf1o
## 2 30856000 Antonio Nari\xf1o
## 3 6352267 Antonio Nari\xf1o
## 4 15500000 Barrios Unidos
## 5 41000000 Barrios Unidos
## 6 17500000 Barrios Unidos
## 7 1866667 Barrios Unidos
## 8 5389000 Bosa
## 9 31070000 Bosa
## 10 6525000 Bosa
## 11 3088000 Bosa
## 12 3553500 Candelaria
## 13 42009999 Candelaria
## 14 35125000 Candelaria
## 15 21033333 Candelaria
## 16 3952667 Chapinero
## 17 4032000 Chapinero
## 18 12898750 Chapinero
## 19 30000000 Chapinero
## 20 21700000 Chapinero
## 21 72500000 Chapinero
## 22 29300000 Chapinero
## 23 7032500 Ciudad Bolivar
## 24 10740000 Ciudad Bolivar
## 25 5000000 Ciudad Bolivar
## 26 30400000 Engativa
## 27 32387500 Engativa
## 28 12025000 Engativa
## 29 2525000 Engativa
## 30 14984250 Fontib\xf3n
## 31 20176667 Fontib\xf3n
## 32 39250000 Fontib\xf3n
## 33 11016667 Fontib\xf3n
## 34 8777083 Fontib\xf3n
## 35 10930000 Kennedy
## 36 18122000 Kennedy
## 37 16532333 Kennedy
## 38 6100833 Kennedy
## 39 5350000 Los M\xe1rtires
## 40 52220112 Los M\xe1rtires
## 41 18883333 Los M\xe1rtires
## 42 23770000 Puente Aranda
## 43 4570833 Rafael Uribe
## 44 7750000 Rafael Uribe
## 45 38935000 Rafael Uribe
## 46 2355417 Rafael Uribe
## 47 3889000 San Cristobal
## 48 7223100 San Cristobal
## 49 14606667 San Cristobal
## 50 4500000 San Cristobal
## 51 6004333 Santa Fe
## 52 12401667 Santa Fe
## 53 15650000 Santa Fe
## 54 36450000 Santa Fe
## 55 2400000 Santa Fe
## 56 29077499 Suba
## 57 21500833 Suba
## 58 31925000 Suba
## 59 23965833 Suba
## 60 37500000 Suba
## 61 7986750 Suba
## 62 21450000 Teusaquillo
## 63 52000000 Teusaquillo
## 64 42500000 Teusaquillo
## 65 23496333 Tunjuelito
## 66 17430000 Tunjuelito
## 67 2986667 Usaaqu\xe9n
## 68 6278250 Usaaqu\xe9n
## 69 25875000 Usaaqu\xe9n
## 70 111100000 Usaaqu\xe9n
## 71 108200000 Usaaqu\xe9n
## 72 56153333 Usaaqu\xe9n
## 73 11616667 Usaaqu\xe9n
## 74 12100000 Usme
## 75 15064333 Usme
## 76 3705000 Usme