library(rio)
data=import("data2.xlsx")
## New names:
## • `` -> `...1`
## • `Población de niños menores de un año
(CENSO 2017)
1a/` -> `Población de
## niños menores de un año
(CENSO 2017)
1a/...7`
## • `Población de niños menores de un año
(CENSO 2017)
1a/` -> `Población de
## niños menores de un año
(CENSO 2017)
1a/...22`
Pregunta 1:
Damos formato:
data = data[,c(1,2,3,19,29,34,46)]
Renombrando:
colnames(data) = c("PROVINCIA","UBIGEO","DISTRITO", "NUM_DISTRITOS","IVIA","IDE","DEVENGADO")
En base a la variables dependiente corremos una regresion gaussiana:
modelo1=formula(DEVENGADO~IVIA+IDE+NUM_DISTRITOS)
reg1=lm(modelo1,data=data)
summary(reg1)
##
## Call:
## lm(formula = modelo1, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2709.2 -1142.4 -425.2 542.3 10819.1
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -752.08 1949.01 -0.386 0.700
## IVIA -539.33 1041.83 -0.518 0.605
## IDE 5445.57 2375.35 2.293 0.023 *
## NUM_DISTRITOS 35.78 24.18 1.480 0.141
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1888 on 192 degrees of freedom
## Multiple R-squared: 0.09031, Adjusted R-squared: 0.07609
## F-statistic: 6.353 on 3 and 192 DF, p-value: 0.0003964
Análisis:
-Se puede concluir que las variables “IVIA” e “NUM_DISTRITOS” no tienen un efectos significativo.
-La variable IDE es significativa al 0.05, el valor de dicha magnitud es de 5445.57 y es de carácter positivo. Es decir que cuando IDE aumenta en una unidad, el valor de DEVENGADO aumenta en 5446 aproximadamente.
-En base el R-squared se pude concluir que las variables incluidas en el modelo explican solo alrededor del 8% de la variabilidad de la variable dependiente.
PREGUNTA 2:
data2=import("dataCarcel.xlsx")
Comprobado hipótesis:
library(survival)
data2$survival=with(data2,Surv(time = semanasLibre, event = fueArrestado))
library(magrittr)
data2%>%
rmarkdown::paged_table()
COX_H1= formula(survival~edad+casado)
rcox1 <- coxph(COX_H1,data=data2)
summary(rcox1)
## Call:
## coxph(formula = COX_H1, data = data2)
##
## n= 432, number of events= 114
##
## coef exp(coef) se(coef) z Pr(>|z|)
## edad -0.06672 0.93545 0.02082 -3.205 0.00135 **
## casado -0.49314 0.61070 0.37269 -1.323 0.18576
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## exp(coef) exp(-coef) lower .95 upper .95
## edad 0.9355 1.069 0.8981 0.9744
## casado 0.6107 1.637 0.2942 1.2678
##
## Concordance= 0.616 (se = 0.027 )
## Likelihood ratio test= 17.27 on 2 df, p=2e-04
## Wald test = 13.99 on 2 df, p=9e-04
## Score (logrank) test = 14.51 on 2 df, p=7e-04
Al exponenciar notamos que la variable edad no tiene un efecto significativo por lo tanto ambos están en lo incorrecto.
PREGUNTA 3:
data3=import("data3.xlsx")
modelo2=formula(MaterMort100m~Tuberculosis100m+EmployPerPop)
reg2=lm(modelo2,data=data3)
summary(reg2)
##
## Call:
## lm(formula = modelo2, data = data3)
##
## Residuals:
## Min 1Q Median 3Q Max
## -520.80 -99.71 -52.99 35.21 1028.94
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -28.05760 43.65145 -0.643 0.52113
## Tuberculosis100m 0.75078 0.09557 7.856 2.56e-13 ***
## EmployPerPop 2.33807 0.88920 2.629 0.00923 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 194.2 on 196 degrees of freedom
## (64 observations deleted due to missingness)
## Multiple R-squared: 0.2864, Adjusted R-squared: 0.2791
## F-statistic: 39.33 on 2 and 196 DF, p-value: 4.351e-15
modelo3=formula(MaterMort100m~TasaFertil1mMuje+EmployPerPop)
reg2=lm(modelo3,data=data3)
summary(reg2)
##
## Call:
## lm(formula = modelo3, data = data3)
##
## Residuals:
## Min 1Q Median 3Q Max
## -320.64 -71.02 -7.28 52.01 876.75
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -89.8159 31.1505 -2.883 0.00432 **
## TasaFertil1mMuje 4.3535 0.2488 17.497 < 2e-16 ***
## EmployPerPop 1.0524 0.6383 1.649 0.10057
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 142.5 on 223 degrees of freedom
## (37 observations deleted due to missingness)
## Multiple R-squared: 0.6037, Adjusted R-squared: 0.6001
## F-statistic: 169.9 on 2 and 223 DF, p-value: < 2.2e-16
El modelo 3 explica cerca del 60% en base al R-Squared, que es superior al del modelo 2 con 28%, por lo tanto la razón la tiene el colega B, además la variable Fertilidad es significativa al 0.001 y tiene un efecto positivo.
PREGUNTA 4:
data4=import("data4.xlsx")
modelo5=formula(admitido~letras+ciencias+prestigio)
rlog1=glm(modelo5, data=data4,family = binomial)
summary(rlog1)
##
## Call:
## glm(formula = modelo5, family = binomial, data = data4)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -6.249705 1.155732 -5.408 6.39e-08 ***
## letras 0.002294 0.001092 2.101 0.0356 *
## ciencias 0.007770 0.003275 2.373 0.0177 *
## prestigio 0.560031 0.127137 4.405 1.06e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 499.98 on 399 degrees of freedom
## Residual deviance: 459.44 on 396 degrees of freedom
## AIC: 467.44
##
## Number of Fisher Scoring iterations: 4