library(rio)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(car)
## Loading required package: carData
## 
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
## 
##     recode
endo=import("ENDO1.sav")
data = select(endo, P2_2, P1_24_E, P1_2, P1_4, P1_5, P1_11_B, P1_11_F, P1_11_G, P1_11_H, P1_11_L, P1_18)
table(data$P2_2)
## 
##     0     1 
##  1551 16489
data$retorno=as.factor(data$P2_2)
levels(data$retorno) = c("no", "si")
table(data$retorno)
## 
##    no    si 
##  1551 16489

variables:

table(data$P1_11_B)
## 
##     0     1 
## 15181  3749
table(data$P1_11_F)
## 
##     0     1 
## 13705  5225
table(data$P1_11_G)
## 
##     0     1 
## 15870  3060
modelo1 = glm(retorno ~ P1_11_B+P1_11_F+P1_11_G, family = binomial(link="logit") ,data = data)
summary(modelo1)
## 
## Call:
## glm(formula = retorno ~ P1_11_B + P1_11_F + P1_11_G, family = binomial(link = "logit"), 
##     data = data)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -2.2967   0.3853   0.3853   0.4515   0.5474  
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept)  2.56328    0.03574  71.722  < 2e-16 ***
## P1_11_B     -0.28345    0.06287  -4.508 6.53e-06 ***
## P1_11_F     -0.40975    0.06039  -6.785 1.16e-11 ***
## P1_11_G     -0.04755    0.07310  -0.651    0.515    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 10576  on 18039  degrees of freedom
## Residual deviance: 10490  on 18036  degrees of freedom
##   (10176 observations deleted due to missingness)
## AIC: 10498
## 
## Number of Fisher Scoring iterations: 5
exp(coef(modelo1))
## (Intercept)     P1_11_B     P1_11_F     P1_11_G 
##  12.9782539   0.7531831   0.6638178   0.9535612
1-(exp(-0.2834))
## [1] 0.2467816
1-(exp(-0.4097))
## [1] 0.3361506
1-(exp(-0.0475))
## [1] 0.04638953

log.odds1 = predict(modelo2, data.frame(P1_4 = 0, P1_11_H = 1, P1_11_G = 1)) log.odds1 ```