问题是lmerTest::step.lmerModLmerTest
当在随机效应选择阶段从模型中消除所有随机效应时,就会中断。它可能不应该(我认为该包的早期版本可能不应该),但解决起来并不难。您可以指定不应简化随机效应模型(step(full.model, reduce.random=FALSE)
), or,当遇到这个错误时,扔掉模型的随机效应成分,然后使用step()
在所得的线性模型上:
fixmodel <- lm(formula(full.model,fixed.only=TRUE),
data=eval(getCall(full.model)$data))
step(fixmodel)
(因为它包括eval()
,这仅在 R 可以找到由data=
争论)。
我已经提交了一份issue https://github.com/runehaubo/lmerTestR/issues/23关于这个问题。
另外(令人困惑的是),stats::step
有不同的论点/做出不同的假设step.lmerModLmerTest
in the lmerTest
包裹。stats::step
定义为
step(object, scope, scale = 0,
direction = c("both", "backward", "forward"),
trace = 1, keep = NULL, steps = 1000, k = 2, ...)
while step.lmerModLmerTest
uses
step(object, ddf = c("Satterthwaite",
"Kenward-Roger"), alpha.random = 0.1, alpha.fixed = 0.05,
reduce.fixed = TRUE, reduce.random = TRUE, keep, ...)
特别是,direction
参数不适用(step.lmerModLmerTest
只进行向后消除);不 不k
(我相信step.lmerModLmerTest
使用 AIC,但我必须仔细检查)。
set.seed(1001)
dd <- data.frame(x1=rnorm(500),x2=rnorm(500),
x3=rnorm(500),f=factor(rep(1:50,each=10)))
library(lme4)
dd$y <- simulate(~x1+x2+x3+(1|f),
newdata=dd,
newparams=list(theta=1,beta=c(1,2,0,0),
sigma=1),
family=gaussian)[[1]]
library(lmerTest)
full.model <- lmer(y~x1+x2+x3+(1|f), data=dd)
step.model<- step(full.model)
step.model
有课step_list
;有打印方法,但没有摘要方法。