Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Label mismatch between margins() and plot(margins())? #185

Open
1 of 3 tasks
PrisonRodeo opened this issue Apr 5, 2022 · 1 comment
Open
1 of 3 tasks

Label mismatch between margins() and plot(margins())? #185

PrisonRodeo opened this issue Apr 5, 2022 · 1 comment

Comments

@PrisonRodeo
Copy link

Hi -

I'm seeing mismatched labels between margins(foo) and plot(margins(foo)), in this case for a logit (no interactions). I hope I'm not doing something wrong. Reproduceable minimal example below. The issue seems to arise when the variables in the fitted model appear in a different order than they do in the data frame.

Thanks,

-- CZ ([email protected], @PrisonRodeo)

====================================
Please specify whether your issue is about:

  • a possible bug
  • a question about package functionality
  • a suggested code or documentation change, improvement to the code, or feature request

Code!

library("margins")
set.seed(7222009)
df<-data.frame(X1=rbinom(400,1,0.5),
               X2=runif(400,0,1),
               X3=rbinom(400,1,0.2))
df$Y<-rbinom(400,1,plogis(1*df$X1+3*df$X2-3*df$X3))
hat<-glm(Y~X1+X2+X3,df,family="binomial")
margins(hat)
plot(margins(hat))  # <- works OK
hat2<-glm(Y~X3+X2+X1,df,family="binomial")
margins(hat2)
plot(margins(hat2)) # <- mismatches labels to AMEs

## session info for your system
sessionInfo()
@jsavinc
Copy link

jsavinc commented Mar 30, 2023

I've encountered the same, it appears that the labels are in the order of the fitted mode, but the plots are in alphabetical order of variable names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants