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

`at` and factors #116

Open
vincentarelbundock opened this Issue Feb 18, 2019 · 3 comments

Comments

Projects
None yet
2 participants
@vincentarelbundock
Copy link
Contributor

vincentarelbundock commented Feb 18, 2019

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

What is the proper way to specify factor values in the at list?

library(margins)
dat <- mtcars
dat$cyl <- as.factor(dat$cyl)
mod <- lm(mpg ~ cyl + hp, dat)
margins(mod, at = list(hp = 100, cyl = '6'))

@leeper leeper added the enhancement label Feb 20, 2019

@leeper

This comment has been minimized.

Copy link
Owner

leeper commented Feb 20, 2019

Yea, this has been a problem at times. I guess it needs to be character. We should add:

  • Documentation of correct behavior
  • Some tests (incl. when levels are numeric values as character, as in the mtcars example)
@vincentarelbundock

This comment has been minimized.

Copy link
Contributor Author

vincentarelbundock commented Feb 20, 2019

Good to know. I'll try to take a look at this if/when I ever complete the plotting project.

Would you be interested in adding a bunch of input checks with something like this: https://github.com/mllg/checkmate

@leeper

This comment has been minimized.

Copy link
Owner

leeper commented Apr 10, 2019

The levels are also being written as numbers rather than their labels:

m <- lm(Sepal.Length ~ Sepal.Width * Species, data = iris)
> margins(m, iris, at = list(Species = c("setosa", "versicolor")))
Average marginal effects at specified values
lm(formula = Sepal.Length ~ Sepal.Width * Species, data = iris)

 at(Species) Sepal.Width Speciesversicolor
      setosa      0.6905             1.435
  versicolor      0.8651             1.435
> summary(.Last.value)
            factor Species    AME     SE       z      p  lower  upper
       Sepal.Width  1.0000 0.6905 0.1657  4.1664 0.0000 0.3657 1.0153
       Sepal.Width  2.0000 0.8651 0.2002  4.3212 0.0000 0.4727 1.2575
 Speciesversicolor  1.0000 1.4345 0.1217 11.7846 0.0000 1.1959 1.6731
 Speciesversicolor  2.0000 1.4345 0.1217 11.7846 0.0000 1.1959 1.6731

which is unintuitive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.