mango123
mango123

Reputation: 39

Can plot_models be used with type="pred"?

I tried to use the following code to produce figures depicting the predicted values for specific variables. However, I get the error:

Error in (show.zeroinf && minfo$is_zero_inflated) || minfo$is_dispersion : 
  invalid 'y' type in 'x || y'

Can someone explain me this error message? Is it not possible to specific the type="pred with plot_models? With only model (plot_model) it works...

Thanks!

data(efc)

fit1 <- lm(barthtot ~ c160age + c12hour + c161sex + c172code, data = efc)
fit2 <- lm(neg_c_7 ~ c160age + c12hour + c161sex + c172code, data = efc)
fit3 <- lm(tot_sc_e ~ c160age + c12hour + c161sex + c172code, data = efc)

plot_models(
  fit1, fit2, fit3,
  type="pred",
  rm.terms = c(
    "c12hour", "c161sex", "c172code"
  )
)

Upvotes: 0

Views: 144

Answers (1)

Quinten
Quinten

Reputation: 41469

You could use plot_model with type = "pred" instead of plot_models. Probably you want to have your features like factors like this (Here is only the output of first model):

library(sjPlot)
#> #refugeeswelcome
library(sjmisc)
data(efc)

efc <- to_factor(efc, c161sex, e42dep, c172code)

fit1 <- lm(barthtot ~ c160age + c12hour + c161sex + c172code, data = efc)
fit2 <- lm(neg_c_7 ~ c160age + c12hour + c161sex + c172code, data = efc)
fit3 <- lm(tot_sc_e ~ c160age + c12hour + c161sex + c172code, data = efc)

lapply(list(fit1, fit2, fit3), \(x) plot_model(x, type = "pred"))
#> [[1]]
#> [[1]]$c160age

#> 
#> [[1]]$c12hour

#> 
#> [[1]]$c161sex

#> 
#> [[1]]$c172code

Created on 2023-02-12 with reprex v2.0.2

Upvotes: 0

Related Questions