简体   繁体   English

如何规范化 Lmer 模型?

[英]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)在我的公式中尝试了手动 log、power、sqrt 转换,但没有任何改进,我也找不到合适的自动转换 R 函数,例如 BoxCox(不适用于 LMER)

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.这可能更适合CrossValidated (“我应该做什么?”适合 CV;“我应该怎么做?”最适合 Stack Overflow),但我会尝试一下。

  • 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]). QQ 图通常是您应该查看的最后一个/最不重要的诊断(顺序应该是大约(1)检查平均值中的显着偏差/缺失模式[拟合与残差、残差与协变量];(2)检查对于异常值/影响点[杠杆,库克距离];(3)检查异方差性[尺度位置图];(4)检查分布假设[QQ图])。 The reason is that any of the "upstream" failures (eg missed patterns) will show up in the QQ plot as well;原因是任何“上游”失败(例如错过的模式)也会出现在 QQ 图中; 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您可以编写自己的蛮力 Box-Cox,例如
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.如果您确实需要拟合具有重尾残差分布的混合模型(例如 Student t),则选项相当有限。 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. brms包可以适合这样的模型(但会让你陷入贝叶斯/MCMC 兔子洞),而heavy包(目前在 CRAN 上存档)可以工作,但似乎不能处理交叉随机效应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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