dados<- read.table("C:/Users/user/Downloads/dados.txt", header = T)
summary(dados [,-1])
## Idade Sexo N_Presc Med_Presc
## Min. :24.00 afem:52 Min. :1.00 Min. : 5.00
## 1st Qu.:52.50 masc:48 1st Qu.:3.00 1st Qu.: 33.50
## Median :71.50 Median :5.00 Median : 62.50
## Mean :66.53 Mean :4.29 Mean : 61.19
## 3rd Qu.:81.00 3rd Qu.:6.00 3rd Qu.: 86.50
## Max. :94.00 Max. :6.00 Max. :143.00
## NA's :2
Gráfico
plot(dados$Sexo)
boxplot(dados$Idade, boxwex = 0.35, col="RED",main = "IDADE")
boxplot(dados$Med_Presc, boxwex = 0.35, col="BLUE",main = "Med_Presc")
Os boxplot’s acima mostram o comportamentos das variaveis idade e Med_presc
G1<- glm (Desfecho~Sexo+N_Presc+Med_Presc+Idade, family=binomial(link="logit"), data=dados)
summary(G1)
##
## Call:
## glm(formula = Desfecho ~ Sexo + N_Presc + Med_Presc + Idade,
## family = binomial(link = "logit"), data = dados)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.6266 -1.1358 -0.8517 1.1809 1.4923
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.307819 0.916240 0.336 0.737
## Sexomasc -0.278029 0.412229 -0.674 0.500
## N_Presc -0.256992 0.238488 -1.078 0.281
## Med_Presc 0.019249 0.013414 1.435 0.151
## Idade -0.004237 0.011624 -0.365 0.715
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 135.82 on 97 degrees of freedom
## Residual deviance: 132.77 on 93 degrees of freedom
## (2 observations deleted due to missingness)
## AIC: 142.77
##
## Number of Fisher Scoring iterations: 4
anova(G1, test="Chisq")
## Analysis of Deviance Table
##
## Model: binomial, link: logit
##
## Response: Desfecho
##
## Terms added sequentially (first to last)
##
##
## Df Deviance Resid. Df Resid. Dev Pr(>Chi)
## NULL 97 135.82
## Sexo 1 0.66868 96 135.15 0.4135
## N_Presc 1 0.12084 95 135.03 0.7281
## Med_Presc 1 2.12000 94 132.91 0.1454
## Idade 1 0.13318 93 132.77 0.7152
Realizando a regressão logistica em todas as variaveis independentes acima, Analisa-se que a variável desfecho não tem relação com as demais variáveis, pois não teve significância em nenhuma das variáveis.
G2<- glm (Desfecho~Sexo, family=binomial(link="logit"), data=dados)
G2
##
## Call: glm(formula = Desfecho ~ Sexo, family = binomial(link = "logit"),
## data = dados)
##
## Coefficients:
## (Intercept) Sexomasc
## 0.07696 -0.32828
##
## Degrees of Freedom: 99 Total (i.e. Null); 98 Residual
## Null Deviance: 138.5
## Residual Deviance: 137.8 AIC: 141.8
anova(G2, test="Chisq")
## Analysis of Deviance Table
##
## Model: binomial, link: logit
##
## Response: Desfecho
##
## Terms added sequentially (first to last)
##
##
## Df Deviance Resid. Df Resid. Dev Pr(>Chi)
## NULL 99 138.47
## Sexo 1 0.66886 98 137.80 0.4134
Realizando a regressão logistica na variavel independente Sexo, Analisa-se que a variável desfecho não tem relação com a mesma, pois não teve significância.
G3<- glm (Desfecho~N_Presc, family=binomial(link="logit"), data=dados)
summary(G3)
##
## Call:
## glm(formula = Desfecho ~ N_Presc, family = binomial(link = "logit"),
## data = dados)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.172 -1.143 -1.107 1.183 1.267
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -0.24656 0.52256 -0.472 0.637
## N_Presc 0.03879 0.11235 0.345 0.730
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 138.47 on 99 degrees of freedom
## Residual deviance: 138.35 on 98 degrees of freedom
## AIC: 142.35
##
## Number of Fisher Scoring iterations: 3
anova(G1, test="Chisq")
## Analysis of Deviance Table
##
## Model: binomial, link: logit
##
## Response: Desfecho
##
## Terms added sequentially (first to last)
##
##
## Df Deviance Resid. Df Resid. Dev Pr(>Chi)
## NULL 97 135.82
## Sexo 1 0.66868 96 135.15 0.4135
## N_Presc 1 0.12084 95 135.03 0.7281
## Med_Presc 1 2.12000 94 132.91 0.1454
## Idade 1 0.13318 93 132.77 0.7152
Realizando a regressão logistica na variavel independente N_Presc, Analisa-se que a variável desfecho não tem relação com a mesma, pois não teve significância.
G4<- glm (Desfecho~Med_Presc, family=binomial(link="logit"), data=dados)
summary(G4)
##
## Call:
## glm(formula = Desfecho ~ Med_Presc, family = binomial(link = "logit"),
## data = dados)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.281 -1.146 -1.036 1.187 1.350
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -0.425994 0.432303 -0.985 0.324
## Med_Presc 0.005644 0.006234 0.905 0.365
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 138.47 on 99 degrees of freedom
## Residual deviance: 137.64 on 98 degrees of freedom
## AIC: 141.64
##
## Number of Fisher Scoring iterations: 3
anova(G4, test="Chisq")
## Analysis of Deviance Table
##
## Model: binomial, link: logit
##
## Response: Desfecho
##
## Terms added sequentially (first to last)
##
##
## Df Deviance Resid. Df Resid. Dev Pr(>Chi)
## NULL 99 138.47
## Med_Presc 1 0.82662 98 137.64 0.3633
Realizando a regressão logistica na variavel independente Med_Presc, Analisa-se que a variável desfecho não tem relação com a mesma, pois não teve significância.
G5<- glm (Desfecho~Idade, family=binomial(link="logit"), data=dados)
summary(G5)
##
## Call:
## glm(formula = Desfecho ~ Idade, family = binomial(link = "logit"),
## data = dados)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.205 -1.155 -1.127 1.201 1.229
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.150853 0.780162 0.193 0.847
## Idade -0.002881 0.011328 -0.254 0.799
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 135.82 on 97 degrees of freedom
## Residual deviance: 135.75 on 96 degrees of freedom
## (2 observations deleted due to missingness)
## AIC: 139.75
##
## Number of Fisher Scoring iterations: 3
anova(G5, test="Chisq")
## Analysis of Deviance Table
##
## Model: binomial, link: logit
##
## Response: Desfecho
##
## Terms added sequentially (first to last)
##
##
## Df Deviance Resid. Df Resid. Dev Pr(>Chi)
## NULL 97 135.82
## Idade 1 0.064732 96 135.75 0.7992
Realizando a regressão logistica na variavel independente Idade, Analisa-se que a variável desfecho não tem relação com a mesma, pois não teve significância.
dev <- c(G1$deviance, G2$deviance, G3$deviance, G4$deviance, G5$deviance) # Deviance
aic <- c(G1$aic,G2$aic, G3$aic, G4$aic, G5$aic) # AIC
criterios <- cbind(dev, aic)
colnames(criterios) <- c("Deviance", "AIC")
rownames(criterios) <- c("Desfecho", "Idade", "Sexo", "N_Presc", "Med_Presc")
criterios
## Deviance AIC
## Desfecho 132.7733 142.7733
## Idade 137.8005 141.8005
## Sexo 138.3500 142.3500
## N_Presc 137.6428 141.6428
## Med_Presc 135.7513 139.7513
library(pscl)
## Warning: package 'pscl' was built under R version 3.5.3
## Classes and Methods for R developed in the
## Political Science Computational Laboratory
## Department of Political Science
## Stanford University
## Simon Jackman
## hurdle and zeroinfl functions by Achim Zeileis
pR2(G1)
## llh llhNull G2 McFadden r2ML
## -66.38666605 -69.23469671 5.69606132 0.04113589 0.05646618
## r2CU
## 0.07463380
pR2(G2)
## llh llhNull G2 McFadden r2ML
## -68.900264312 -69.234696709 0.668864795 0.004830416 0.006666329
## r2CU
## 0.008893186
pR2(G3)
## llh llhNull G2 McFadden r2ML
## -6.917500e+01 -6.923470e+01 1.193987e-01 8.622748e-04 1.193274e-03
## r2CU
## 1.591882e-03
pR2(G4)
## llh llhNull G2 McFadden r2ML
## -68.821385248 -69.234696709 0.826622921 0.005969716 0.008232158
## r2CU
## 0.010982074
pR2(G5)
## llh llhNull G2 McFadden r2ML
## -67.87564824 -69.23469671 2.71809694 0.01962959 0.02735458
## r2CU
## 0.03615573
require(epiDisplay)
## Loading required package: epiDisplay
## Warning: package 'epiDisplay' was built under R version 3.5.3
## Loading required package: foreign
## Loading required package: survival
## Warning: package 'survival' was built under R version 3.5.3
## Loading required package: MASS
## Warning: package 'MASS' was built under R version 3.5.3
## Loading required package: nnet
logistic.display(G1, crude= T)
##
## Logistic regression predicting Desfecho
##
## crude OR(95%CI) adj. OR(95%CI)
## Sexo: masc vs afem 0.72 (0.32,1.59) 0.76 (0.34,1.7)
##
## N_Presc (cont. var.) 1.04 (0.84,1.3) 0.77 (0.48,1.23)
##
## Med_Presc (cont. var.) 1.01 (0.99,1.02) 1.02 (0.99,1.05)
##
## Idade (cont. var.) 0.9971 (0.9752,1.0195) 0.9958 (0.9733,1.0187)
##
## P(Wald's test) P(LR-test)
## Sexo: masc vs afem 0.5 0.5
##
## N_Presc (cont. var.) 0.281 0.275
##
## Med_Presc (cont. var.) 0.151 0.142
##
## Idade (cont. var.) 0.715 0.715
##
## Log-likelihood = -66.3867
## No. of observations = 98
## AIC value = 142.7733