5
$\begingroup$

Context and current approach:

I read through quite a few posts on this website and on the internet but I'm still not 100% sure on what exactly the assumptions are and how to check them in practice.

Below a (hopefully exhaustive) list of the assumptions I have in mind:

  1. The model is correctly specified (i.e. linear relationships between outcome and continuous predictors, no perfect colinearities)
  2. Samples are independent (obviously after e.g. repeated measures have been taking into account)
  3. Residuals on all levels have constant variance (that is, the "errors" and the random effects)
  4. Residuals on all levels are normally distributed (again that needs to be true for "errors" and the random effects)

Having all of this in mind, I'm now looking to use R to check these assumptions. We can use some built in data from the lme4 package

library("lme4")
data("sleepstudy")
head(sleepstudy)
# Some simple MM
sleepstudy_model=lmer(Reaction ~ Days + (1 | Subject), sleepstudy)
  1. We can look at the "errors" here if we want to see if there's a pattern, check colinearity between predictors, etc.
plot(sleepstudy_model)
  1. We just consider the design of the study at hand for this. I assume we can look for patterns in the "error" terms again.
plot(sleepstudy_model)
  1. Here it gets trickier for me.. For the "errors" it's simple, but what about the random intercept?
# Checking for the errors, just look for a pattern in here
plot(sleepstudy_model)

#But what about the random intercept? Something like this?
plot(data.frame(ranef(sleepstudy_model))$condval, data.frame(ranef(sleepstudy_model))$condsd)
  1. Same thing here, it's easy for the "errors", but I'm not sure about the random intercept.
# Checking for the errors
qqnorm(residuals(sleepstudy_model))

#Checking for the random intercept? 
qqnorm(data.frame(ranef(sleepstudy_model))$condval)

Question:

Did I list all necessary assumptions correctly? If yes, did I correctly check for all of them? Are the any additional nice ways to check for some?

Sources:

Robert Long's answer to the question "assumptions for lmer models" below:

assumptions for lmer models

Frank Harrel's answer to the question "Are there any parametric assumptions for Linear Mixed Models - lmer (multivariate model)" below:

Are there any parametric assumptions for Linear Mixed Models - lmer (multivariate model)

Some answers from to the question "Checking assumptions lmer/lme mixed models in R" below:

Checking assumptions lmer/lme mixed models in R

$\endgroup$
1
  • $\begingroup$ Late answer, but this is for ease of effort for other searchers that find this answer. Try: ``` library(performance) check_model(sleepstudy_model) ``` $\endgroup$
    – MrSwaggins
    Commented Aug 7 at 5:30

1 Answer 1

3
+50
$\begingroup$

I think that's a pretty solid approach to the assumptions, but a few points:

I'm not sure it's particularly useful to think of the random effects as "residuals", since you don't exactly have observed data against which to compare your model predictions against.

In this example, random effects are not nested, so you don't need to worry about them having different variance in different contexts. You would, however, if you had data on students (level 1) nested within different classes (L2) nested within different schools (L3).

In general, you can do a lot of flexible diagnostics by adding your model predictions and the corresponding residuals as new columns in your data frame.

sleepstudy = mutate(sleepstudy,
                    prediction = fitted(sleepstudy_model),
                    resid = Reaction - prediction,
                    resid2 = resid^2) # Squared errors

I've posted some of the diagnostic plots you can generate using this data to https://rpubs.com/eointravers/xv-lmm-residuals (example below)

enter image description here

PS: Since this is reaction time data, a lot of the apparent violations of the assumptions can be cleaned up by analysing log-transformed RTs instead.

$\endgroup$
2
  • $\begingroup$ Thanks for the helpful answer! I will accept it tonight if nothing else comes up. I somehow can't see anything when clicking on the link you provide. I would be very interested to have a look! $\endgroup$
    – Joel H
    Commented Jun 9, 2022 at 11:01
  • $\begingroup$ Are you sure? It works for me, even in an incognito tab. $\endgroup$
    – Eoin
    Commented Jun 9, 2022 at 14:41

Your Answer

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

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