Reputation: 7517
I was wondering in my R code below, how I can extract df
values from the ems$emmeans
object?
library(lme4)
library(emmeans)
dat <- read.csv('https://raw.githubusercontent.com/hkil/m/master/z.csv')
dat$year <- as.factor(dat$year)
m1 <- lmer(y~year*group + (1|stid), data = dat)
ems <- emmeans(m1, pairwise ~ group*year, infer = c(T, T))
# How to extract 'df' values from ems$emmeans?
Upvotes: 1
Views: 467
Reputation: 887951
There is as.data.frame
method for 'emmGrid'
methods(class = 'emmGrid')
#[1] [ + as.data.frame as.glht as.list CLD coef confint
#[9] contrast pairs plot predict print rbind show str
#[17] summary test update vcov
So, we can convert the output of 'emmeans' to data.frame
and extract the 'df' with $
or [[
as.data.frame(ems$emmeans)$df
There is a Note
which suggest that `D.f. calculations are disable because the observations exceed 3000 and to enable, add 'pbkrtest.limit = 3435'
ems <- emmeans(m1, pairwise ~ group*year, infer = c(T, T), pbkrtest.limit = 3435)
as.data.frame(ems$emmeans)$df
#[1] 3090.821 2994.815 3328.634 3164.587 3380.889 3371.980
Upvotes: 1