vincentarelbundock / marginaleffects

R package to compute and plot predictions, slopes, marginal means, and comparisons (contrasts, risk ratios, odds, etc.) for over 100 classes of statistical and ML models. Conduct linear and non-linear hypothesis tests, or equivalence tests. Calculate uncertainty estimates using the delta method, bootstrapping, or simulation-based inference
https://marginaleffects.com
Other
462 stars 48 forks source link

marginaleffects "Argument 1 must have names" error #55

Closed jakeybob closed 3 years ago

jakeybob commented 3 years ago

Hi -- thought I'd give this interesting package a whirl, but ran into this issue.

minimal example

library(marginaleffects)

dat <- read.csv("https://vincentarelbundock.github.io/Rdatasets/csv/palmerpenguins/penguins.csv")
dat$large_penguin <- ifelse(dat$body_mass_g > median(dat$body_mass_g, na.rm = TRUE), 1, 0)
mod <- glm(large_penguin ~ bill_length_mm + flipper_length_mm + species, data = dat, family = binomial)
mfx <- marginaleffects(mod)

The last line gives the error:

Error: Argument 1 must have names.
Run `rlang::last_error()` to see where the error occurred.
In addition: Warning message:
In tmp$type <- predt : Coercing LHS to a list

Running rang::last_error() points to a dplyr::bind_rows() issue -- so I guess somewhere bind_rows is being extra strict about column names?

Other functions (typical, counterfactual) don't throw any errors.

My sessionInfo() is:

R version 4.0.1 (2020-06-06)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS  10.16

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] marginaleffects_0.0.0.9000

loaded via a namespace (and not attached):
 [1] rstudioapi_0.13   magrittr_2.0.1    MASS_7.3-51.6     margins_0.3.26   
 [5] insight_0.14.4    tidyselect_1.1.1  R6_2.5.1          rlang_0.4.11     
 [9] fansi_0.5.0       blob_1.2.1        dplyr_1.0.7       tools_4.0.1      
[13] data.table_1.13.0 checkmate_2.0.0   utf8_1.2.2        DBI_1.1.0        
[17] ellipsis_0.3.2    assertthat_0.2.1  tibble_3.1.4      lifecycle_1.0.0  
[21] prediction_0.3.14 crayon_1.4.1      purrr_0.3.4       vctrs_0.3.8      
[25] glue_1.4.2        compiler_4.0.1    pillar_1.6.2      generics_0.1.0   
[29] backports_1.2.1   pkgconfig_2.0.3  
vincentarelbundock commented 3 years ago

Wow, talk about a bad first impression! Thanks for reporting this!

Just to clarify, are you running the very latest GitHub version? If not, would you mind installing it and restarting your R session before trying again? (I very recently fixed a similar issue, and automated tests with similar examples are passing.)

If that doesn't work, I'll get on this when I'm back home in a couple hours.

Thanks again!

jakeybob commented 3 years ago

lol no worries -- no rush whatsoever 😀

Yep, latest GitHub version (v0.0.0.9000) installed via remotes::install_github("vincentarelbundock/marginaleffects"). Did an uninstall/reinstall just to be sure, and am getting the same error.

vincentarelbundock commented 3 years ago

Can you try to install the latest version of the emmeans package and try again?

I can replicate the bug, but only on one of the three computers I tried. When I updated emmeans on that computer, the bug seems to disappear.

This still feels like a mystery to me, but this seems like a low-cost thing to try, so might as well do it

jakeybob commented 3 years ago

Cool -- that worked! (I don't think I had any version of emmeans installed previously)