Agnes Flack
Agnes Flack

Reputation: 31

Odds ratio and 95% CI for interaction in logistic model in R

I am running a logistic model with an interaction between a dichotomous and a continuous variable:

aidslogit<-glm(cd4~ AGE+ANTIRET+AGE*ANTIRET, data = aidsdata, family = "binomial")
summary(aidslogit, digits=3)

Deviance Residuals: 
   Min      1Q  Median      3Q     Max  
-1.870  -1.190   0.771   1.056   1.586  

Coefficients:
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)    -0.599565   0.313241  -1.914   0.0556 .  
AGE            -0.008340   0.008849  -0.942   0.3459    
ANTIRET         1.308591   0.198031   6.608  3.9e-11 ***
AGE:ANTIRET    -0.013547   0.005507  -2.460   0.0139 *  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 9832.8  on 7264  degrees of freedom
Residual deviance: 9434.9  on 7261  degrees of freedom
  (654 observations deleted due to missingness)
AIC: 9442.9

Number of Fisher Scoring iterations: 4

What I would like to do is calculate the OR and 95% CI for antiretroviral use at different ages, i.e, at age 20, 30, and 40. I guess I could output the covariances and do it by hand, but it seems like there must be a way to do it automatically.

For comparison:

In SAS it would look like this:

proc logistic data=aidsdata descending;
model cd4=antiret age antiret*age;
oddsratio antiret /at (age=20 30 40);
run;

Upvotes: 3

Views: 2205

Answers (1)

eipi10
eipi10

Reputation: 93811

For a regression without interactions, the odds ratio for each coefficient is exp(coef(aidslogit)). These are the odds ratios for a one-unit change in a given variable.

But with an interaction, you need to include both the main effect and the interaction. In this case, AGE is the second coefficient and AGE:ANTIRET is the fourth coefficient, so:

# Odds ratio for a one-unit change in AGE when ANTIRET=0
OR = exp(coef(aidslogit)[2])

# Odds ratio for a one-unit change in AGE when ANTIRET=1
OR = exp(coef(aidslogit)[2] + coef(aidslogit)[4])

To calculate the odds ratio for other AGE differences, multiply the coefficients by that amount. For example, to get the odds ratio for a 10-unit change in AGE:

# Odds ratio for a 10-unit change in AGE when ANTIRET=0
OR = exp(10 * coef(aidslogit)[2])

# Odds ratio for a 10-unit change in AGE when ANTIRET=1
OR = exp(10 * (coef(aidslogit)[2] + coef(aidslogit)[4]))

Upvotes: 1

Related Questions