我运行的初始模型如下:
play1 <- glmer(choice ~ x1 + x2 + x3 + x4 + x5 + log(x6) + (x1 + x2 + x3 + x4 + x5 + log(x6) || order), data=data.play0, family=binomial, control=glmerControl(optCtrl=list(maxfun=1e6)))
这并没有收敛,我收到了警告。我重新运行它:
play1.b <- glmer(choice ~ x1 + x2 + x3 + x4 + x5 + log(x6) + (x1 + x2 + x3 + x4 + x5 + log(x6) || order), data=data.play0, family=binomial, start=list(fixef=fixef(mm1.play0), theta=getME(mm1.play0, "theta")), control=glmerControl(optCtrl=list(maxfun=1e6)))
它仍然没有收敛。 x3,x4和x5的标准偏差接近于零,因此我放弃这些随机效应并继续
play1.c <- glmer(choice ~ x1 + x2 + x3 + x4 + x5 + log(x6) +
(x1 + x2 + log(x6) || order), data=data.play0,
family=binomial, start=list(fixef=fixef(play0),
theta=getME(play0, "theta")[-c(5,7)]),
control=glmerControl(optCtrl=list(maxfun=1e6)))
然后我收到我之前描述的错误消息
Error in getStart(start, lower = rho$lower, pred = rho$pp, "theta") :
incorrect number of theta components (!=4)
我为c矢量尝试不同的组合,但我仍然得到相同的消息。一切都是数字的。
答案 0 :(得分:3)
你没有给出一个可重复的例子,所以我做了一个:
library("lme4")
set.seed(101)
dd <- as.data.frame(matrix(rnorm(3000),ncol=6,
dimnames=list(NULL,paste0("x",1:6))))
dd$order <- factor(sample(1:25,size=500,replace=TRUE))
dd$x6 <- abs(dd$x6)
form <- choice ~ x1 + x2 + x3 + x4 + x5 + log(x6) +
(x1 + x2 + x3 + x4 + x5 + log(x6) || order)
dd$choice <- simulate(form[-2],
newdata=dd,
newparams=list(beta=rep(1,7),
theta=rep(1,7)),
family=binomial,
weights=rep(1,500))[[1]]
现在适合一些模特:
mm.play1 <- glmer(choice ~ x1 + x2 + x3 + x4 + x5 + log(x6) +
(x1 + x2 + x3 + x4 + x5 + log(x6) || order),
data=dd, family=binomial,
control=glmerControl(optCtrl=list(maxfun=1e6),
optimizer="nloptwrap"))
mm.play1b <- update(play1,start=list(fixef=fixef(mm.play1),
theta=getME(mm.play1, "theta")))
我稍稍调整了你的代码(使用&#34; nloptwrap&#34;优化器以获得一点额外的速度)
th <- getME(mm.play1, "theta")[c(1,2,3,7)]
mm.play1c <- update(mm.play1,
. ~ x1 + x2 + x3 + x4 + x5 + log(x6) +
(x1 + x2 + log(x6) || order),
start=list(fixef=fixef(mm.play1),
theta=th))
这是有效的(暂时没有时间进一步解释,但基本上你必须确保矢量长度匹配......)