1

我已经估计了数据集中每个组的截距的置信区间,如下所示:

d <- data.frame(
    g=sample(letters[1:5], 100, replace=TRUE),
    y=runif(100)
)

library(lme4)

fm <- lmList(y ~ 1 | g, data=d)
ci.fm <- confint(fm)
ci.fm
# An object of class "lmList.confint"
# , , (Intercept)
# 
#       2.5 %    97.5 %
# a 0.4253236 0.6668585
# b 0.4860047 0.6794625
# c 0.4071186 0.6822713
# d 0.2785848 0.5992378
# e 0.4110070 0.6890399

必须有一种方法可以分别索引每个列,但我无法弄清楚。我已经尝试过查看str(ci.fm)attributes(ci.fm)尝试过attr(ci.fm, dimnames[[2]]$"2.5 %")其他类似的事情,但所有这些都没有奏效。我会很感激一个正确方向的指针。谢谢。

4

2 回答 2

2

It is an S4 object: you can have the list of "slots" with slotNames, and access them with @ (instead of $). In this case, the only slot is .Data, with a leading dot, so ci.fm@.Data contains the actual data.

str(ci.fm)
# Formal class 'lmList.confint' [package "lme4"] with 1 slots
#   ..@ .Data: num [1:5, 1:2, 1] 0.35 0.348 0.315 0.143 0.388 ...
#   .. ..- attr(*, "dimnames")=List of 3
#   .. .. ..$ : chr [1:5] "a" "b" "c" "d" ...
#   .. .. ..$ : chr [1:2] "2.5 %" "97.5 %"
#   .. .. ..$ : chr "(Intercept)"

slotNames(ci.fm)
# [1] ".Data"

str( ci.fm@.Data )  # 3-dimensional array
#  num [1:5, 1:2, 1] 0.35 0.348 0.315 0.143 0.388 ...
#  - attr(*, "dimnames")=List of 3
#   ..$ : chr [1:5] "a" "b" "c" "d" ...
#   ..$ : chr [1:2] "2.5 %" "97.5 %"
#   ..$ : chr "(Intercept)"

ci.fm@.Data[,1,1]  # First column
#         a         b         c         d         e 
# 0.3496147 0.3482908 0.3147435 0.1434213 0.3876549 
于 2012-06-28T15:27:12.300 回答
2
ci.fm[,"2.5 %",]
        a         b         c         d         e 
0.4463712 0.3297468 0.3622782 0.2901415 0.2847008
于 2012-06-28T15:28:19.383 回答