0
$\begingroup$

I spent so many hours trying to create bargraph for lmer in R but I cant find a way to get each condition group mean to vary. I want to plot the following model

  ratings_long <- lmerTest::lmer(value ~ rating + (1+rating | group) + (1 | responseid), data=mydatalong, REML=F) #control for diff btw
  summary(ratings_long) 
  coef(ratings_long)

the code I used for creating the plot

  if (require(lme4, quietly=TRUE)) {
    ratings_long <- lmerTest::lmer(value ~ rating + (1 | group) + (1 | responseid), data=mydatalong, REML=F)
    reghelper::graph_model(ratings_long, y=value, x=rating, lines=group, bargraph=TRUE)
  }
    
  reghelper::graph_model(ratings_long, value, group, lines=rating, bargraph=TRUE) #doesnt have random effects 

The plot looks like this enter image description here

But I want something like this enter image description here

I know it’s supposed to vary because I ran the lmer model and it says both intercept and slopes significantly differ, which means they are not constant. enter image description here

Any one aware of what is the problem and solution? The only thing that came up for me was from this site From https://rdrr.io/cran/reghelper/man/graph_model.html (here it says “Details

If there are additional covariates in the model other than what is indicated to be graphed by the function, these variables will be plotted at their respective means. In the case of a categorical covariate, the results will be averaged across all its levels.”) , but this doesn't seem to work as well. Thanks in advance.

$\endgroup$
3
  • $\begingroup$ Questions of the type "How to do something in R" (or any other software) are off topic. And this function seems to plot the fixed effects while not the random effects. That is, it plots the value ~ ratings part of the model, which obviously doesn't vary by group. $\endgroup$
    – dipetkov
    Commented Aug 18, 2022 at 4:46
  • 2
    $\begingroup$ It looks like this question is actually on-topic, because the key aspect is the difference between fixed and random effects, which is statistical (and I would not expect random R users at StackOverflow to be able to answer). So: can you please edit your post to create a Minimal Working Example? $\endgroup$ Commented Aug 18, 2022 at 7:12
  • $\begingroup$ Thanks for commenting, I think I kind of got the reason for my mistake ( random vs fixed). can you tell me which line I should modify to change from fixed to random effect? If that fails, I will try creating the Minimal reproducible example, although Im not sure if I can do it well as Im a newbie. Thanks in advance. $\endgroup$
    – numpynp
    Commented Aug 18, 2022 at 23:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.