Skip to content

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

@PrisonRodeo

Description

@PrisonRodeo

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions