-2
df <- data.frame(C=c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8), 
                 Y=c("F","F","F","F","F","F","F","F","F","F","F","F","F","F","F","F",
                     "M","M","M","M","M","M","M","M","M","M","M","M","M","M","M","M"), 
                 B=c(1,1,3,2,5,3,6,7,2,1,2,4,3,2,3,6,8,6,5,8,5,7,4,8,7,8,2,9,7,7,6,7))

m <- glmer(Y ~ B + (1|C), data=df, family=binomial())

plot_model(m)

I was hoping to obtain a similar probability curve plot as shown here.

How can I achieve that?

M--
  • 25,431
  • 8
  • 61
  • 93
locus
  • 387
  • 2
  • 9
  • Which probability curve plot? – cardinal40 Sep 03 '19 at 21:47
  • 1
    I didn't downvote, but I believe others are doing so because you're not showing much "research effort". It's good that you've included some data and model-fitting code, but it would be even better if you showed an attempt to solve the problem yourself - at present it reads a bit like "please write the code for me" – Ben Bolker Sep 03 '19 at 22:36
  • 1
    does https://strengejacke.github.io/sjPlot/articles/plot_marginal_effects.html help? – Ben Bolker Sep 03 '19 at 22:39
  • @locus Did you read that webpage? Not sure why the answer is not just: `sjp.glmer(m, type = "fe.pc")` – IRTFM Sep 03 '19 at 22:55
  • @BenBolker: I played around with the plot_model arguments but I could never get the desired result. The function sjp.glmer has been replaced by plot_model and I couldn't figure out what the equivalent options were. The link you sent is helpful. – locus Sep 03 '19 at 23:16
  • 1
    @42- because sjp.glmer function doesn't exist anymore - it was replaced by plot_model and the arguments are different. – locus Sep 03 '19 at 23:18
  • 1
    Yes, BenBolker's link is going to be most helpful since `sjPlot` has changed a lot since the original blogpost you linked to. I think you want something like `plot_model(m, type = "pred", terms = "B")`, but please edit the question to be more specific if that's not it. – Marius Sep 03 '19 at 23:27
  • I suppose the fact that the page is dated "18. November 2014" might give you pause" about the possibility that the sjPlot package might have changed in the last 5 years. Both the prior and current versions of that package do not have a `sjp.glmer` function. – IRTFM Sep 03 '19 at 23:31

1 Answers1

2

There's only one fixed effect covariate ($B), so after reading the help page for plot_model, and comparing to the out-of-date material you offered. this seems to deliver the requested plot:

> plot_model(m, type = "pred")
$B

enter image description here

After stumbling around trying to get the most current version of sjPlot and all of the current versions of its dependencies from Github, and then reading the current help page and testing out the code above, I now see that @Marius already posted this. Oh well. If he wants to an answer, I will delete.

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • the last part of your answer looks more like a comment than part of an answer ... – Ben Bolker Sep 04 '19 at 16:04
  • It was in part a warning that installing sjPlot was somewhat a hassle with quite a few dependencies that did not get installed on the first second or even third go rounds, as well as a suggestion that Marius might want to post his own approach, since he might well have more experience with this package than do I. – IRTFM Sep 04 '19 at 20:02