【发布时间】:2020-03-06 12:30:19
【问题描述】:
我正在使用lme4 运行二项式逻辑回归,其构造如下:
m2_DL <- glmer(Dest ~ Pb_on * Pb_type + Dest_tree + ZF_Dest + (1|Site), data = DF_DL_3, family = binomial(link = "logit"))
所有变量都是除 ZF_Dest 之外的因子,它是数字的。完整模型 (m1) 包含一个额外的数值变量并且工作正常。然而,第二个模型未能与警告消息收敛:
fixed-effect model matrix is rank deficient so dropping 6 columns / coefficients
Warning message:
In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
Model failed to converge with max|grad| = 0.00144561 (tol = 0.001, component 1)
在我的情况下,预计排名不足并且(我假设)与这里的问题无关。上网查看后发现可以尝试在我的 glmer 中添加以下参数:control = glmerControl(optimizer = "bobyqa"),确实可以解决问题。
但是,我希望更好地了解这个函数的作用,以及如果只有我的第二个模型有这个额外的参数,我是否仍然可以比较我的模型。这把我带到了this question on SO。这个问题的一个 cmets 指出:“你没有使用不同的优化器(bobyqa 是 glmer 的默认值)”。但如果是这种情况,那么添加参数如何解决警告,因为我没有像有时那样增加迭代次数?
从该问题的答案中,我了解到,如果两个模型的可能性差异很接近,我表示收敛错误是“误报”,这也是我的模型的情况。我还按照推荐阅读了help(converge),并使用了那里指示的 allFit 函数。
这输出:
bobyqa : fixed-effect model matrix is rank deficient so dropping 6 columns / coefficients
[OK]
Nelder_Mead : fixed-effect model matrix is rank deficient so dropping 6 columns / coefficients
[OK]
nlminbwrap : fixed-effect model matrix is rank deficient so dropping 6 columns / coefficients
[OK]
nmkbw : fixed-effect model matrix is rank deficient so dropping 6 columns / coefficients
[OK]
optimx.L-BFGS-B : fixed-effect model matrix is rank deficient so dropping 6 columns / coefficients
[OK]
nloptwrap.NLOPT_LN_NELDERMEAD : fixed-effect model matrix is rank deficient so dropping 6 columns / coefficients
[OK]
nloptwrap.NLOPT_LN_BOBYQA : fixed-effect model matrix is rank deficient so dropping 6 columns / coefficients
[OK]
Warning messages:
1: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
Model failed to converge with max|grad| = 0.0013785 (tol = 0.001, component 1)
2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
Model failed to converge with max|grad| = 0.00904036 (tol = 0.001, component 1)
3: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
Model failed to converge with max|grad| = 0.00904036 (tol = 0.001, component 1)
并且包含 allFit 结果的对象包含:
original model:
Dest ~ Pb_on * Pb_type + Dest_tree + ZF_Dest + (1 | Site)
data: DF_DL_3
optimizers (7): bobyqa, Nelder_Mead, nlminbwrap, nmkbw, optimx.L-BFGS-B, nloptwrap.NLOPT_LN_N...
1 optimizer(s) failed
differences in negative log-likelihoods:
max= 6.65e-05 ; std dev= 3.41e-05
在这里您可以看到 1 个优化器失败,我在使用 allFit 时收到了几个警告。现在我明白并非所有优化器都是平等的,有些优化器不适用于某些数据。问题是我不明白如何解释这个allFit 函数的结果,我不确定哪个优化器失败了,我是否应该担心。总而言之,我的问题:
如果这确实是默认优化器,BOBYQA 优化器如何解决该问题?
我应该如何解释
allFit的结果。解决第二个模型的警告的最佳方法是什么。直接加
control = glmerControl(optimizer = "bobyqa")合适吗?如果我将此参数添加到此模型中,我还能公平地将此模型与其他模型进行比较吗? (注意:我使用
anova函数来比较模型)。
谢谢
2020 年 6 月 3 日编辑: 根据 Roland 的要求,这里是 allFit 对象的摘要:
$which.OK
bobyqa Nelder_Mead nlminbwrap nmkbw
TRUE TRUE TRUE TRUE
optimx.L-BFGS-B nloptwrap.NLOPT_LN_NELDERMEAD nloptwrap.NLOPT_LN_BOBYQA
FALSE TRUE TRUE
$msgs
$msgs$bobyqa
NULL
$msgs$Nelder_Mead
NULL
$msgs$nlminbwrap
NULL
$msgs$nmkbw
[1] "Model failed to converge with max|grad| = 0.0013785 (tol = 0.001, component 1)"
$msgs$nloptwrap.NLOPT_LN_NELDERMEAD
[1] "Model failed to converge with max|grad| = 0.00904036 (tol = 0.001, component 1)"
$msgs$nloptwrap.NLOPT_LN_BOBYQA
[1] "Model failed to converge with max|grad| = 0.00904036 (tol = 0.001, component 1)"
$fixef
(Intercept) Pb_onL Pb_onN Pb_onS Pb_typeNG Pb_typeSong Dest_treeL ZF_Dest
bobyqa 0.4421569 0.5633434 0.1788602 -0.2046165 0.1777216 -0.1115736 0.5845617 0.01578428
Nelder_Mead 0.4420709 0.5633071 0.1788488 -0.2046262 0.1777301 -0.1115980 0.5845859 0.01578563
nlminbwrap 0.4421020 0.5633365 0.1788603 -0.2046102 0.1777225 -0.1115746 0.5845682 0.01578510
nmkbw 0.4423417 0.5635447 0.1791150 -0.2045143 0.1781367 -0.1114576 0.5844313 0.01578639
nloptwrap.NLOPT_LN_NELDERMEAD 0.4434285 0.5612392 0.1765273 -0.2063090 0.1773619 -0.1140108 0.5852130 0.01579032
nloptwrap.NLOPT_LN_BOBYQA 0.4434285 0.5612392 0.1765273 -0.2063090 0.1773619 -0.1140108 0.5852130 0.01579032
Pb_onL:Pb_typeNG Pb_onN:Pb_typeNG Pb_onL:Pb_typeSong Pb_onN:Pb_typeSong
bobyqa -1.140386 -0.1635209 -0.5446501 -0.2497627
Nelder_Mead -1.140380 -0.1635345 -0.5445915 -0.2497404
nlminbwrap -1.140389 -0.1635264 -0.5446236 -0.2497616
nmkbw -1.140884 -0.1640907 -0.5448729 -0.2500731
nloptwrap.NLOPT_LN_NELDERMEAD -1.138619 -0.1624441 -0.5413400 -0.2461967
nloptwrap.NLOPT_LN_BOBYQA -1.138619 -0.1624441 -0.5413400 -0.2461967
$llik
bobyqa Nelder_Mead nlminbwrap nmkbw
-826.3143 -826.3143 -826.3143 -826.3143
nloptwrap.NLOPT_LN_NELDERMEAD nloptwrap.NLOPT_LN_BOBYQA
-826.3143 -826.3143
$sdcor
Site.(Intercept)
bobyqa 1.537530
Nelder_Mead 1.537517
nlminbwrap 1.537501
nmkbw 1.537453
nloptwrap.NLOPT_LN_NELDERMEAD 1.538042
nloptwrap.NLOPT_LN_BOBYQA 1.538042
$theta
Site.(Intercept)
bobyqa 1.537530
Nelder_Mead 1.537517
nlminbwrap 1.537501
nmkbw 1.537453
nloptwrap.NLOPT_LN_NELDERMEAD 1.538042
nloptwrap.NLOPT_LN_BOBYQA 1.538042
$times
user.self sys.self elapsed user.child sys.child
bobyqa 6.51 0 6.55 NA NA
Nelder_Mead 3.06 0 3.06 NA NA
nlminbwrap 2.22 0 2.22 NA NA
nmkbw 2.17 0 2.17 NA NA
nloptwrap.NLOPT_LN_NELDERMEAD 0.94 0 0.94 NA NA
nloptwrap.NLOPT_LN_BOBYQA 0.86 0 0.86 NA NA
$feval
bobyqa Nelder_Mead nlminbwrap nmkbw
3098 1274 NA 672
nloptwrap.NLOPT_LN_NELDERMEAD nloptwrap.NLOPT_LN_BOBYQA
97 97
attr(,"class")
[1] "summary.allFit"
使用car::vif(full_model) 检查共线性结果:
> car::vif(m1_DD)
GVIF Df GVIF^(1/(2*Df))
Pb_on 17.606990 3 1.612925
Pb_type 20.180212 2 2.119490
ZF_Dest 1.015237 1 1.007589
ZF_Other 1.006738 1 1.003364
Pb_on:Pb_type 96.910527 4 1.771317
由于我不是 100% 确定如何解释这些,我使用了 this 链接,这表明我不应该太担心。正如一个答案所述,“GVIF(1/(2×Df))
2020 年 10 月 3 日编辑
经过更多搜索(现在我知道bobyqa 的真正作用,感谢meriops!)我遇到了this thread。阅读那里的答案,我相信我现在的答案如下:
根据 meriops 所说:“glmer 默认使用两阶段优化,第一阶段使用 bobyqa,第二阶段使用 Nelder-Mead。因此,当您将优化器更改为 bobyqa 时,您使用 bobyqa两个阶段。”
根据 Ben Bolker 在 this thread 中的回答,以及我自己的可能性差异
基于上述线程,我现在假设这确实很好。
同样,上述线程表明在我的情况下这不是问题。因为我的模型确实是嵌套的。
如果你们中的任何人希望详细说明您的 cmets 或将它们调整为完整的答案,那么请这样做,然后我会接受它们。
【问题讨论】:
-
summary对象的allFit输出是什么? -
我已将摘要添加为对原始问题的编辑。
-
有趣的是,所有优化器都报告相同的对数似然,但系数略有不同。您检查过预测变量的共线性吗?
-
我不是 100% 确定如何为 glmer 执行此操作。但我尝试了 car::vif(full_model)。这会产生对我来说似乎没问题的结果。以防万一我还将这些添加到原始问题中。
-
glmer默认使用两阶段优化,bobyqa用于第一阶段,Nelder-Mead用于第二阶段。因此,当您将优化器更改为bobyqa时,两个阶段都使用bobyqa。
标签: r warnings lme4 convergence