是否可以将merModLmerTest对象从lmerTest向下转换为lme4中的merMod对象?我有很多用例,在这些用例中我需要在格式之间切换。
根据lmerTest文档:
merModLmerTest包含lme4包的merMod类,并重载anova和汇总函数。
但是,我不知道继承是如何工作的。
发布于 2019-04-18 14:44:46
lmerModLmerTest对象几乎与merMod对象相同,但有一些额外的插槽。也许有一种优雅的方法来减少它们,但我是用蛮力完成的(由于new()函数所做的一些评估,它比我想象的要复杂一些)。
示例:
library(lme4)
fm0 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)
library(lmerTest)
fm1 <- as(fm0,"lmerModLmerTest")这可能是设置事情的错误方式(应该使用setAs()等)。但是..。
as.merMod.lmerModLmerTest <- function(x) {
r <- list(Class="lmerMod")
for (s in names(getSlots("merMod"))) {
r[[s]] <- slot(x,s)
}
r$resp <- quote(x@resp)
r$call <- quote(x@call) ## protect from evaluation
do.call(new,r)
}试一试:
fm2 <- as.merMod.lmerModLmerTest(fm1)
all.equal(fm0,fm2) ## TRUEhttps://stackoverflow.com/questions/31321104
复制相似问题