6

我想知道如何提取emmean从包 中提取 和SE列。MWE 如下所示。emmGridemmeans R

library(emmeans)
warp.lm <- lm(breaks ~ wool * tension, data = warpbreaks)
Test <- emmeans(warp.lm,  specs = "wool")

Test
wool   emmean       SE df lower.CL upper.CL
 A    31.03704 2.105459 48 26.80373 35.27035
 B    25.25926 2.105459 48 21.02595 29.49257

Results are averaged over the levels of: tension 
Confidence level used: 0.95 

class(Test)
[1] "emmGrid"
attr(,"package")
[1] "emmeans"
4

1 回答 1

8

summary(Test)而是给出一个 data.frame 。

class(summary(Test))
[1] "summary_emm" "data.frame" 

所以可以这样做:

summary(Test)$emmean
[1] 31.03704 25.25926

summary(Test)$SE
[1] 2.105459 2.105459

要真正获得一个新的子集 data.frame,您需要显式强制转换为 data.frame 类:

as.data.frame(summary(Test))[c('emmean', 'SE')]
    emmean       SE
1 31.03704 2.105459
2 25.25926 2.105459
于 2018-01-26T12:37:30.750 回答