你在做 lapply 时没有使用你迭代的向量,你只能做 1 次测试, lapply 没有意义:
lapply(onelmer,
function(x){emmeans(onelmer[[i]], pairwise ~ onelmer1[i] ...)})}
试试下面的方法,仔细检查你正在迭代的内容,并确保给它们起更好的有意义的名字(而不是 onelmer1 和 onemer...):
library(emmeans)
library(lme4)
set.seed(111)
learndata_long3 = data.frame(ACC=rnorm(100),LR1st=sample(c("a","b"),100,replace=TRUE),LR2nd = sample(c("c","d"),100,replace=TRUE),Subject = factor(rep(1:2,50)))
lhiry1 <- lmer(ACC ~ LR1st +(1|Subject),data = learndata_long3)
lhiry2 <- lmer(ACC ~ LR2nd +(1|Subject),data = learndata_long3)
mdls=list(lhiry1=lhiry1,lhiry2=lhiry2)
coefs=c('LR1st','LR2nd')
output= vector("list",2)
for (i in 1:length(mdls)){
output[[i]]=emmeans(mdls[[i]],
as.formula(paste("pairwise ~",coefs[i])),
adjust ="bonf")
}
output
[[1]]
$emmeans
LR1st emmean SE df lower.CL upper.CL
a -0.0836 0.150 2.73 -0.588 0.420
b -0.0275 0.155 3.11 -0.510 0.455
Degrees-of-freedom method: kenward-roger
Confidence level used: 0.95
$contrasts
contrast estimate SE df t.ratio p.value
a - b -0.0561 0.198 97.7 -0.283 0.7777
Degrees-of-freedom method: kenward-roger
[[2]]
$emmeans
LR2nd emmean SE df lower.CL upper.CL
c -0.273 0.149 3.02 -0.747 0.200
d 0.151 0.147 2.83 -0.333 0.635
Degrees-of-freedom method: kenward-roger
Confidence level used: 0.95
$contrasts
contrast estimate SE df t.ratio p.value
c - d -0.424 0.192 97 -2.216 0.0290
Degrees-of-freedom method: kenward-roger