我已经建立了以下模型
model2 <- lmerTest::lmer(LPP2POz ~ 1 + COND + (1|ID), data = dataLPP2POz)
如果我尝试运行以下函数,它会返回这个错误:
printCoefmat(summary(model2)$tTable,
has.Pvalue = T, P.values = T)
这里是我正在处理的数据集的短数据帧
dput(head(dataLPP2POz))
structure(list(ID = structure(c(1L, 1L, 1L, 2L, 2L, 2L), .Label = c("01",
"04", "06", "07", "08", "09", "10", "11", "12", "13", "15", "16",
"17", "18", "19", "21", "22", "23", "25", "27", "28", "30", "44",
"46", "49"), class = "factor"), GR = c("RP", "RP", "RP", "RP",
"RP", "RP"), SES = c("V", "V", "V", "V", "V", "V"), COND = structure(c(1L,
2L, 3L, 1L, 2L, 3L), .Label = c("NEG-CTR", "NEG-NOC", "NEU-NOC"
), class = "factor"), LPP2POz = c(7.91468942320841, 9.94838815736199,
10.2186482048953, 1.07455889922813, 1.65917850515029, 3.22422743232682
)), row.names = c(NA, 6L), class = "data.frame")
Error in printCoefmat(summary(model2)$tTable, has.Pvalue = T, P.values = T) :
'x' must be coefficient matrix/data frame
有人能明白错误是什么吗?
跟进并澄清@aosmith的评论。
对于不同的混合模型包,提取系数表的工作方式不同。较新的默认值(适用于lme4
,lmerTest
,glmmTMB
)是系数表可以提取为summary(model)$coefficients
(在底层,这意味着summary()
方法返回一个列表,其中coeff表存储为$coefficients
)元素。对于这些包,coef(summary(model))
是更好的实践。
对于来自nlme
包(即lme
)的对象,汇总表被存储为summary(model)$tTable
(这很不幸,但nlme
比R本身更老…
它不会给出与printCoefmat
完全相同的结果,但您也可以查看broom.mixed::tidy()
输出的一些漂亮打印选项,其目的是构建一个兼容层,因此您不必记住所有这些东西…