Not sure if the question is suitable to ask here.

Calculating odds ratio with interaction term in R using exp() function:

For example, If I take exponent of the coefficients which would give me odds ratio. It works fine for the predictors with no interaction. However, my question is if the interaction term is included and we take exp() function on the coefficient, is the odds ratio for the interaction term (y:z) correct?


x <- sample( c(0,1), 20, replace=TRUE, prob=c(0.1, 0.52))
y <- sample( c(0,1), 20, replace=TRUE, prob=c(0.3, 0.52))
z <- sample( c(0,1), 20, replace=TRUE, prob=c(0.15, 0.04))




exp(cbind(Odds_and_OR=coef(model), confint(model)))

glm(formula = x ~ y * z, family = binomial(link = "logit"), data = df)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-1.8930   0.4530   0.6360   0.6681   0.9005  

             Estimate Std. Error z value Pr(>|z|)
(Intercept)    1.6094     1.0954   1.469    0.142
y             -0.2231     1.3509  -0.165    0.869
z             -0.9163     1.6432  -0.558    0.577
y:z           17.0961  3956.1807   0.004    0.997

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 20.016  on 19  degrees of freedom
Residual deviance: 19.234  on 16  degrees of freedom
AIC: 27.234

Number of Fisher Scoring iterations: 16

> exp(cbind(Odds_and_OR=coef(model), confint(model)))
Waiting for profiling to be done...
            Odds_and_OR         2.5 %   97.5 %
(Intercept)         5.0  8.063919e-01 95.79539
y                   0.8  3.208724e-02 10.71957
z                   0.4  1.106609e-02 13.61758
y:z          26590507.7 6.838652e-265       NA
  • 1
    $\begingroup$ A standard error as big as 4000 and p-value of nearly 1 hint that there could be separation problem. Try plot the outcome by y and z and look for empty cells, and consider getting more sample or use exact estimation. $\endgroup$ Jul 28, 2016 at 19:28
  • $\begingroup$ Thanks for the response. I am just looking to see if it is technically correct to calculate odds ratio for interaction term using exp() function on the interaction coefficient. $\endgroup$
    – deepseas
    Jul 28, 2016 at 19:32
  • 1
    $\begingroup$ It is technically correct. But the interpretation is not as straightforward: if neither z nor y is zero, then you'd always need to incorporate the interaction's coefficient in the estimation. So, given y = y' and y' is not 0, then the OR for z will be exp(-0.9163 + y' * 17.0961). For each unique value in y, you'll have a different OR for z, and vice versa. The OR of exp(17.0961) itself alone is not very useful. $\endgroup$ Jul 28, 2016 at 19:36
  • $\begingroup$ Thanks a lot. It is helpful. I am still little confused. This makes sense but I am not able to grasp it completely yet. Does R have any function to do this already? If not, I will have to figure it out. $\endgroup$
    – deepseas
    Jul 28, 2016 at 19:48
  • 1
    $\begingroup$ Just use model$coef to extract the coefficient and do the conversion. You have only two binary variables so it's the OR for y when z = 1 and z = 0; and the OR for z when y = 1 and y = 0. $\endgroup$ Jul 28, 2016 at 20:02

1 Answer 1


I think the way I would approach this (given your specific example) is to describe my results as follows:

  • When y is 1 and z is 0, the odds ratio (including interaction) is exp(-0.2231)
  • When y is 0 and z is 1, the odds ratio (including interaction) is exp(-0.9136)
  • When y = z = 1, the odds ratio (including interation) is exp(-0.2231-0.9136+17.0961)

I guess the question is how do you want to interpret the model and this is how I would choose to interpret such a model.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.