I'm after some advice regarding heteroscedasticity in a residuals vs predicted plot.

I have measured the length of a group of animals at birth and then at five subsequent time points into the future. As length is a continuous variable and I have random factors to account for, I have built a set of gaussian GLMM models in the glmmTMB package. I used AICc to select my most parsimonious model. My most parsimonious model is below, there are no random effects in my final model:

glmmTMB(length ~ time + small_length_at_birth, data = long, family = gaussian)

I created residual plots using the DHARMa package and it appears that my model residuals are to some extent non-linear and heteroscedastic.

Plot 1

I then log() transformed length and re-ran my model; I got the same most parsimonious model. When I create residual plots for this new transformed model the qq plot is much better, but the residuals vs predicted values still indicates a problem. My understanding from reading here (the Missing predictors or quadratic effects section) and here (Ben Bolker answer) is that this pattern in residuals vs predicted suggests I may be missing a quadratic effect. I have tried re-running my models with time + time^2 and time + time^2 + time^3, but neither seems to improve the residuals vs predicted plot.

Plot 2

I have plotted length over time separately for a bunch of individuals (but not all individuals). There is definitely variation in how individual animal's length increases over time, but random intercepts for individual are not supported and random slop for individual will not run for some reason unknown to me.

Does anyone have any suggestions/advice on how else to go about solving problem with heteroscedasticity? I assume this pattern in the residuals is significant enough to not be appropriate to ignore it?

UPDATE I have plotted residuals against each predictor from the second set of models were length is log transformed. Below is the plot for residuals vs time - it appears that the time variable is driving the observed pattern in residuals vs predicted plot (plot 2), however despite this including 'time + time^2' or another quadratic does not solve the problem.

Plot 3

  • 2
    $\begingroup$ Have you tried factor(time)? Also, what is your reason for selecting the most parsimonious model? Random effects are used to account for dependence between measurements, so forgoing a mixed model based on parsimony alone does not seem like a good choice to me. $\endgroup$ May 8, 2020 at 4:02
  • $\begingroup$ Another question: What is small_length_at_birth? A random intercept would already account for baseline differences, and you can then simply include the baseline measurement as the first time point. $\endgroup$ May 8, 2020 at 4:11
  • $\begingroup$ I have previously been told that the inclusion of random effects should also be based on comparision of AICc values or similar criteria - it sounds like this is not true? I recognise that the structure of your random effects accounts for your study design, but i guess in the case that you include a random effect that does not reduce AICc I was told that this indicates that the particular aspect of the study design you are trying to account for is not particularly important. $\endgroup$ May 8, 2020 at 4:15
  • 2
    $\begingroup$ By leaving out the random effect, the remaining model assumes independent errors. Since this assumption is violated by the experimental design, the standard errors of the coefficients will be invalid. As for small_length_at_birth, this is something that you could model with a random slope. If what you hypothesize is true, then the random slope will be positively correlated with the random intercept. $\endgroup$ May 8, 2020 at 4:20
  • 1
    $\begingroup$ Does this answer your question? Resolving heteroscedasticity in Poisson GLMM $\endgroup$
    – user318514
    Aug 23, 2022 at 19:42


Your Answer

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

Browse other questions tagged or ask your own question.