0

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

Axeman
  • 32,068
  • 8
  • 81
  • 94
  • 1
    Please provide a simple reproducible example. – Axeman May 29 '22 at 17:52
  • 1
    If you set up your regression with `female` as a factor, `plot_model` will recognize that and plot correctly. Here's an actual reproducible example: `library(sjPlot); mtcars$am <- factor(mtcars$am); m <- glm(vs ~ am, mtcars, family = 'binomial'); plot_model(m, type = "pred", terms = "am")` – Axeman May 29 '22 at 17:57
  • @Axeman post as an answer? – Allan Cameron May 29 '22 at 19:58

1 Answers1

0

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")