I am trying to do a logistic regression and adding an interaction term. However, I cant get it to work. I tried to do the same in STATA which was successful, but I would like to do it in R. If someone could contact me to help, I would appreciate it a lot. I am using the glm function and it has work up until I added the interaction term. I have a binary outcome, a continuous variable and a numeric interaction with 6 levels. I want to see how each of this 6 levels interact with the variable and how this effects the probability of the outcome. I have tried the making al the levels as individual factors, but R does only display the results for 5 of the individual factors and it is not the same result as in STATA.
This is the code I am running:
My_data$Numeric_variable<- factor(My_data$Numeric_v ariable,
levels = c(0, 2, 3, 4, 5, 6))
model <- glm(Outcome_binary ~ Continuous_variable* Numeric_variable,
family = binomial,
data = My_data[My_data$sex == "Men", ])
summary(model)
But the 0 level is not displayed in the results, and I think it is used as a reference when it should be a individual factor.
I have also created a code with dummy variables to force the 0 level to be seen as a individual factor, but then the 6 level gets only NA output and the other levels do not show the same P-value as in STATA.
Is there anyone who can help me woth this? I am at my wits end.
Br,
Jessica