Trouble with setting reference category on logistic regression interaction variable

73 Views Asked by At

Among the variables in my dataset, I want to test the interaction between two variables- state category and purpose.

  • state.ctgry has two ordinal categories (NDA and Non NDA)
  • Purporse has 5 ordinal categories (Social, Economic, Cultural, Religious and Educational)

I want to keep NDA interactions as the reference category and get the non-NDA interaction results displayed in my log reg. In my plain purpose variable, I had defined "economic" as at the reference category. I am interested in the religious, social and cultural interactions with non NDA in my result

Despite defining the category, I still see the results for the NDA interaction with non-NDA interaction treated as the reference category (Image attached )

Regdcanceled$state.ctgry <- as.factor(Regdcanceled$state.ctgry)
Regdcanceled$Purpose <- as.factor(Regdcanceled$Purpose)

# set category 1 of variable A as reference
Regdcanceled$state.ctgry <- relevel(Regdcanceled$state.ctgry, ref = "NDA")

# set category X of variable B as reference
Regdcanceled$Purpose <- relevel(Regdcanceled$Purpose, ref = "Economic")

# create the interaction variable with NDA as the reference category
Regdcanceled$Int <- interaction(Regdcanceled$state.ctgry, Regdcanceled$Purpose, 
                                drop = TRUE)

# Fit logistic regression model with all levels of the interaction variable
log.fit4 <- glm(Cancelled ~ Purpose + state.ctgry + Total.amount + Int, 
                data = Regdcanceled, family = binomial)
summary(log.fit4)

1

There are 1 best solutions below

0
Nick Glättli On

You add interactions by using *. The reference category stems from the reference category of your interaction variables. Thus you would have to alter your code like this:

log.fit4 <- glm(Cancelled ~ Purpose*state.ctgry + Total.amount, 
                data = Regdcanceled, family = binomial)