3

我正在使用 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

它永远不会回报我,即使它不同`

4

2 回答 2

5

无论如何,我不会像我们俩已经做过的那样,对警告的一般机制大发雷霆。我无法将警告日志归零或重置。它相当有效地隐藏起来。而是看对象,说它的名字是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
于 2015-03-24T06:12:01.403 回答
0

我一直在寻找解决同一问题的方法,但偶然发现了这个问题。经过更多研究后,我发现以下工作(至少对于 glm-models):

obj <- glm(y ~ x, ...) # model specification
if (obj$converged) { 
# do stuff
} else { 
# do something else 
}
于 2021-10-05T12:50:03.453 回答