2

I have a model with several fixed and random variables.
Here is the code:

model1<-lmer(dep ~ pred + sex + age + heat + (1|ID) + (1|year),data=data)

So, by running a ggplot I get this graph

ggplot dep & pred

However, the ggplot, and the geom_smooth() function will only plot the slope and confidence intervals calculated between dep and pred.
But it will not take into account the other factors, including random terms

Indeed, with the code
Effect("pred",model1)

I get a different and probably real slope

pred effect

        600        1000        2000        3000        4000 
-0.14747707 -0.10876855 -0.01199725  0.08477404  0.18154534

Is there a way to plot the slope and the real confidence interval area of a lmer?

UPDATE: I was able to get a graph with the good coordinates and confidence intervals using plot(effect("pred",model1)) And this is how looks like:

new plot right coordinates

But how can I now make this graph look decent? Or how can I plot this in ggplot or similar so that I can modify everything?

tjebo
  • 21,977
  • 7
  • 58
  • 94
Smanne
  • 23
  • 4
  • a very similar question was asked recently see here https://stackoverflow.com/questions/61288690/visualising-linear-mixed-model-in-r/61289768#61289768 hope this helps. Let me know if you need guidance, don't forget to ping me otherwise I won't be notified) – tjebo Apr 22 '20 at 15:54
  • @Tjebo thanks for your answer. I meant something different. I want only one single regression line between dep&pred, as in the plot above. However, I am not able to get the same slope and confidence intervals in ggplot. – Smanne Apr 24 '20 at 12:56
  • best would be to provide some sample data! The way to go in ggplot would be to predict() your data, and use the error intervals as upper and lower boundary for geom_ribbon. – tjebo Apr 24 '20 at 13:13

0 Answers0