rr <- ranef(fm1) ## condVar = TRUE has been the default for a while
使用as.data.frame:给出条件模式和 SD,您可以从中计算区间(从技术上讲,这些不是“置信区间”,因为 BLUP/条件模式的值不是参数......)
dd <- as.data.frame(rr)
transform(dd, lwr = condval - 1.96*condsd, upr = condval + 1.96*condsd)
或者broom.mixed::tidy:
broom.mixed::tidy(m1, effects = "ran_vals", conf.int = TRUE)
broom.mixed::tidy() 内部使用as.data.frame.ranef.mer()(as.data.frame 调用的方法):该函数采用?lme4::ranef 中描述的相当复杂的数据结构,并以更用户友好的格式提取条件模式和标准差:
如果‘condVar’为‘TRUE’,则‘"postVar"’
属性是维度为 j x j x k 的数组(或此类列表
数组)。这个数组的第 k 个面是正定的
j 对称 j 矩阵。如果只有一个分组因子
该模型是整个随机数的方差-协方差矩阵
效应向量,以模型的估计为条件
参数和数据上,将是块对角线;这个 j by j
矩阵是第 k 个对角线块。具有多个分组因素
‘"postVar"’ 属性的面仍然是对角线
这个条件方差 - 协方差矩阵的块,但
矩阵本身不再是块对角线。
在这种特殊情况下,您需要执行以下操作来复制 as.data.frame() 的 condsd 列:
## get the 'postVar' attribute of the first (and only) RE term
aa <- attr(rr$Subject, "postVar")
## for each slice of the array, extract the diagonal;
## transpose and drop dimensions;
## take the square root
sqrt(c(t(apply(aa, 3, diag))))