0

I'm using the "margins" package to obtain the average marginal effects of a logistic regression. When I try to plot these marginal effects, the results from the plot are different from the results I obtain from the "margins" function. I have no idea why this is happening D:

The formula I'm using for the regression is the following:

mod_7 <- glm(ID_izq_WV7 ~ sex_7 + edad_7 + edusup_7 + ingresos_7 + indiv_eco_7 +
             interv_gob_7 + lib_ind_WV7 + prefdem_7 + postmat_WV7 + confgob_WV7 +
             agnostic_7, family = binomial)

Then, I'm using the "margins" function to obtain the average marginal effects:

summary(margins(mod_7, type = "link"))

From this code, I obtain the following results: Results: Average Marginal Effects

Then, I create a plot for the same regression formula, using this code:

par(mar = c(8, 5, 4, 3))
plot(margins(mod_7), las = 2)

From this code, I get the following plot: Plot: Average Marginal Effects

The results shown in the plot do not match the results I get from "summary.margins". Does anybody know why this is happening? Thanks so much for your help!

siltelmar
  • 13
  • 3
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. – MrFlick Sep 02 '20 at 02:57

1 Answers1

1

I still don't know why this was happening, but I realized that the values shown in the plot were in the same order as the values shown in the table. The names of the variables were just scrambled in a different order. To solve this, I just labeled the variables in the correct order:

plot(margins_mod_europa_4,
 labels = c("Secularismo", "Confianza en instituciones gubernamentales",
           "Edad", "Educación Superior", "Individualismo económico",
           "Ingresos altos", "Intervención gubernamental", 
           "Valoración de libertades individuales", "Valores postmaterialistas",
           "Preferencia por la democracia", "Sexo = Mujer"),
 las = 2)
siltelmar
  • 13
  • 3