我目前遵循此指南:https://mran.microsoft.com/snapshot/2020-03-10/web/packages/sjPlot/vignettes/plot_model_estimates.html
我为指南复制并粘贴了以下内容:
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"))
我添加了两个模型:
# added
m2 <- glm(y ~ sex + dep, data = df, family = binomial(link = "logit"))
m3 <- glm(y ~ sex + dep + barthel, data = df, family = binomial(link = "logit"))
我希望图只显示某些系数:
plot_models(m1, m2, m3,
terms = c("sex", "dep"))
我得到这个错误:
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.
我想把不同的情节分面:
plot_models(m1, m2, m3,
facet_grid = TRUE)
我得到了这个错误:
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.
有谁能给我提供一些关于这里可能发生的事情的见解吗?谢谢!
1条答案
按热度按时间6pp0gazn1#
你可能把
plot_model
和plot_models
函数和sjPlot
弄混了。当你使用未知参数时,它会返回错误。所以你必须确保你使用了正确的参数。例如,facet_grid
参数不存在,你可以通过?plot_models
来检查。下面是一些可复制的代码:创建于2023年3月14日,使用reprex v2.0.2