Reputation: 391
I'm using fixed effects logistic regression in R, using the glm
function. I've done some reading about interpreting interaction terms in generalized linear models. When using the log odds, the model is linear and the interaction term(s) can be interpreted in the same way as OLS regression. When the coefficients are exponentiated into odds ratios, this is no longer the case. Since my audience are more familiar with odds ratios, i'd like to report my results using that metric.
Is there a pre-cooked way of calculating interaction terms as odds ratios using R? If, not, can anyone walk me through how this should be done?
Edit 1: I'm providing a reproducible example below.
set.seed(1234)
dat <- data.frame(
Y = factor(round(runif(60))),
x1 = rnorm(60, 10, 3),
sex = sample(c("male", "female"), size = 60, prob = c(.4, .6), replace = TRUE),
population = sample(c("France", "Kenya", "Thailand"), size = 60, prob = c(.3, .45, .25), replace = TRUE)
)
fm1 <- glm(Y ~ x1 + sex * population, family = binomial(link = "logit"), data = dat)
summary(fm1)
# odds ratios
exp(coef(fm1))
Edit 2: additional clarification.
The motivation behind my question comes from the following explanation of logistic regression interactions from the UCLA statistics site:
http://www.ats.ucla.edu/stat/stata/seminars/interaction_sem/interaction_sem.htm
My understanding, from reading this, is that the interpretation of interaction terms that have been transformed into either odds ratios or probabilities is not the same as for the same terms in log odds units. I guess I'm trying to understand if I just need to change my interpretation of the interaction term when converting to odds ratios, or whether I need to do some calculation in addition to the exponentiation?
Upvotes: 0
Views: 6900
Reputation: 263471
If you are talking about the interpretation of the glm()
output and remain on the log-odds scale than it is exactly analogous to how you would interpret the output from lm()
. In both cases it is better to talk about predictions rather than trying to separately interpret the coefficients. When you ask for a "pre-cooked way of calculating interaction terms as odds ratios using R", it is not clear what you are really requesting. Do you know of such a "pre-cooked way of calculating interaction terms" for lm()
model output?
The UCLA tutorial is saying that you should ask for a method of looking at probabilities and in R regressions functions the answer is "predict":
?predict.glm
This is the set of sum of the linear predictors, i.e the sum of the Intercept and the coefficients for persons with the unique combinations of categorical features at the sample mean for x1 in this dataset:
> data.frame( expand.grid(sex=unique(dat$sex), population=unique(dat$population)), x1=mean(dat$x1))
sex population x1
1 female Kenya 9.380473
2 male Kenya 9.380473
3 female France 9.380473
4 male France 9.380473
5 female Thailand 9.380473
6 male Thailand 9.380473
> predict( fm1, newdata=data.frame( expand.grid(sex=unique(dat$sex), population=unique(dat$population)), x1=mean(dat$x1)))
1 2 3 4 5 6
-0.1548962 0.4757249 -0.5963092 -0.3471242 0.8477717 0.2029501
Those could be exponentiated if odds ratios are desired, but you should then know what is in the denominator for the odds ratios. And these are the probabilities (obtained with type='response'):
> predict( fm1, newdata=data.frame( expand.grid(sex=unique(dat$sex), population=unique(dat$population)), x1=mean(dat$x1)), type="response")
1 2 3 4 5 6
0.4613532 0.6167379 0.3551885 0.4140800 0.7000995 0.5505641
Upvotes: 2