How to extract odds ratio of intercept and slope coefficient from simple logistic model in R?

R ProgrammingServer Side ProgrammingProgramming

To create the simple logistic model, we need to use glm function with family = binomial because the dependent variable in simple logistic model or binomial logistic model has two categories, if there are more than two categories then the model is called as multinomial logistic model. If we want to extract the odds ratio of slope and intercept from the simple logistic model then exp function needs to be used with model object as shown in the below examples.

Example

 Live Demo

set.seed(999)
x1<-rpois(1000,10)
y1<-sample(0:1,1000,replace=TRUE) LogisticModel_1<-glm(y1~x1,family=binomial)
summary(LogisticModel_1)

Output

Call:
glm(formula = y1 ~ x1, family = binomial)

Deviance Residuals:
Min 1Q Median 3Q Max
-1.177 -1.122 -1.088 1.234 1.319

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.03144 0.21467 0.146 0.884
x1 -0.01630 0.02044 -0.797 0.425

(Dispersion parameter for binomial family taken to be 1)

Null deviance: 1381.9 on 999 degrees of freedom
Residual deviance: 1381.3 on 998 degrees of freedom
AIC: 1385.3

Number of Fisher Scoring iterations: 3

Example

 Live Demo

x2<-rpois(100000,15)
y2<-sample(c(TRUE,FALSE),100000,replace=TRUE) LogisticModel_2<-glm(y2~x2,family=binomial)
summary(LogisticModel_2)

Output

Call:
glm(formula = y2 ~ x2, family = binomial)

Deviance Residuals:
Min 1Q Median 3Q Max
-1.181 -1.180 1.174 1.175 1.177

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.0084037 0.0252237 0.333 0.739
x2 -0.0002083 0.0016286 -0.128 0.898

(Dispersion parameter for binomial family taken to be 1)

Null deviance: 138629 on 99999 degrees of freedom
Residual deviance: 138629 on 99998 degrees of freedom
AIC: 138633

Number of Fisher Scoring iterations: 3

Example

 Live Demo

x3<-sample(0:9,5000,replace=TRUE)
y3<-sample(0:1,5000,replace=TRUE) LogisticModel_3<-glm(y3~x3,family=binomial) summary(LogisticModel_3)

Output

Call:
glm(formula = y3 ~ x3, family = binomial)

Deviance Residuals:
Min 1Q Median 3Q Max
-1.171 -1.168 -1.166 1.186 1.189

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.026424 0.052975 -0.499 0.618
x3 0.001242 0.009895 0.126 0.900

(Dispersion parameter for binomial family taken to be 1)

Null deviance: 6930.9 on 4999 degrees of freedom
Residual deviance: 6930.9 on 4998 degrees of freedom
AIC: 6934.9

Number of Fisher Scoring iterations: 3

Example

 Live Demo

x4<-sample(1:100,5000,replace=TRUE)
y4<-sample(c(TRUE,FALSE),5000,replace=TRUE) LogisticModel_4<-glm(y4~x4,family=binomial)
summary(LogisticModel_4)

Output

Call:
glm(formula = y4 ~ x4, family = binomial)

Deviance Residuals:
Min 1Q Median 3Q Max
-1.183 -1.169 -1.155 1.185 1.200

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.0530051 0.0567387 -0.934 0.350
x4 0.0006682 0.0009722 0.687 0.492

(Dispersion parameter for binomial family taken to be 1)

Null deviance: 6931.0 on 4999 degrees of freedom
Residual deviance: 6930.5 on 4998 degrees of freedom
AIC: 6934.5

Number of Fisher Scoring iterations: 3
raja
Published on 16-Oct-2020 14:02:13

Advertisements