- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

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

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

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

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

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

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

- Related Articles
- How to set the coefficient of one variable to 1 for logistic regression model in R?
- How to extract p-values for intercept and independent variables of a general linear model in R?
- How to extract the model equation from model object in R?
- How to extract correlation coefficient value from correlation test in R?
- How to add a regression line to a plot in base R if intercept and slope are given?
- How to extract the residuals and predicted values from linear model in R?
- How to create a scatterplot with regression line using ggplot2 with 0 intercept and slope equals to 1 in R?
- How to display regression intercept using model in a plot created by ggplot2 in R?
- How to deal with glm.fit error “NA/NaN/Inf” for logistic regression model in R?
- How to display regression slope using model in a plot created by ggplot2 in R?
- How to extract the regression coefficients, standard error of coefficients, t scores, and p-values from a regression model in R?
- How to extract p-value and R-squared from a linear regression in R?
- How to extract statistical summary from boxplot in R?
- How to extract characters from a string in R?
- How to extract the frequencies from a histogram in R?

Advertisements