subject <- factor(rep(c(1,2,3,4,5,6,7,8),each=4))
dep <- c(5,4,9,3,4,4,2,1,10,7,8,7,1,2,1,1,5,10,1,7,3,2,1,4,3,8,7,3,1,1,2,1,1,1,2,1,15,10,20,11,2,2,1,3,11,12,9,7,2,3,1,2,11,9,8,9,3,4,2,1,14,20,11,21)
f1 <- factor(rep(c("Female","Male"), each=32))
f2 <- factor(rep(c("day1","day2"),times=32))
data <- data.frame(sub=subject, dep=dep, f1=f1, f2=f2)
m <- lmer(dep ~ f1*f2 + (1|sub), data=data)
I've been trying without success to calculate standard errors as shown with
library(emmeans)
emmeans(m, ~ f1|f2)
Can somebody help me to understand how to get the standard errors without using the library?
EDIT (unbalanced)
subject <- factor(rep(c(1,2,3,4,5,6,7),each=4, times=2))
dep <- c(5,4,9,3,4,4,2,1,10,7,8,7,1,2,1,1,5,10,1,7,3,2,1,4,3,8,7,3,1,1,2,1,15,10,20,11,2,2,1,3,11,12,9,7,2,3,1,2,11,9,8,9,3,4,2,1)
f1 <- factor(rep(c(rep("Female",times=16),rep("Male",times=12)), times=2))
f2 <- factor(c("day1","day1","day1","day1", rep(c("day1","day2"),times=24), "day2","day2","day2","day2"))
data <- data.frame(sub=subject, dep=dep, f1=f1, f2=f2)
m <- lmer(dep ~ f1*f2 + (1|sub), data=data)