El objetivo de esta sesión es identificar el ambiente de trabajo de R, sus componentes y los objetos de trabajo.
Algunos vectores de numéricos:
3
c(2, 3)
1:5
301:350
Vectores nombrados:
a <- 10:30
Y se pueden recuperar para el trabajo posterior:
a
Ahora vectores de texto:
saludo <- c("Hola", "Yo", "Soy", "Jesus")
Datos almacenados en vectores:
saludo
2:5
saludo2 <- c(saludo, 2:5)
saludo2
Un dataframe:
myDataframe <- data.frame(orden = 1:5, ciudad = c("Ibague", "Bogota", "Tunja", "Cali", "Medellin"), letras = letters[1:5], meses = month.name[1:5], salario = rnorm(5, 200, 50))
myDataframe
Una matriz:
myMatrix1 = matrix(1:12, nrow = 3)
myMatrix1
Otra matriz con texto:
myMatrix2 = matrix(c(1:11, "a"), nrow = 3)
myMatrix2
Una matriz que nos recuerda quien es ‘a’:
myMatrix3 = matrix(c(1:11, a), nrow = 3)
myMatrix3
Finalmente una lista:
myLista <- list(vector = a, matrix = myMatrix1, dataframe = myDataframe)
myLista
Encontrar el índice de masa corporal de cada compañero.
Plan B:
names(super.adj)
[1] "dpto" "ciiu" "ciudad"
[4] "activoCorriente" "pasivoCorriente" "razonCorriente"
Promover el uso de scripts en R para la facilitar la replicación del análisis.
Construir un script que explique los objetos de R y muestre con ejemplos su uso. Introducir un parámetro para ejecutar el código cambiando el parámetro.
Construir y ejecutar funciones de usuario en R.
mean
Otra función un poco más elaborada:
lm
Nuestra función:
myMean <- function(x) {
mySum <- sum(x, na.rm = TRUE)
myN <- length(x)
mySum / myN
}
Usando nuestra función:
vector <- c(1, NA, 5, 9)
myMean(x = vector)
Ajustando nuestra función:
myMean <- function(x) {
mySum <- sum(x, na.rm = TRUE)
myN <- length(na.omit(x))
mySum / myN
}
y ahora:
myMean(x = vector)
myMean <- function(x) {
mySum <- sum(x, na.rm = TRUE)
myN <- length(na.omit(x))
myMean <- mySum / myN
return(c(suma = mySum, muestra = myN, media = myMean))
}
myMean(vector)
Ahora con dos entradas:
myMean <- function(x, y) {
mySum <- sum(x, na.rm = TRUE)
myN <- length(na.omit(x))
myMean <- mySum / myN
mySd <- sd(x, na.rm = TRUE)
mySe <- mySd / sqrt(myN)
myZ <- qnorm(y, 0, 1)
seMax <- myZ * mySe
return(c(suma = mySum, muestra = myN, media = myMean, errorMax = seMax))
}
myMean(vector, 0.975)
ls()
Escribir una función que describa una variable o vector. La función debe generar una lista con el número de observaciones, el número de valores perdidos, la media, la varianza, la desviación estándar, el coeficiente de variación, el error estándar, los valores mínimo y máximo, y los cuartiles.
Escribir una función que identifique las observaciones irregulares a través del método de Tukey.
Buscar, instalar y usar paquetes de análisis en R.
Importar y exportar datos y resultados a otras aplicaciones.
library(foreign)
getwd()
#d <- read.dta("pwt90.dta")
#install.packages("readstata13")
library(readstata13)
d <- read.dta13("pwt90.dta")
Ahora a conocer nuestros datos:
dim(d)
names(d)
str(d)
Segundo, desde excel:
super <- readxl::read_excel("BalanceGeneral2015SIREMV2.xls")
super <- readxl::read_excel("BalanceGeneral2015SIREMV2.xls")
dim(super)
[1] 26533 242
names(super)
[1] "NIT"
[2] "RAZON SOCIAL"
[3] "CIUDAD"
[4] "DEPARTAMENTO"
[5] "CIIU"
[6] "SECTOR"
[7] "1105 CAJA"
[8] "1110 BANCOS"
[9] "1115 REMESAS EN TRÃ\u0081NSITO"
[10] "1120 CUENTAS DE AHORRO"
[11] "1125 FONDOS"
[12] "11 SUBTOTAL DISPONIBLE"
[13] "12 INVERSIONES"
[14] "1305 CLIENTES"
[15] "1310 CUENTAS CORRIENTES COMERCIALES (CP)"
[16] "1315 CUENTAS POR COBRAR A CASA MATRIZ (CP)"
[17] "1320 CUENTAS POR COBRAR A VINCULADOS ECONÃMICOS (CP)"
[18] "1323 CUENTAS POR COBRAR A DIRECTORES (CP)"
[19] "1325 CUENTAS POR COBRAR A SOCIOS Y ACCIONISTAS (CP)"
[20] "1328 APORTES POR COBRAR (CP)"
[21] "1330 ANTICIPOS Y AVANCES (CP)"
[22] "1332 CUENTAS DE OPERACIÃN CONJUNTA (CP)"
[23] "1335 DEPÃSITOS (CP)"
[24] "1340 PROMESAS DE COMPRAVENTA (CP)"
[25] "1345 INGRESOS POR COBRAR (CP)"
[26] "1350 RETENCIÃN SOBRE CONTRATOS (CP)"
[27] "1355 ANTICIPO DE IMPTOS. Y CONTRIB.O SALDOS A FAVOR (CP)"
[28] "1360 RECLAMACIONES (CP)"
[29] "1365 CUENTAS POR COBRAR A TRABAJADORES (CP)"
[30] "1370 PRESTAMOS A PARTICULARES (CP)"
[31] "1380 DEUDORES VARIOS (CP)"
[32] "1385 DERECHOS DE RECOMP. DE CART. NEGOCIADA (CP)"
[33] "1390 DEUDAS DE DIFÃ\u008dCIL COBRO (CP)"
[34] "1399 PROVISIONES (CP)"
[35] "13 SUBTOTAL DEUDORES (CP)"
[36] "1405 MATERIAS PRIMAS"
[37] "1410 PRODUCTOS EN PROCESO"
[38] "1415 OBRAS DE CONSTRUC. EN CURSO"
[39] "1417 OBRAS DE URBANISMO"
[40] "1420 CONTRATOS EN EJECUCIÃN (CP)"
[41] "1425 CULTIVOS EN DESARROLLO (CP)"
[42] "1428 PLANTACIONES AGRÃ\u008dCOLAS (CP)"
[43] "1430 PRODUCTOS TERMINADOS"
[44] "1435 M/CÃ\u008dAS NO FABRICADAS POR LA EMP."
[45] "1440 BIENES RAÃ\u008dCES PARA LA VENTA"
[46] "1445 SEMOVIENTES (CP)"
[47] "1450 TERRENOS"
[48] "1455 MATERIALES, REPUESTOS Y ACCESORIOS (CP)"
[49] "1460 ENVASES Y EMPAQUES (CP)"
[50] "1465 INVENTARIOS EN TRÃ\u0081NSITO (CP)"
[51] "1499 PROVISIONES (CP)"
[52] "14 SUBTOTAL INVENTARIOS (CP)"
[53] "1705 GASTOS PAGADOS POR ANTICIPADO (CP)"
[54] "1710 CARGOS DIFERIDOS (CP)"
[55] "1715 COSTOS DE EXPLORACIÃN POR AMORTIZAR (CP)"
[56] "1720 COSTOS DE EXPLOTACIÃN Y DESARROLLO (CP)"
[57] "1730 CARGOS POR CORRECCIÃN MONETARIA DIFERIDA (CP)"
[58] "1798 AMORTIZACIÃN ACUMULADA (CP)"
[59] "17 SUBTOTAL DIFERIDO (CP)"
[60] "TOTAL ACTIVO CORRIENTE"
[61] "12 INVERSIONES__1"
[62] "1305 CLIENTES__1"
[63] "1310 CUENTAS CORRIENTES COMERCIALES"
[64] "1315 CUENTAS POR COBRAR A CASA MATRIZ"
[65] "1320 CUENTAS POR COBRAR A VINCULADOS ECONÃM."
[66] "1323 CUENTAS POR COBRAR A DIRECTORES"
[67] "1325 CUENTAS POR COBRAR A SOCIOS Y ACCIONISTAS"
[68] "1330 ANTICIPOS Y AVANCES"
[69] "1332 CUENTAS DE OPERACIÃN CONJUNTA"
[70] "1335 DEPÃSITOS"
[71] "1340 PROMESAS DE COMPRAVENTA"
[72] "1345 INGRESOS POR COBRAR"
[73] "1350 RETENCIÃN SOBRE CONTRATOS"
[74] "1355 ANTICIPO DE IMPTOS.Y CONTRIB.O SALDOS A FAVOR"
[75] "1360 RECLAMACIONES"
[76] "1365 CUENTAS POR COBRAR A TRABAJADORES"
[77] "1370 PRESTAMOS A PARTICULARES"
[78] "1380 DEUDORES VARIOS"
[79] "1385 DERECHOS DE RECOMP. DE CART.NEGOCIADA"
[80] "1390 DEUDAS DE DIFÃ\u008dCIL COBRO"
[81] "1399 PROVISIONES"
[82] "13 SUBTOTAL DEUDORES A LARGO PLAZO"
[83] "15 PROPIEDADES PLANTA Y EQUIPO"
[84] "1605 CRÃDITO MERCANTIL"
[85] "1610 MARCAS"
[86] "1615 PATENTES"
[87] "1620 CONCESIONES Y FRANQUICIAS"
[88] "1625 DERECHOS"
[89] "1630 KNOW HOW"
[90] "1635 LICENCIAS"
[91] "1698 AMORTIZACIÃN ACUMULADA"
[92] "1699 PROVISIONES"
[93] "16 SUBTOTAL INTANGIBLES"
[94] "1705 GASTOS PAGADOS POR ANTICIPADO"
[95] "1710 CARGOS DIFERIDOS"
[96] "1715 COSTOS DE EXPLORACIÃN POR AMORTIZAR"
[97] "1720 COSTOS DE EXPLOTACIÃN Y DESARROLLO"
[98] "1730 CARGOS POR CORRECCIÃN MONETARIA DIFERIDA"
[99] "1798 AMORTIZACIÃN ACUMULADA"
[100] "17 SUBTOTAL DIFERIDOS"
[101] "1805 BIENES DE ARTE Y CULTURA"
[102] "1895 DIVERSOS"
[103] "1899 PROVISIONES"
[104] "18 SUBTOTAL OTROS ACTIVOS"
[105] "1905 DE INVERSIONES"
[106] "1910 DE PROPIEDADES PLANTA Y EQUIPO"
[107] "1995 DE OTROS ACTIVOS"
[108] "19 SUBTOTAL VALORIZACIONES"
[109] "TOTAL ACTIVO NO CORRIENTE"
[110] "TOTAL ACTIVO"
[111] "21 OBLIGACIONES FINANCIERAS (CP)"
[112] "22 PROVEEDORES (CP)"
[113] "2305 CUENTAS CORRIENTES COMERCIALES (CP)"
[114] "2310 A CASA MATRIZ (CP)"
[115] "2315 A COMPAÃÃ\u008dAS VINCULADAS (CP)"
[116] "2320 A CONTRATISTAS (CP)"
[117] "2330 ORDENES DE COMPRA POR UTILIZAR (CP)"
[118] "2335 COSTOS Y GASTOS POR PAGAR (CP)"
[119] "2340 INSTALAMENTOS POR PAGAR (CP)"
[120] "2345 ACREEDORES OFICIALES (CP)"
[121] "2350 REGALÃ\u008dAS POR PAGAR (CP)"
[122] "2355 DEUDAS CON ACCIONISTAS O SOCIOS (CP)"
[123] "2357 DEUDAS CON DIRECTORES (CP)"
[124] "2360 DIVIDENDOS O PARTICIPACIONES POR PAGAR (CP)"
[125] "2365 RETENCIÃN EN LA FUENTE (CP)"
[126] "2367 IMPUESTO A LAS VENTAS RETENIDO (CP)"
[127] "2368 IMPUESTO DE INDUSTRIA Y COMERCIO RETENIDO (CP)"
[128] "2370 RETENCIONES Y APORTES DE NÃMINA (CP)"
[129] "2375 CUOTAS POR DEVOLVER"
[130] "2380 ACREEDORES (CP)"
[131] "23 SUBTOTAL CUENTAS POR PAGAR (CP)"
[132] "24 IMPUESTOS GRAVÃ\u0081MENES Y TASAS (CP)"
[133] "25 OBLIGACIONES LABORALES (CP)"
[134] "2605 PARA COSTOS Y GASTOS (CP)"
[135] "2610 PARA OBLIGACIONES LABORALES (CP)"
[136] "2615 PARA OBLIGACIONES FISCALES (CP)"
[137] "2620 PENSIONES DE JUBILACIÃN (CP)"
[138] "2625 PARA OBRAS DE URBANISMO (CP)"
[139] "2630 PARA MANTENIMIENTO Y REPARACIONES (CP)"
[140] "2635 PARA CONTINGENCIAS (CP)"
[141] "2640 PARA OBLIGACIONES DE GARANTÃ\u008dAS (CP)"
[142] "2695 PROVISIONES DIVERSAS (CP)"
[143] "26 SUBTOTAL PASIVOS ESTIMAD. Y PROVIS. (CP)"
[144] "27 DIFERIDOS (CP)"
[145] "2805 ANTICIPOS Y AVANCES RECIBIDOS (CP)"
[146] "2810 DEPÃSITOS RECIBIDOS (CP)"
[147] "2815 INGRESOS RECIBIDOS PARA TERCEROS (CP)"
[148] "2820 CUENTAS DE OPERACIÃN CONJUNTA (CP)"
[149] "2825 RETENCIONES A TERCEROS SOBRE CONTRATOSV"
[150] "2830 EMBARGOS JUDICIALES (CP)"
[151] "2835 ACREEDORES DEL SISTEMA (CP)"
[152] "2840 CUENTAS EN PARTICIPACIÃN (CP)"
[153] "2895 DIVERSOS (CP)"
[154] "28 SUBTOTAL OTROS PASIVOS (CP)"
[155] "2905 BONOS EN CIRCULACIÃN (CP)"
[156] "2910 BONOS OBLIGATOR. CONVERTIBLES EN ACCIONES (CP)"
[157] "2915 PAPELES COMERCIALES (CP)"
[158] "2920 BONOS PENSIONALES (CP)"
[159] "2925 TÃ\u008dTULOS PENSIONALES (CP)"
[160] "29 SUBTOTAL BONOS Y PAPELES COMERCIA. (CP)"
[161] "TOTAL PASIVO CORRIENTE"
[162] "21 OBLIGACIONES FINANCIERAS"
[163] "22 PROVEEDORES (LP)"
[164] "2305 CUENTAS CORRIENTES COMERCIALES"
[165] "2310 A CASA MATRIZ"
[166] "2315 A COMPAÃÃ\u008dAS VINCULADAS"
[167] "2320 A CONTRATISTAS"
[168] "2335 COSTOS Y GASTOS POR PAGAR"
[169] "2345 ACREEDORES OFICIALES"
[170] "2350 REGALÃ\u008dAS POR PAGAR"
[171] "2355 DEUDAS CON ACCIONISTAS O SOCIOS"
[172] "2357 DEUDAS CON DIRECTORES"
[173] "2360 DIVIDENDOS O PARTICIPACIONES POR PAGAR"
[174] "2375 CUOTAS POR DEVOLVER__1"
[175] "2380 ACREEDORES VARIOS"
[176] "23 SUBTOTAL CUENTAS POR PAGAR"
[177] "24 IMPUESTOS GRAVÃ\u0081MENES Y TASAS (LP)"
[178] "25 OBLIGACIONES LABORALES"
[179] "2605 PARA COSTOS Y GASTOS"
[180] "2610 PARA OBLIGACIONES LABORALES"
[181] "2615 PARA OBLIGACIONES FISCALES"
[182] "2620 PENSIONES DE JUBILACIÃN (LP)"
[183] "2625 PARA OBRAS DE URBANISMO"
[184] "2635 PARA CONTINGENCIAS"
[185] "2640 PARA OBLIGACIONES DE GARANTÃ\u008dAS"
[186] "2695 PROVISIONES DIVERSAS"
[187] "26 SUBTOTAL PASIVOS ESTIMAD. Y PROVIS."
[188] "2705 INGRESOS RECIBIDOS POR ANTICIPADO"
[189] "2710 ABONOS DIFERIDOS"
[190] "2715 UTILIDAD DIFERIDA EN VENTAS A PLAZOS"
[191] "2720 CRÃDITO POR CORRECCIÃN MONETARIA DIFERIDA"
[192] "2725 IMPUESTOS DIFERIDOS"
[193] "27 SUBTOTAL DIFERIDOS"
[194] "2805 AVANCES Y ANTICIPOS RECIBIDOS"
[195] "2810 DEPÃSITOS RECIBIDOS"
[196] "2815 INGRESOS RECIBIDOS PARA TERCEROS"
[197] "2820 CUENTAS DE OPERACIÃN CONJUNTA"
[198] "2825 RETENCIONES A TERCEROS SOBRE CONTRATOS"
[199] "2835 ACREEDORES DEL SISTEMA (LP)"
[200] "2840 CUENTAS EN PARTICIPACIÃN"
[201] "2895 DIVERSOS"
[202] "28 SUBTOTAL OTROS PASIVOS"
[203] "2905 BONOS EN CIRCULACIÃN"
[204] "2910 BONOS OBLIGATOR. CONVERTIBLES EN ACCIONES"
[205] "2915 PAPELES COMERCIALES"
[206] "2920 BONOS PENSIONALES (LP)"
[207] "2925 TÃ\u008dTULOS PENSIONALES (LP)"
[208] "29 SUBTOTAL BONOS Y PAPELES COMERCIA."
[209] "TOTAL PASIVO NO CORRIENTE"
[210] "TOTAL PASIVO"
[211] "3105 CAPITAL SUSCRITO Y PAGADO"
[212] "3115 APORTES SOCIALES"
[213] "3120 CAPITAL ASIGNADO"
[214] "3125 INVERSIÃN SUPLEMENTARIA AL CAPITAL ASIGNADO"
[215] "3130 CAPITAL DE PERSONAS NATURALES"
[216] "3135 APORTES DEL ESTADO"
[217] "3140 FONDO SOCIAL"
[218] "31 SUBTOTAL CAPITAL SOCIAL"
[219] "3205 PRIMA EN COLOC.ACC,CUOTAS O PARTES DE INT. SOCIAL"
[220] "3210 DONACIONES"
[221] "3215 CRÃDITO MERCANTIL"
[222] "3220 KNOW HOW"
[223] "3225 SUPERÃ\u0081VIT MÃTODO DE PARTICIPACIÃN"
[224] "32 SUBTOTAL SUPERÃ\u0081VIT DE CAPITAL"
[225] "33 RESERVAS"
[226] "34 REVALORIZACIÃN DEL PATRIMONIO"
[227] "35 DIVIDEN. O PARTC. DECRET. EN ACC.O CUOTAS"
[228] "36 RESULTADOS DEL EJERCICIO"
[229] "3705 UTILIDADES ACUMULADAS"
[230] "3710 PERDIDAS ACUMULADAS"
[231] "37 RESULTADOS DE EJERCICIOS ANTERIORES"
[232] "38 SUPERÃ\u0081VIT POR VALORIZACIONES"
[233] "TOTAL PATRIMONIO"
[234] "TOTAL PASIVO Y PATRIMONIO"
[235] "81 DERECHOS CONTINGENTES"
[236] "82 DEUDORAS FISCALES"
[237] "83 DEUDORAS DE CONTROL"
[238] "9 CUENTAS DE ORDEN ACREEDORAS POR CONTRA"
[239] "91 RESPONSABILIDADES CONTINGENTES"
[240] "92 ACREEDORAS FISCALES"
[241] "93 ACREEDORAS DE CONTROL"
[242] "8 CTAS DE ORDEN DEUDORAS POR CONTRA"
Tercero, sin convertir a excel:
super2 <- read.csv("BalanceGeneral2015SIREMV2.txt", header = TRUE, sep = ";", dec = ",", as.is = TRUE)
dim(super2)
names(super2)
library(DescTools)
XLView(head(super))
Otra opción:
library(xlsx)
write.xlsx(head(super), file = "supersociedades.xlsx", sheetName = "myData", showNA = FALSE)
Explorar el potencial de ggplot2 para describir datos.
Algunos ajustes a los nombres de la base de datos:
library(dplyr)
super.adj <- data.frame(dpto = super$DEPARTAMENTO, ciiu = super$CIIU, ciudad = super$CIUDAD)
super.adj$activoCorriente <- super$`TOTAL ACTIVO CORRIENTE`
super.adj$pasivoCorriente <- super$`TOTAL PASIVO CORRIENTE`
super.adj$razonCorriente <- ifelse(super.adj$pasivoCorriente > 0, super.adj$activoCorriente / super.adj$pasivoCorriente, NA)
Un gráfico de muestra en R base:
hist(x = super.adj$razonCorriente)
boxplot(razonCorriente ~ dpto, data = super.adj)
library(ggplot2)
ggplot(data = super.adj, aes(x = razonCorriente)) + geom_histogram()
ggplot(data = super.adj, aes(x = razonCorriente, y = dpto)) + geom_boxplot()
Removiendo los outliers:
super.adj.filtered <- filter(super.adj, razonCorriente < 10)
hist(x = super.adj.filtered$razonCorriente)
boxplot(razonCorriente ~ dpto, data = super.adj.filtered)
ggplot(data = super.adj.filtered, aes(x = razonCorriente)) + geom_histogram()
ggplot(data = super.adj.filtered, aes(x = dpto, y = razonCorriente)) + geom_boxplot() + coord_flip()
Seleccionando los departamentos a analizar:
library(ggplot2)
myDpto <- c("BOGOTA D.C.", "BOYACA", "TOLIMA")
ggplot(data = filter(super.adj, razonCorriente < 10 & dpto %in% myDpto), aes(x = razonCorriente)) + geom_histogram() + facet_wrap(~ dpto, scales = "free_y")
Ahora uno de dispersión:
plot(activoCorriente ~ pasivoCorriente, data = super.adj.filtered)
ggplot(data = filter(super.adj, razonCorriente < 10 & dpto %in% myDpto), aes(x = pasivoCorriente, y = activoCorriente)) + geom_point() + facet_wrap(~ dpto, scales = "free") + geom_smooth(method = "lm")
Estudiar la relación entre educación (capital humano) y crecimiento en la base de datos PWT9.0.
Aplicar todo lo aprendido hasta el momento a un proyecto de investigación.
Construir la sección de descripción de los datos de un proyecto de investigación o un informe de consultoría.
https://www.supersociedades.gov.co/Servicio_Ciudadano/tramitesyservicios/Paginas/SIREM.aspx
Fundamentos de regresión: Mínimos cuadrados, propiedades y supuestos.
library(readxl)
pg2013 <- read_excel("EstadoResultados2013SIREMV2.xlsx")
names(pg2013)
pg2014 <- read_excel("EstadoResultados2014SIREMV2.xlsx")
names(pg2014)
names(pg2013) == names(pg2014)
pg2015 <- read_excel("EstadoResultados2015SIREMV2.xls")
names(pg2015)
names(pg2013) == names(pg2015)
cbind(names(pg2013), names(pg2015))
pg2015 <- pg2015[ , -5]
names(pg2015) <- names(pg2013)
pg <- list(pg2013, pg2014, pg2015)
names(pg[[1]]) == names(pg[[2]])
names(pg[[1]]) == names(pg[[3]])
all(names(pg[[1]]) == names(pg[[3]]))
which((names(pg[[1]]) == names(pg[[3]])) == FALSE)
cbind(names(pg[[1]]), names(pg[[3]]))
all(names(pg[[1]]) == names(pg[[3]]))
[1] TRUE
names(pg1315)
[1] "year" "nit" "razSoc" "ciudad" "dpto" "ciiu"
[7] "sector" "ingOpe" "cosVen" "utiBru" "gasAdm" "gasVen"
[13] "utiOpe" "ingNoOpe" "gasNoOpe" "intereses" "uadi" "impRen"
[19] "udi"
names(ef1315)
[1] "year" "nit" "razSoc" "ciudad" "dpto" "ciiu"
[7] "sector" "disponible" "actCte" "actTot" "pasCte" "pasTot"
[13] "patTot" "ingOpe" "cosVen" "utiBru" "gasAdm" "gasVen"
[19] "utiOpe" "ingNoOpe" "gasNoOpe" "intereses" "uadi" "impRen"
[25] "udi"
summary(ef1315)
year nit razSoc ciudad
Length:61725 Min. :800000001 Length:61725 Length:61725
Class :character 1st Qu.:811022490 Class :character Class :character
Mode :character Median :860031774 Mode :character Mode :character
Mean :853634412
3rd Qu.:900113369
Max. :900868847
dpto ciiu sector disponible
Length:61725 Length:61725 Length:61725 Min. : 0
Class :character Class :character Class :character 1st Qu.: 21691
Mode :character Mode :character Mode :character Median : 115710
Mean : 780900
3rd Qu.: 436700
Max. :851257912
actCte actTot pasCte pasTot
Min. :0.000e+00 Min. :0.000e+00 Min. :0.000e+00 Min. :0.000e+00
1st Qu.:6.753e+05 1st Qu.:1.846e+06 1st Qu.:2.799e+05 1st Qu.:5.020e+05
Median :1.938e+06 Median :4.659e+06 Median :9.924e+05 Median :1.664e+06
Mean :7.761e+06 Mean :2.217e+07 Mean :5.406e+06 Mean :8.561e+06
3rd Qu.:5.607e+06 3rd Qu.:1.209e+07 3rd Qu.:3.366e+06 3rd Qu.:5.245e+06
Max. :2.480e+09 Max. :2.135e+10 Max. :2.004e+09 Max. :1.034e+10
patTot ingOpe cosVen
Min. :-1.541e+08 Min. :0.000e+00 Min. : -263571
1st Qu.: 6.915e+05 1st Qu.:4.844e+05 1st Qu.: 0
Median : 1.993e+06 Median :2.342e+06 Median : 1022109
Mean : 1.361e+07 Mean :1.433e+07 Mean : 10182120
3rd Qu.: 5.902e+06 3rd Qu.:8.364e+06 3rd Qu.: 5253834
Max. : 2.009e+10 Max. :7.150e+09 Max. :7306821025
utiBru gasAdm gasVen
Min. :-789124779 Min. :0.000e+00 Min. : 0
1st Qu.: 221524 1st Qu.:1.429e+05 1st Qu.: 0
Median : 843321 Median :4.419e+05 Median : 4073
Mean : 4150083 Mean :1.576e+06 Mean : 1504727
3rd Qu.: 2540752 3rd Qu.:1.121e+06 3rd Qu.: 504420
Max. :2604211940 Max. :1.584e+09 Max. :711338660
utiOpe ingNoOpe gasNoOpe intereses
Min. :-804018063 Min. :0.000e+00 Min. :0.000e+00 Min. : 0
1st Qu.: -919 1st Qu.:5.885e+03 1st Qu.:1.857e+04 1st Qu.: 2657
Median : 129360 Median :5.888e+04 Median :9.798e+04 Median : 31586
Mean : 1069615 Mean :9.914e+05 Mean :1.044e+06 Mean : 262747
3rd Qu.: 585156 3rd Qu.:3.123e+05 3rd Qu.:3.983e+05 3rd Qu.: 143260
Max. :2280130395 Max. :2.373e+09 Max. :2.364e+09 Max. :244475651
NA's :12482
uadi impRen udi
Min. :-794796715 Min. :-33842819 Min. :-794796715
1st Qu.: 9059 1st Qu.: 15294 1st Qu.: 1619
Median : 120628 Median : 55274 Median : 73386
Mean : 1016672 Mean : 386905 Mean : 674177
3rd Qu.: 512378 3rd Qu.: 188080 3rd Qu.: 340166
Max. :2219800850 Max. :849789644 Max. :1380571993
NA's :7085
Explorar el uso de R para la estimación de modelos de regresión.
ef1315 %>%
filter(dpto == "BOYACA") %>%
select(razCor, roa) %>%
ggplot(aes(x = log(razCor), y = roa)) + geom_point() + geom_smooth() #method = "lm")
Heteroscedasticidad:
bptest(regBoyaca, ~ log(razCor) + I(log(razCor))^2, data = dataBoyaca)
studentized Breusch-Pagan test
data: regBoyaca
BP = 0.0032455, df = 1, p-value = 0.9546
gqtest(regBoyaca, order.by = ~razCor, data = dataBoyaca)
Goldfeld-Quandt test
data: regBoyaca
GQ = 1.1669, df1 = 144, df2 = 143, p-value = 0.1783
alternative hypothesis: variance increases from segment 1 to 2
resettest(regBoyaca)
RESET test
data: regBoyaca
RESET = 1.857, df1 = 2, df2 = 287, p-value = 0.158
# Reset test
resettest(regBoyaca)
coeftest(regBoyaca, vcov = vcovHC(regBoyaca))
t test of coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.0026151 0.0121086 0.2160 0.829166
log(razCor) 0.0407920 0.0131554 3.1008 0.002121 **
---
Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1
coeftest(regBoyaca, vcov = vcovHC(regBoyaca))
coeftest(regBoyaca)
Factor de inflación de Varianza:
ef1315 %>%
filter(dpto == "BOYACA") %>%
select(razCor, roa, actTot) %>%
lm(roa ~ log(razCor) + actTot, data = .) %>% #, na.action = na.omit)
summary
Call:
lm(formula = roa ~ log(razCor) + actTot, data = .)
Residuals:
Min 1Q Median 3Q Max
-1.01129 -0.02797 0.00418 0.03249 0.67294
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -6.820e-03 1.103e-02 -0.618 0.537
log(razCor) 4.221e-02 7.038e-03 5.997 6e-09 ***
actTot 1.302e-09 8.244e-10 1.580 0.115
---
Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1
Residual standard error: 0.135 on 288 degrees of freedom
Multiple R-squared: 0.1129, Adjusted R-squared: 0.1067
F-statistic: 18.32 on 2 and 288 DF, p-value: 3.239e-08
ef1315 %>%
filter(dpto == "BOYACA") %>%
select(razCor, roa, actTot) %>%
lm(roa ~ log(razCor) + actTot, data = .) %>% #, na.action = na.omit)
summary
ef1315 %>%
#filter(dpto == "BOYACA") %>%
filter(razCor > 0) %>%
select(razCor, roa) %>%
lm(roa ~ log(razCor), data = .) %>% #, na.action = na.omit)
summary
ef1315 %>%
#filter(dpto == "BOYACA") %>%
filter(razCor > 0) %>%
select(razCor, roa, actTot) %>%
lm(roa ~ log(razCor) + actTot, data = .) %>% #, na.action = na.omit)
summary
ef1315$ciiu1 <- substr(ef1315$ciiu, 1,1)
ef1315 %>% select(nit, ciiu, ciiu1) %>% head()
Aplicaciones de la regresión. Interpretación de los resultados: Efectos marginales y modelos no lineales.
ef1315 %>%
#filter(dpto == "BOYACA") %>%
filter(razCor > 0) %>%
lm(roa ~ log(razCor) + actTot + ciiu1, data = .) %>% #, na.action = na.omit)
summary
Validación de los modelos. Supuestos.
Taller
Estudiar el uso de los modelos de regresión en la investigación.
Lectura de artículos de investigación.
Comparación de los modelo de regresión y análisis.
Informes de investigación tipo paper/artículo.
htmlreg(myRegs, file = "output.doc")
The table was written to the file 'output.doc'.
Estudiar el uso de los modelos de regresión en estructuras complejas de datos generalmente utilizados en la investigación.
# Desarrollar regresiones por departamentos y analizar la distribución de los coeficientes a través del país.
Integrar las herramientas de tidyverse al análisis de regresión.
Explorar el uso de R para la estimación de modelos de panel (Pooling, Efectos fijos, Efectos aleatorios)
Fundamentación
Estimación de los modelos en R.
Taller reporte de resultados de investigación.
Repasar y aclarar dudas sobre R y Econometría.
Aclaración de dudas.
Presentación y discusión de los proyectos.