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

plot_predictions() with categorical variables and vcov = FALSE results in error message #897

Closed
huftis opened this issue Sep 4, 2023 · 3 comments

Comments

@huftis
Copy link
Contributor

huftis commented Sep 4, 2023

Using plot_prediction() with categorical variables and vcov = FALSE results in an error message (setting vcov = TRUE works fine):

library(marginaleffects)
mod = lm(Sepal.Length ~ Species, data = iris)
plot_predictions(mod, by = "Species", vcov = FALSE)
#> Error in `ggplot2::geom_point()`:
#> ! Problem while computing aesthetics.
#> ℹ Error occurred in the 1st layer.
#> Caused by error in `.data[[NULL]]`:
#> ! Must subset the data pronoun with a string, not `NULL`.

Tested using the latest Git version.

This is especially a problem for glmmTMB models, where plot_predictions() tells us that we should use vcov = FALSE (though it actually seems to work fine with vcov = vcov(mod) for linear Gaussian models like this one).

@vincentarelbundock
Copy link
Owner

Thanks a lot for the report. I think that the problem arises here, where we call .data[[v_color]] but v_color is NULL:

https://github.com/vincentarelbundock/marginaleffects/blob/main/R/plot_build.R#L79

It's probably just a question of inserting more if/else statements or use a do.call() to ensure that we don't feed useless arguments to ggplot::aes(). The problem will probably arise in the next code block as well with continuous x-axis, but it should be a pretty easy fix. (But start of semester is upon us at my university, so I'll do my best...)

@vincentarelbundock
Copy link
Owner

Half-baked PR: #898

@vincentarelbundock
Copy link
Owner

Thanks again for the report. Should be fixed on Github:

library(marginaleffects)
mod = lm(Sepal.Length ~ Species, data = iris)
plot_predictions(mod, by = "Species", vcov = FALSE)

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