13
$\begingroup$

I've been analysing some data using linear mixed effect modelling in R. I'm planning to make a poster with the results and I was just wondering if anyone experienced with mixed effect models could suggest which plots to use in illustrating the results of the model. I was thinking about residual plots, plot of fitted values vs original values, etc.

I know this will very much depend on my data but I was just trying to get a feel for the best way to illustrate results of linear mixed effect models. I'm using the nlme package in R.

Thanks

$\endgroup$
22
$\begingroup$

It depends on your model, but, in my experience, even colleagues, who don't have a good understanding of mixed effects models, really like if you plot the predictions with different grouping levels:

library(nlme)
fm2 <- lme(distance ~ age + Sex, data = Orthodont, random = ~ 1|Subject)

newdat <- expand.grid(Sex=unique(Orthodont$Sex),
                  age=c(min(Orthodont$age),
                            max(Orthodont$age)))

library(ggplot2)
p <- ggplot(Orthodont, aes(x=age, y=distance, colour=Sex)) +
  geom_point(size=3) +
  geom_line(aes(y=predict(fm2), group=Subject, size="Subjects")) +
  geom_line(data=newdat, aes(y=predict(fm2, level=0, newdata=newdat), size="Population")) +
  scale_size_manual(name="Predictions", values=c("Subjects"=0.5, "Population"=3)) +
  theme_bw(base_size=22) 
print(p)

enter image description here

$\endgroup$
  • $\begingroup$ @ Roland, thanks for your answer. My model is a linear mixed effect model containing independent and dependent variables with some covariates. $\endgroup$ – John_dydx May 17 '14 at 9:35
  • $\begingroup$ @ Roland, can I just ask if fm2 <- lme(distance ~ age + Sex, data = Orthodont, random = ~ 1|Subject) is the same as fm3 <- lme(distance ~ age*Sex, data = Orthodont, random = ~ 1|Subject) . I'm trying to use Sex as a covariate for the model. $\endgroup$ – John_dydx May 17 '14 at 12:43
  • $\begingroup$ No. age * Sex is the same as age + Sex + age:Sex, i.e., it includes the interaction. $\endgroup$ – Roland May 17 '14 at 12:49
  • 1
    $\begingroup$ Yes, of course. You'd need to remove colour=Sex. $\endgroup$ – Roland May 17 '14 at 17:23
  • 1
    $\begingroup$ Yes, but that's basic ggplot2 functionalty. Study the documentation and tutorials. You might want to use scale_colour_manual. $\endgroup$ – Roland May 20 '14 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.