我正在使用 glmer 函数进行模拟。对于我提取的每个模拟 估计,...到数据库中,但我也想有一个变量 指示模拟数据是否正确收敛。 (我收到警告,例如奇异收敛、错误收敛……但无论如何都会给出估计值)。
我试试
assign("last.warning", NULL, envir = baseenv()) # clear the previous warning
mod1=glmer(y~x+(1+x|study), family="binomial", data=test1)
warningss1=ifelse(length(warnings())>0, "yes", "no"); warningss1
它永远不会返回我,即使它有分歧`
最佳答案
无论如何,我不会反对一般的警告机制,就像我们俩已经做过的那样。我无法找到将警告日志清零或重置的方法。它被相当有效地隐藏起来。而是查看对象,假设它的名称是 gm1
,您将无法收敛。 (我只是减少了样本量,直到发生收敛失败。):
gm1@optinfo$conv$lme4$messages
#[1] "Model failed to converge with max|grad| = 0.10941 (tol = 0.001, component 5)"
#[2] " Hessian is numerically singular: parameters are not uniquely determined"
any( grepl("failed to converge", gm1@optinfo$conv$lme4$messages) )
#[1] TRUE
#with a convergent run:
> any( grepl("failed to converge", gm1@optinfo$conv$lme4$messages) )
#[1] FALSE
> gm1@optinfo$conv$lme4$messages
#NULL
关于r - 在 R 中通过 glmer 捕捉收敛与否,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29223906/