Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting elements from emmGrid of emmeans R package

Tags:

r

extract

emmeans

I wonder how to extract emmean and SE columns from emmGrid of emmeans R package. MWE is given below.

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"
like image 947
MYaseen208 Avatar asked Jan 26 '18 12:01

MYaseen208


1 Answers

summary(Test) gives a data.frame instead.

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

So one can do:

summary(Test)$emmean
[1] 31.03704 25.25926

And

summary(Test)$SE
[1] 2.105459 2.105459

To actually get a new subsetted data.frame, you need to explicitly coerce to class data.frame:

as.data.frame(summary(Test))[c('emmean', 'SE')]
    emmean       SE
1 31.03704 2.105459
2 25.25926 2.105459
like image 97
Axeman Avatar answered Sep 28 '22 19:09

Axeman