我正在使用一个伽马分布的多变量模型,我想利用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')我想,解决方案可能取决于控制参数,但在查看故障排除小插曲后,我不确定从哪里开始。
发布于 2019-11-20 05:07:08
一种解决方案是缩放变量(只要它们是数字)。
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 ***这是因为估计值是基于缩放参数的,所以必须谨慎地解释它们,否则就是“不缩放”。要了解scale()函数的作用,请参阅:Understanding scale in R;要更深入地了解模型中的含义,请参阅:interpretation of scaled regression coefficients...
最后,模型收敛的事实并不意味着它们是很好的匹配。
https://stackoverflow.com/questions/56176678
复制相似问题