Open nowo1978 opened 4 years ago
I believe that this is due to 2 problems:
cplot_extract.default
where the function calls an undefined object called "dat" when it should be "data".prediction::mean_or_mode
does not have a method to handle logical data.To illustrate, I added a logical method to a branch of my prediction
fork, and I fixed the bug in my marginsplot
package. marginsplot
was initially intended to be a ggplot2
replacement for margins
' plotting functions. Unfortunately, it looks like the maintainer of margins
no longer has time to look at contributions, so it sat in a PR for a year. I spun it off as a separate package until an opportunity for merging comes up.
You can try my fix like this:
remotes::install_github('vincentarelbundock/marginsplot')
remotes::install_github('vincentarelbundock/prediction@mean_mode_logical')
## load package
library("margins")
library("marginsplot")
cars <- mtcars
cars$am <- as.logical(cars$am)
mod <- lm(hp ~ disp + am, data = cars)
cplot(mod, x = "disp")
Created on 2020-05-29 by the reprex package (v0.3.0)
Please specify whether your issue is about:
Hi! I am using margins to estimate marginal effects and cplot() to plot predicted probabilities. But if there is a logical variable "x" in my model cplot() returns the error:
Here is a minimal code example:
It works okay if I use the same command with the "what" argument:
Which is why I think it is a bug rather than an error on my side. It also works fine if I use the original numeric variable or if it is defined as a factor.
Thanks for your work! Klaus
Session info and traceback: