简体   繁体   English

如何从混合模型(lmer)中提取学生化残差?

[英]How can I extract studentized residuals from mixed model (lmer)?

Here is my model, 这是我的模特,

MY = lmer(MY ~ Energy*Protein + (1|Sequence/Cow) + (1|Period), data = CH4CO2)

Is there a function that can extract studentized residuals? 有没有可以提取学生化残差的函数?

Here is what I did according to the definition, 这是我根据定义所做的,

StudentResid = function(fit){
  res = residuals(fit)
  H = hatvalues(fit)
  sigma = summary(fit)$sigm
  sres = sapply(1:length(res), function(i) res[[i]]/(sigma*sqrt(1-H[[i]])))
  test = abs(sres) > 3
  ifelse(any(test), which(test), NA)
}

StudentResid(MY)

Here I return the observations that has a relatively large studentized residual, considering as outlier. 在这里,我返回具有相对较大的学生化残差的观测值(考虑为离群值)。 Looks good? 看起来不错?

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

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