1

I'm running three logistic models with all categorical variables, some of them binary but most of them with 3 or more factors as values, the first would be the base model, the second have 2 interaction terms and the third have a three-way interaction.

model1 <- glm(y ~ x + z + a + b + c + d, data=df,
              family=binomial(link="logit"), na.action=na.omit)

model2 <- glm(y ~ x*d + z*d + a*d + b*d + c*d, data=df,
              family=binomial(link="logit"), na.action=na.omit)

model3 <- glm(y ~ x*d + z*d + a*d + b*d + c*d + x*z*d, data=df, 
              family=binomial(link="logit"), na.action=na.omit)

So I wanted to calculate the marginal effects of the three models using margins, it just works fine in the first case, but in the second and third model (the ones with interactions) no coefficient is reported for the interactions terms, just for the same variables reported in the first model.

library(margins)

mod0 <- margins(model1)
mod1 <- margins(model2)
mod2 <- margins(model3)


library(modelsummary)

modelsummary(list(mod0, mod1, mod3))

Output: enter image description here

As you can see, there is no interactions in the marginal effects output.

I have reviewed the documentation, thought at first I should use the at argument and that would solve it, but I had some troubles interpretting the output, not all coefficients match the possitive or negative sign of the base model with interactions and it also lacks p-values and confidence intervals, also thought about dydx but wasn't sure how to explicit all the interactions I need and what to do with the three-way interaction.

jay.sf
  • 60,139
  • 8
  • 53
  • 110
esteban
  • 102
  • 8

1 Answers1

0

The margins package defines a "marginal effect" as the slope of the outcome model with respect to one of the predictors. In other words, We are taking the derivative of y with respect to x, then with respect to z, then with respect to the other variables. So each variable has a marginal effect, but the interaction terms do not have marginal effects. I recommend you read the good vignette for margins:

https://cran.r-project.org/web/packages/margins/vignettes/Introduction.html

Alternatively, you may want to look at the vignette for marginaleffects, a more recent package which aims to be a "successor" to margins (disclaimer: I am the author):

https://vincentarelbundock.github.io/marginaleffects/articles/marginaleffects.html

Vincent
  • 15,809
  • 7
  • 37
  • 39