library(readxl)
datos_tesis1 <- read_excel("C:/Users/Isabella/Desktop/datos tesis1.xlsx", 
    col_types = c("numeric", "text", "text", 
        "text", "numeric", "text", "text", 
        "numeric", "text", "text", "numeric", 
        "text", "text", "numeric", "text", 
        "text", "text", "text", "text", "text", 
        "numeric", "text", "text", "text", 
        "text", "text", "text"))
## New names:
## * `101. ¿Obtuvo el crédito solicitado?` -> `101. ¿Obtuvo el crédito solicitado?...10`
## * `101. ¿Obtuvo el crédito solicitado?` -> `101. ¿Obtuvo el crédito solicitado?...11`
modelofinal=glm(formula= Y~EDAD+EMPLEADOS+CC+RUT+X1+DEUDAASUMIDA+M1+M2+SOLVENCIA+MORA, family="binomial", data = datos_tesis1)
summary(modelofinal)
## 
## Call:
## glm(formula = Y ~ EDAD + EMPLEADOS + CC + RUT + X1 + DEUDAASUMIDA + 
##     M1 + M2 + SOLVENCIA + MORA, family = "binomial", data = datos_tesis1)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -3.1107  -0.9077   0.1635   0.8967   1.7956  
## 
## Coefficients:
##               Estimate Std. Error z value Pr(>|z|)    
## (Intercept)   -1.05778    0.18250  -5.796 6.79e-09 ***
## EDAD           0.05571    0.01331   4.184 2.86e-05 ***
## EMPLEADOS      0.03415    0.07388   0.462   0.6439    
## CC1            0.06281    0.25441   0.247   0.8050    
## RUT1           0.47338    0.21516   2.200   0.0278 *  
## X11            3.72502    0.66018   5.642 1.68e-08 ***
## DEUDAASUMIDA1  1.67195    0.94386   1.771   0.0765 .  
## M11           -1.03870    0.82233  -1.263   0.2065    
## M21           -0.38911    0.70032  -0.556   0.5785    
## SOLVENCIA1    -1.20189    0.71806  -1.674   0.0942 .  
## MORA1          0.78793    0.98640   0.799   0.4244    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 947.87  on 715  degrees of freedom
## Residual deviance: 664.78  on 705  degrees of freedom
## AIC: 686.78
## 
## Number of Fisher Scoring iterations: 6
exp(modelofinal$coefficients)
##   (Intercept)          EDAD     EMPLEADOS           CC1          RUT1 
##     0.3472250     1.0572864     1.0347414     1.0648282     1.6054144 
##           X11 DEUDAASUMIDA1           M11           M21    SOLVENCIA1 
##    41.4719118     5.3225294     0.3539158     0.6776591     0.3006247 
##         MORA1 
##     2.1988318
mod=predict(modelofinal,type = "response")
library(pROC)
## Warning: package 'pROC' was built under R version 4.0.5
## Type 'citation("pROC")' for a citation.
## 
## Attaching package: 'pROC'
## The following objects are masked from 'package:stats':
## 
##     cov, smooth, var
objroc <- roc(mod, datos_tesis1$Y,auc=T,ci=T)
## Warning in roc.default(mod, datos_tesis1$Y, auc = T, ci = T): 'response'
## has more than two levels. Consider setting 'levels' explicitly or using
## 'multiclass.roc' instead
## Setting levels: control = 0.197594379756048, case = 0.199482282252067
## Setting direction: controls < cases
## Warning in ci.auc.roc(roc, ...): ci.auc() of a ROC curve with AUC == 1 is always
## 1-1 and can be misleading.
plot.roc(objroc,print.auc=T,print.thres = "best",col="blue",xlab="1-ESpecificidad",ylab="Sensibilidad")