bertcarnell / tornado

tornado plots for model sensitivity analysis
https://bertcarnell.github.io/tornado/
GNU General Public License v3.0
5 stars 0 forks source link

Variable importance for weighted models. #4

Closed shabbychef closed 1 year ago

shabbychef commented 1 year ago

First, thanks for the package.

When attempting to use importance with weighted glms, I get an error claiming an "Unexpected Internal error". A MWE:

glm1 <- glm(vs ~ disp, data = mtcars, family = binomial(link = "logit"), weights=mtcars$gear)
glm0 <- glm(vs ~ 1, data = mtcars, family = binomial(link = "logit"), weights=mtcars$gear)
imp <- tornado::importance(glm1, glm0)

Looking in the debugging trace, it seems the problem is in .create_tab_summary, where var_final has value c("disp", "(weights)"), whereas rownames(model_add1) = c("<none>", "disp").

bertcarnell commented 1 year ago

Thanks for the excellent bug report. I was able to reproduce the error you saw. I had not tested the methods with weighted models, so I'm glad you caught it.

bertcarnell commented 1 year ago

I committed a fix and associated tests (73c9fda4be6e0f44641f7d5df6ee0f2e4e272972). You can try the development version of the package now with devtools::install_github("bertcarnell/tornado") or wait for me to post to CRAN. It usually takes multiple days for me to go through the whole release process, so I recommend trying the development version.

bertcarnell commented 1 year ago

Submitted to CRAN today and tagged as v0.1.2