# In R, Odds ratio calculation using function exp(coef) is correct or not for the interaction term?

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?

Thanks

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))

df<-data.frame(cbind(x,y,z))

summary(model)

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

###################################################
output:
Call:
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

Coefficients:
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

• 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. – Penguin_Knight Jul 28 '16 at 19:28
• 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. – deepseas Jul 28 '16 at 19:32
• 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. – Penguin_Knight Jul 28 '16 at 19:36
• 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. – deepseas Jul 28 '16 at 19:48
• 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. – Penguin_Knight Jul 28 '16 at 20:02