与其他许多人一样,我运行使用glme函数的模型运行lme4包时遇到问题。使用glmer解决警告信息
这里是我的模型:
model = glmer(depvar ~ variety*cover+amplitude+time+ (1|pp) + (1|stim),
data = datafile, family=poisson)
,这里是警告我得到:
Warning message:
In checkConv(attr(opt, "derivs"), opt$par,
ctrl = control$checkConv, :
Model failed to converge with max|grad| = 0.00606839
(tol = 0.001, component 1)
我在this link看,如果我添加
control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=100000))
在年底我的模型,我解决了这个问题。 我试过了,所以我现在模型是:
model = glmer(depvar ~ variety*cover+amplitude+time+
(1|pp) + (1|stim), data = datafile, family=poisson,
control=glmerControl(optimizer="bobyqa",
optCtrl=list(maxfun=100000)))
和它的作品没有给出任何警告信息。
我想问一下是否有人可以解释我为模型添加的内容,因为我不确定是否理解。另外,这是解决警告问题的可接受解决方案吗?或者任何人以不同的方式解决它?
非常感谢。
而不control=glmerControl(optimizer="bobyqa", optCtrl=list(maxfun=100000)))
的输出是:
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: poisson (log)
Formula: depvar ~ variety * cover + amplitude + time + (1 | pp) + (1 | stim)
Data: datafile
AIC BIC logLik deviance df.resid
6916.6 6963.1 -3450.3 6900.6 2473
Scaled residuals:
Min 1Q Median 3Q Max
-0.8955 -0.4712 -0.2797 0.3163 3.0090
Random effects:
Groups Name Variance Std.Dev.
stim (Intercept) 0.031757 0.17821
pp (Intercept) 0.008918 0.09443
Number of obs: 2481, groups: stim, 200; pp, 28
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.77480 0.21459 3.611 0.000305 ***
variety2-1 0.04813 0.03096 1.555 0.119969
cover2-1 0.06725 0.03096 2.172 0.029862 *
amplitude -0.04704 0.02685 -1.752 0.079837 .
time -0.02545 0.03747 -0.679 0.496943
variety2-1:cover2-1 0.01435 0.06170 0.233 0.816128
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
convergence code: 0
Model failed to converge with max|grad| = 0.00606839 (tol = 0.001, component 1)
与control=glmerControl(optimizer="bobyqa", optCtrl=list(maxfun=100000)))
的输出是:
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: poisson (log)
Formula: depvar ~ variety * cover + amplitude + time + (1 | pp) + (1 | stim)
Data: datafile
Control: glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 1e+05))
AIC BIC logLik deviance df.resid
6916.6 6963.1 -3450.3 6900.6 2473
Scaled residuals:
Min 1Q Median 3Q Max
-0.8956 -0.4712 -0.2797 0.3163 3.0090
Random effects:
Groups Name Variance Std.Dev.
stim (Intercept) 0.031759 0.17821
pp (Intercept) 0.008917 0.09443
Number of obs: 2481, groups: stim, 200; pp, 28
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.77480 0.21457 3.611 0.000305 ***
variety2-1 0.04813 0.03096 1.555 0.119997
cover2-1 0.06725 0.03096 2.172 0.029860 *
amplitude -0.04703 0.02685 -1.751 0.079861 .
time -0.02545 0.03746 -0.679 0.496889
variety2-1:cover2-1 0.01434 0.06170 0.232 0.816160
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
您应该阅读'help(“convergence”)'。 – Roland
@Roland我知道我应该“尝试所有可用的优化器(例如,从优化,nlminb,...等几种不同的BOBYQA和Nelder-Mead,L-BFGS-B的实现)。虽然这对于大型拟合当然会很慢,我们认为它是黄金标准;如果所有优化器收敛于实际上相同的值,那么我们会认为收敛警告是误报。“(来自help'convergence')。但是我想明白为什么我们在这种情况下需要使用“bobyqa”作为优化器。它有什么作用? – dede
第一点是这个警告可能是误报。该帮助没有说'我们需要使用“bobyqa”'。它说我们可以并且我们应该将结果与其他优化器的结果进行比较。但是,您没有使用不同的优化器(bobyqa是'glmer'的默认值),而是增加了“允许的最大功能评估数”,即允许尝试达到收敛的更多迭代。 – Roland