> library(nlme)
> d <- data.frame(x=rep(letters, each=5),
z=rep(LETTERS[1:13], each=10),
y=rep(rnorm(26, sd=2), each=5) + rep(rnorm(13), each=10) + rnorm(26 * 5))
> r <- ranef(d) # random.effects is a synonym for this
# Look at the structure of r
> str(r)
List of 2
$ z:'data.frame': 13 obs. of 1 variable:
..$ (Intercept): num [1:13] -1.575 -0.365 -1.817 0.235 2.369 ...
..- attr(*, "effectNames")= chr "(Intercept)"
$ x:'data.frame': 26 obs. of 1 variable:
..$ (Intercept): num [1:26] -0.8628 0.0536 1.724 -1.9115 -1.1764 ...
..- attr(*, "effectNames")= chr "(Intercept)"
- attr(*, "label")= chr "Random effects"
- attr(*, "level")= int 2
- attr(*, "standardized")= logi FALSE
- attr(*, "grpNames")= chr [1:2] "z" "x %in% z"
- attr(*, "class")= chr [1:2] "ranef.lme" "list"
> head(r$x)
(Intercept)
A/a -0.86283867
A/b 0.05360748
B/c 1.72401850
B/d -1.91145501
C/e -1.17643222
C/f 0.24315559
> head(r$z)
(Intercept)
A -1.5752441
B -0.3648627
C -1.8167101
D 0.2353324
E 2.3685118
F -1.7544619
> r$z["A", ]
[1] -1.575244
> r$x["A/a", ]
[1] -0.8628387
'level'參數不起作用嗎? http://finzi.psych.upenn.edu/R/library/nlme/html/ranef.lme.html – 2010-09-10 13:28:06
不,問題不在於我找不到任何隨機效果;我想要一個給定組的具體價值。我有一個功能上是隨機效應列表的數據框。當我打印時(random.effects(Model)),我得到兩列 - 右邊是組名列表,左邊是隨機效果列表。然而,random.effects(Model)[「group_name」]不起作用(但是如果我知道如何選擇一個整數i,random.effects(Model)[i]將起作用)。 R語言中的哪些內容將我在左側看到的名稱與我在右側看到的值聯繫在一起? – 2010-09-10 15:48:07