0

I am currently following this guide: https://mran.microsoft.com/snapshot/2020-03-10/web/packages/sjPlot/vignettes/plot_model_estimates.html

I copied and pasted the following for the guide:

library(sjPlot)
library(sjlabelled)
library(sjmisc)
library(ggplot2)

data(efc)
theme_set(theme_sjplot())

# create binary response
y <- ifelse(efc$neg_c_7 < median(na.omit(efc$neg_c_7)), 0, 1)

# create data frame for fitting model
df <- data.frame(
  y = to_factor(y),
  sex = to_factor(efc$c161sex),
  dep = to_factor(efc$e42dep),
  barthel = efc$barthtot,
  education = to_factor(efc$c172code)
)

# set variable label for response
set_label(df$y) <- "High Negative Impact"

# fit model
m1 <- glm(y ~., data = df, family = binomial(link = "logit"))

I added two models:

# added
m2 <- glm(y ~ sex + dep, data = df, family = binomial(link = "logit"))

m3 <- glm(y ~ sex + dep + barthel, data = df, family = binomial(link = "logit"))

I wanted the plot to only show certain coefficients:

plot_models(m1, m2, m3,
            terms = c("sex", "dep"))

I got this error:

Error in (show.zeroinf && minfo$is_zero_inflated) || minfo$is_dispersion : 
  invalid 'y' type in 'x || y'
In addition: Warning message:
Could not access model information. 

I wanted to facet the different plots:

plot_models(m1, m2, m3,
            facet_grid = TRUE)

And I got this error:

Error in (show.zeroinf && minfo$is_zero_inflated) || minfo$is_dispersion : 
  invalid 'y' type in 'x || y'
In addition: Warning message:
Could not access model information. 

Could anyone provide me some insight into what could be going on here? Thanks!

hy9fesh
  • 589
  • 2
  • 15

1 Answers1

0

You are probably confusing plot_model and plot_models function from sjPlot. When you use an unknown argument, it will return the error. So you have to make sure you use the right arguments. The facet_grid argument doesn't exists for example, you could check this by ?plot_models. Here some reproducible code:

library(sjPlot)
library(sjlabelled)
library(sjmisc)
library(ggplot2)

all.models <- list()
all.models[[1]] <- m1
all.models[[2]] <- m2
all.models[[3]] <- m3

plot_models(all.models,
            rm.terms = c("barthel", "education"))

Created on 2023-03-14 with reprex v2.0.2

Quinten
  • 35,235
  • 5
  • 20
  • 53