简体   繁体   中英

How to normalize a Lmer model?

lmer:

mixed.lmer6 <- lmer(Size ~ (Time+I(Time^2))*Country*STemperature +
   (1|Country:Locality)+ (1|Locality:Individual)+(1|Batch)+
   (1|Egg_masses), REML = FALSE, data = data_NoNA) 

residuals:

plot_model(mixed.lmer6, type = "diag")

非正态

Tried manual log,power, sqrt transformations in my formula but no improvement and I also can not find a suitable automatic transformation R function such as BoxCox (which does not work for LMER's)

Any help or tips would be appreciated

This might be better suited for CrossValidated ("what should I do?" is appropriate for CV; "how should I do it?" is best for Stack Overflow), but I'll take a crack.

  • The QQ plot is generally the last /least important diagnostic you should look at (the order should be approximately (1) check for significant bias/missed patterns in the mean [fitted vs. residual, residual vs. covariates]; (2) check for outliers/influential points [leverage, Cook's distance]; (3) check for heteroscedasticity [scale-location plot]; (4) check distributional assumptions [QQ plot]). The reason is that any of the "upstream" failures (eg missed patterns) will show up in the QQ plot as well; resolving them will often resolve the apparent non-Normality.
  • If you can fix the distributional assumptions by fixing something else about the model (adding covariates/adding interactions/adding polynomial or spline terms/removing outliers), then do that.
  • you could code your own brute-force Box-Cox, something like
fitted_model <- lmer(..., data = mydata)
bcfun <- function(lambda, resp = "y") {
   y <- mydata[[resp]]
   mydata$newy <- if (lambda==0) log(y) else (y^lambda -1)/lambda
   ## https://stats.stackexchange.com/questions/261380/how-do-i-get-the-box-cox-log-likelihood-using-the-jacobian
   log_jac <- sum((lambda-1)*log(y))
   newfit <- update(fitted_model, newy ~ ., data = mydata)
   return(-2*(c(logLik(newfit))+ log_jac))
}
lambdavec <- seq(-2, 2, by = 0.2)
boxcox <- vapply(lambdavec, bcfun, FUN.VALUE = numeric(1))
plot(lambdavec, boxcox - min(boxcox))

(lightly tested! but feel free to let me know if it doesn't work)

  • if you do need to fit a mixed model with a heavy-tailed residual distribution (eg Student t), the options are fairly limited. The brms package can fit such models (but takes you down the Bayesian/MCMC rabbit hole), and the heavy package (currently archived on CRAN) will work, but doesn't appear to handle crossed random effects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM