英文:
Problem with glmmTMB function in R: gives NaN in summary
问题
I have a large motor insurance dataset with which I want to make a mixed model regression to model the expected claim frequency using glmmTMB, with the purpose of determining an initial base premium.
My script looks like this:
glmmTMB(response ~ Var1 + Var2 + Var3 + ... +
offset(log(exposure_level) + (1|policy_id),
data = data,
family = nbinom1(link = "log"))
No matter what I do I get warnings regarding NaN and convergence and the p-value, std, z value, AIC, BIC, logLik and deviance in the summary are all NaN.
I get the following warnings:
Warning messages:
1: In .checkRankX(TMBStruc, control$rank_check) :
fixed effects in conditional model are rank deficient
2: In (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
3: In (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
4: In fitTMB(TMBStruc) :
Model convergence problem; non-positive-definite Hessian matrix. See vignette('troubleshooting')
5: In fitTMB(TMBStruc) :
Model convergence problem; false convergence (8). See vignette('troubleshooting')
I have tried grouping the data more and leaving out variables, but it does not seem that I can fix the issues. No matter what I try the warnings and NaN still shows.
Has anyone experienced the same and know how to solve the problem?
英文:
I have a large motor insurance dataset with which I want to make a mixed model regression to model the expected claim frequency using glmmTMB, with the purpose of determining an initial base premium.
My script looks like this:
glmmTMB(response ~ Var1 + Var2 + Var3 + ... +
offset(log(exposure_level) + (1|policy_id),
data = data,
family = nbinom1(link = "log"))
No matter what I do I get warnings regarding NaN and convergence and the p-value, std, z value, AIC, BIC, logLik and deviance in the summary are all NaN.
I get the following warnings:
> Warning messages: <br>
> 1: In .checkRankX(TMBStruc, control$rank_check) :
fixed effects in conditional model are rank deficient<br>
> 2: In (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation<br>
> 3: In (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation<br>
> 4: In fitTMB(TMBStruc) :
Model convergence problem; non-positive-definite Hessian matrix. See vignette('troubleshooting')<br>
> 5: In fitTMB(TMBStruc) :
Model convergence problem; false convergence (8). See vignette('troubleshooting')
I have tried grouping the data more and leaving out variables, but it does not seem that I can fix the issues. No matter what I try the warnings and NaN still shows.
Has anyone experienced the same and know how to solve the problem?
答案1
得分: 1
The key is
> 在.checkRankX(TMBStruc, control$rank_check)中:条件模型中的固定效应秩亏
如果您在模型拟合中添加参数control = glmmTMBControl(rank_check = "adjust")
,它应该会自动处理这个问题。
这意味着您的预测变量集中存在多重共线性列(有很多原因会导致这种情况:与某些组合缺失的交互作用、完全描述一组分类选项的虚拟变量、常量列...)
例如:
library(glmmTMB)
data("sleepstudy", package = "lme4")
ss <- transform(sleepstudy, Days2 = Days)
m <- glmmTMB(Reaction ~ Days + Days2 + (1|Subject),
data = ss,
control = glmmTMBControl(rank_check = "adjust"))
这会产生消息(不再是警告)
> 从秩亏的条件模型中删除列:Days2
英文:
The key is
> In .checkRankX(TMBStruc, control$rank_check) : fixed effects in conditional model are rank deficient
If you add the argument control = glmmTMBControl(rank_check = "adjust")
to your model fit, it should take care of this automatically.
This means that you have multicollinear columns in your set of predictor variables (there are lots of reasons this happens: interactions with some combinations missing, dummy variables that completely describe a set of categorical options, constant columns ...)
For example:
library(glmmTMB)
data("sleepstudy", package = "lme4")
ss <- transform(sleepstudy, Days2 = Days)
m <- glmmTMB(Reaction ~ Days + Days2 + (1|Subject),
data = ss,
control = glmmTMBControl(rank_check = "adjust"))
which gives the message (not a warning any more)
> dropping columns from rank-deficient conditional model: Days2
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论