[英]How to (quickly) extract t values from lmer model in lme4?
I am working with a script that calls lmer
function of the lme4
package thousands of times (do not worry, relevant correction for multiple comparisons is performed later) and would like to save as much time during a single call as possible. 我与调用脚本工作
lmer
的功能lme4
包上千次(不要担心,在后面进行多重比较相关的校正),并想在单个呼叫尽可能在尽可能多的时间来保存。
I want to extract t-values from the fitted model, what is the fastest (computation time) way to do this? 我想从拟合模型中提取t值,最快的方式(计算时间)是什么? I tried using
summary(model)
but it seems to take (much) longer than calling lmer
itself. 我尝试使用
summary(model)
但似乎比调用lmer
本身花费的时间更长。 Is it possible to get the t-values from the obtained model without using summary()
? 是否可以在不使用
summary()
情况下从获得的模型中获得t值?
The best way to answer this question is to look at the code of lme4:::summary.merMod
to figure out how to get the pieces you need. 回答此问题的最佳方法是查看
lme4:::summary.merMod
的代码,以弄清楚如何获得所需的零件。 This ought to do it: 这应该做到:
library(lme4)
fm1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
t.stat <- function(x) fixef(x)/sqrt(diag(vcov(x)))
t.stat(fm1)
## (Intercept) Days
## 36.838311 6.771485
coef(summary(fm1))[,"t value"] ## identical
Depending on what characteristics are common across your thousands of calls to lmer
there may be other opportunities for computational efficiency: see eg ?refit
and ?modular
. 取决于您成千上万次致电
lmer
共同特征是什么,可能还有其他提高计算效率的机会:请参阅例如?refit
和?modular
。
(Looking at the code of lme4:::summary.merMod
doesn't reveal anything obviously time-consuming: I would be interested in profiling results that say what's slow in those computations.) (查看
lme4:::summary.merMod
的代码并没有发现任何明显耗时的内容:我对剖析表明哪些计算速度较慢的结果很感兴趣。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.