1

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)

  • 2
    Look at the help for formula (`?formula`) to understand how to add interaction terms to a regression model using the `*` or `:` operators. – George Savva Apr 18 '23 at 08:27
  • Please provide enough code so others can better understand or reproduce the problem. – Community Apr 18 '23 at 15:17

1 Answers1

0

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)
Nick Glättli
  • 421
  • 1
  • 7