【问题标题】:Non-converging glmmTMB非收敛 glmmTMB
【发布时间】:2019-11-20 05:07:08
【问题描述】:

我正在使用具有 Gamma 分布的多变量模型,我想使用 glmmTMB 中部署的 lme4 语法,但是,我注意到我的模型有些奇怪。显然,当我使用stats::glm 时,模型很容易收敛,但似乎在glmmTMB 框架中出现错误。这是一个可重现的示例:

d <- data.frame(gamlss.data::plasma) # Sample dataset

m4.1 <- glm(calories ~ fat*fiber, family = Gamma(link = "log"), data = d)    # Dos parámetros con interacción
m4.2 <- glmmTMB(calories ~ fat*fiber, family = Gamma(link = "log"), data = d)    # Dos parámetros con interacción

>Warning message:
In fitTMB(TMBStruc) :
  Model convergence problem; non-positive-definite Hessian matrix. See vignette('troubleshooting')

我想,解决方案可能在于控制参数,但在查看故障排除小插曲后,我不确定从哪里开始。

【问题讨论】:

    标签: r glm


    【解决方案1】:

    一种解决方案可以是缩放变量(只要它们是数字的)。

    d <- data.frame(gamlss.data::plasma) # Sample dataset
    
    m4.1 <- glm(calories ~ fat*fiber, family = Gamma(link = "log"), data = d)    
    m4.2 <- glmmTMB(calories ~ scale(fat)*scale(fiber), family = Gamma(link = "log"), data = d) 
    

    在这里,第二个模型收敛得很好,而之前没有。 但是,请注意两个模型在参数估计上的差异:

    > summary(m4.1)
    
    Call:
    glm(formula = calories ~ fat * fiber, family = Gamma(link = "log"), 
        data = d)
    
    Deviance Residuals: 
         Min        1Q    Median        3Q       Max  
    -0.42031  -0.07605  -0.00425   0.07011   0.60073  
    
    Coefficients:
                  Estimate Std. Error t value Pr(>|t|)    
    (Intercept)  6.120e+00  5.115e-02 119.654   <2e-16 ***
    fat          1.412e-02  6.693e-04  21.104   <2e-16 ***
    fiber        5.108e-02  3.704e-03  13.789   <2e-16 ***
    fat:fiber   -4.092e-04  4.476e-05  -9.142   <2e-16 ***
    
    (Dispersion parameter for Gamma family taken to be 0.0177092)
    
        Null deviance: 40.6486  on 314  degrees of freedom
    Residual deviance:  5.4494  on 311  degrees of freedom
    AIC: 4307.2
    
    Number of Fisher Scoring iterations: 4
    ______________________________________________________________
    > summary(m4.2)
    Family: Gamma  ( log )
    Formula:          calories ~ scale(fat) * scale(fiber)
    Data: d
    
         AIC      BIC   logLik deviance df.resid 
      4307.2   4326.0  -2148.6   4297.2      310 
    
    
    Dispersion estimate for Gamma family (sigma^2): 0.0173 
    
    Conditional model:
                             Estimate Std. Error z value Pr(>|z|)    
    (Intercept)              7.458146   0.007736   964.0   <2e-16 ***
    scale(fat)               0.300768   0.008122    37.0   <2e-16 ***
    scale(fiber)             0.104224   0.007820    13.3   <2e-16 ***
    scale(fat):scale(fiber) -0.073786   0.008187    -9.0   <2e-16 ***
    

    这是因为估算值基于缩放参数,因此必须谨慎解释,或“未缩放”。看: Understanding `scale` in R 了解 scale() 函数的作用,请参阅:interpretation of scaled regression coefficients... 以更深入地了解这在模型中的含义

    最后一点,模型收敛的事实并不意味着它们非常适合。

    【讨论】:

      猜你喜欢
      • 2019-09-22
      • 1970-01-01
      • 1970-01-01
      • 2013-05-10
      • 2015-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-21
      相关资源
      最近更新 更多