使用plot_model在边际效应图中删除二进制预测变量

发布于 2025-02-02 14:40:12 字数 677 浏览 4 评论 0原文

我正在尝试从logistic回归中产生边际效应图,我使用plot_model(sjplot)从可公开可用的调查数据中产生了边缘效应图。该情节的预测因子是二元(男性或女性),而响应变量是受访者是否投票给绿党。

这是代码:

logit3 %>%
  plot_model(
    type = "pred",
    terms = "female"
  ) +
  labs(
      x = "Gender",
      y = "Predicted probability of voting Green",
      title = "Predicted probability of voting Green by gender"
  )

这是图:

”在此处输入图像描述

该情节可产生良好,而不是两者之间的线性线。

我敢肯定,这有一个简单的答案,我只是愚蠢,但我似乎找不到任何在线上的东西。我也没有在这个论坛上发布太多,所以请告诉我是否需要提供其他任何内容。

谢谢

I'm trying to produce a marginal effects plot from a logistic regression I ran, using plot_model (sjPlot), from publicly available survey data. The predictor for the plot is binary (male or female) and the response variable is whether a respondent votes for a Green party.

This is the code:

logit3 %>%
  plot_model(
    type = "pred",
    terms = "female"
  ) +
  labs(
      x = "Gender",
      y = "Predicted probability of voting Green",
      title = "Predicted probability of voting Green by gender"
  )

And this is the plot:

enter image description here

The plot produces fine but, since this is a binary predictor, I would like it as two separate points (for male and female), with confidence intervals, rather than than a linear line between the two.

I'm sure this has an easy answer and that I'm just being stupid, but I can't seem to find anything online. I also haven't posted much on this forum, so please let me know if I need to provide anything else.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

呆萌少年 2025-02-09 14:40:12

抱歉,没有发布preprex。使用因子()指定预测变量解决了问题,谢谢!我以前曾尝试使用AS.Factor(),该factor()不起作用。

library(sjPlot) 
mtcars$am <- factor(mtcars$am)
m <- glm(vs ~ am, mtcars, family = 'binomial')
plot_model(m, type = "pred", terms = "am")

Sorry for not posting a reprex. Specifying the predictor using factor() solved the problem, thank you! I had previously tried using as.factor(), which didn't work.

library(sjPlot) 
mtcars$am <- factor(mtcars$am)
m <- glm(vs ~ am, mtcars, family = 'binomial')
plot_model(m, type = "pred", terms = "am")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文