我正在尝试使用glmmTMB将零膨胀的Poisson随机效应模型与计数数据进行拟合。但是,我收到了一些错误和警告。
head(data)
count time study
1 0 259 1
2 0 199 1
3 0 571 1
4 0 927 1
5 7 254 1
6 0 877 1
str(data)
'data.frame': 959 obs. of 3 variables:
$ count : int 0 0 0 0 7 0 0 0 0 0 ...
$ time : int 259 199 571 927 254 877 555 158 1014 705 ...
$ study : Factor w/ 10 levels "1","2","3","4",..: 1 1 1 1 1 1 1 1 1 1 ...
时间是一个偏移项,学习是我必须添加的随机效应。
错误1
如果我添加随机效应,则以下随机效应模型报告相同的错误
f1<-glmmTMB(count~1+offset(time)+1|study, data = data, family = poisson, ziformula = ~1|study)
f2<-glmmTMB(count~1+offset(time)+1|study, data = subset(data, study=="1"), family = poisson, ziformula = ~1|study)
NA/NaN function evaluationError in nlminb(start = par, objective = fn, gradient = gr, control = control$optCtrl) :
gradient function must return a numeric vector of length 4
错误2
我认为我需要尝试一个更简单的模型,因此我放弃了随机效应。不幸的是,我收到了另一个错误。
f3<-glmmTMB(count~1+offset(time), data = data, family = poisson, ziformula = ~1)
f4<-glmmTMB(count~1+offset(time), data = subset(data, study=="1"), family = poisson, ziformula = ~1)
NA/NaN function evaluationError in nlminb(start = par, objective = fn, gradient = gr, control = control$optCtrl) :
NA/NaN gradient evaluation
警告1
好。我不知道如何获得没有错误的输出。因此,我放弃了偏移项而不是随机效应,从而获得了警告而不是错误。
f5<-glmmTMB(count~1+1|study, data = data, family = poisson, ziformula = ~1|study)
f6<-glmmTMB(count~1+1|study, data = subset(data, study=="1"), family = poisson, ziformula = ~1|study)
Cholmod warning 'matrix not positive definite' at file ../Supernodal/t_cholmod_super_numeric.c, line 729Cholmod warning 'matrix not positive definite' at file ../Supernodal/t_cholmod_super_numeric.c, line 729Cholmod warning 'matrix not positive definite' at file ../Supernodal/t_cholmod_super_numeric.c, line 729Cholmod warning 'matrix not positive definite' at file ../Supernodal/t_cholmod_super_numeric.c, line 729Cholmod warning 'matrix not positive definite' at file ../Supernodal/t_cholmod_super_numeric.c, line 729Cholmod warning 'matrix not positive definite' at file ../Supernodal/t_cholmod_super_numeric.c, line 729Cholmod warning 'matrix not positive definite' at file ../Supernodal/t_cholmod_super_numeric.c, line 729Cholmod warning 'matrix not positive definite' at file ../Supernodal/t_cholmod_super_numeric.c, line 729
“好”,既没有错误也没有警告
经过一堆修改后,我发现如果我放弃两个随机效应项和偏移项中的至少一个,模型将不会报告错误或警告。
f7<-glmmTMB(count~1+1|study, data = data, family = poisson, ziformula = ~1)
f8<-glmmTMB(count~1, data = data, family = poisson, ziformula = ~1|study)
问题
哪些问题导致了这些错误和警告?如果可能的话,我该如何拟合ZIP混合效果模型并且既不会收到错误也不会收到警告?
示例
我有一个可复制的示例,它产生了警告1
count.ex<-rpois(500, 0.2)
study.ex<-as.factor(sample(1:5, 500, replace = TRUE))
time.ex<-rexp(500, 150)
fit.ex<-glmmTMB(count.ex~1+offset(time.ex)+1|study.ex, family = poisson, ziformula = ~1|study.ex)
Cholmod warning 'matrix not positive definite' at file ../Supernodal/t_cholmod_super_numeric.c, line 729Cholmod warning 'matrix not positive definite' at file ../Supernodal/t_cholmod_super_numeric.c, line 729Cholmod warning 'matrix not positive definite' at file ../Supernodal/t_cholmod_super_numeric.c, line 729Model convergence problem; non-positive-definite Hessian matrix. See vignette('troubleshooting')
答案 0 :(得分:1)
没有可复制的示例,这相当困难!
模型存在一个明显的问题:您在模型中指定了offset(time)
,几乎可以肯定要使用offset(log(time))
。您的time
值很大(我在您的str()
中看到的值范围为500-1000;偏移量在模型中以<{1>}输入预测的值,它要么太大(如果`offset
您应注意用括号保护随机效应术语(例如,您使用exp(offset)
而不是~1 + 1|study
;我认为这不会在此处显示的示例中引起问题,但通常,管道(~1 + (1|study)
)运算符的优先级较低,这意味着|
等效于~1+a+b|study
...
如果我使用
~(1+a+b)|study
在您的示例中,我没有收到任何警告。