【问题标题】:Catching the convergence or not by glmer in R在 R 中通过 glmer 捕捉收敛与否
【发布时间】:2015-03-24 02:18:26
【问题描述】:

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

即使有分歧,它也永远不会回报我`

【问题讨论】:

    标签: r glm convergence


    【解决方案1】:

    无论如何,我不会反对一般的警告机制,就像我们都已经做过的那样。我无法将警告日志归零或重置。它相当有效地隐藏起来。相反,看看对象,说它的名字是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
    

    【讨论】:

      【解决方案2】:

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

      obj <- glm(y ~ x, ...) # model specification
      if (obj$converged) { 
      # do stuff
      } else { 
      # do something else 
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-01-14
        • 2017-07-15
        • 1970-01-01
        • 1970-01-01
        • 2018-11-11
        • 1970-01-01
        • 2019-06-05
        相关资源
        最近更新 更多