1

It is my first time doing logistic regressions and I am currently trying to teach myself how to find the odds ratio. I got my coefficients from r as shown below.

    (Intercept)   totalmins 
       0.2239254    1.2424020 

To exponentiate the regression coefficient I did the following:

exp1.242/exp1.242+1   = 0.77

Really not sure if this is the correct process or not.

Any advice on how I would go about calculating odds ratio would be greatly appreciated

detection- 1/0 data if animal was detected at site
total mins- time animal spent at site

here's the output

    glm(formula = detection ~ totalmins, family = binomial(link = "logit"), 
    data = data)

Deviance Residuals: 
     Min        1Q    Median        3Q       Max  
-2.81040  -0.63571   0.00972   0.37355   1.16771  

Coefficients:
             Estimate Std. Error z value Pr(>|z|)  
(Intercept)  -1.49644    0.81818  -1.829   0.0674 .
totalmins  0.21705    0.08565   2.534   0.0113 
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 41.194  on 33  degrees of freedom
Residual deviance: 21.831  on 32  degrees of freedom
  (1 observation deleted due to missingness)
AIC: 25.831

Number of Fisher Scoring iterations: 8
louiseo
  • 11
  • 1
  • 3
  • 3
    If you have an example data set it might be easier to help. Let's say you build a logistic regression model called "model1". To obtain the odds ratios and 95% confidence intervals for your model you could type: exp(cbind(OR = coef(model1), confint(model1, level = 0.95))) – user3585829 Jan 07 '18 at 18:59
  • I will add the data set to the question now, cheers – louiseo Jan 07 '18 at 19:02
  • The above code should still work for you to get your odds ratios. Did you try it? – user3585829 Jan 07 '18 at 19:08
  • 1
    Some more useful info here: https://stats.stackexchange.com/questions/8661/logistic-regression-in-r-odds-ratio – AntoniosK Jan 07 '18 at 19:31

1 Answers1

1

This model evaluates the log odds of detecting an animal at the site based on the time in minutes that the animal spent on the site. The model output indicates:

log odds(animal detected | time on site) = -1.49644 + 0.21705 * minutes animal on site

To convert to odds ratios, we exponentiate the coefficients:

odds(animal detected) = exp(-1.49644) * exp(0.21705 * minutes animal on site) 

Therefore, the odds and probability of detection if the animal spends 0 minutes on site is e(-1.49644) or 0.2239. The odds ratio of detection if an animal is on site for X minutes is calculated as follows. We'll model odds ratios for minutes 0 through 10, and calculate the associated probability of detection.

# odds of detection if animal on site for X minutes
coef_df <- data.frame(intercept=rep(-1.49644,11),
                   slopeMinutes=rep(0.21705,11),
                   minutesOnSite=0:10)
coef_df$minuteValue <- coef_df$minutesOnSite * coef_df$slopeMinutes
coef_df$intercept_exp <- exp(coef_df$intercept)
coef_df$slope_exp <- exp(coef_df$minuteValue)
coef_df$odds <- coef_df$intercept_exp * coef_df$slope_exp
coef_df$probability <- coef_df$odds / (1 + coef_df$odds)

...and the output:

> coef_df[,c(3:4,6:8)]
   minutesOnSite intercept_exp slope_exp   odds probability
1              0        0.2239     1.000 0.2239      0.1830
2              1        0.2239     1.242 0.2782      0.2177
3              2        0.2239     1.544 0.3456      0.2569
4              3        0.2239     1.918 0.4294      0.3004
5              4        0.2239     2.383 0.5335      0.3479
6              5        0.2239     2.960 0.6629      0.3986
7              6        0.2239     3.678 0.8235      0.4516
8              7        0.2239     4.569 1.0232      0.5057
9              8        0.2239     5.677 1.2712      0.5597
10             9        0.2239     7.053 1.5793      0.6123
11            10        0.2239     8.763 1.9622      0.6624
>

See also How to get probability from GLM output for another example using space shuttle autolander data from the MASS package.

Len Greski
  • 10,505
  • 2
  • 22
  • 33