2

Usually my mixed models contain several categorical variables with a lot of unique levels, so X matrix is ​​very sparse.
I use glmmTMB package that handles X and Z matrices as sparse. This significantly reduced RAM usage during fitting the model.
The glmmTMB package is great, but there is one problem for me (maybe I'm missing something):
when I use interactions between a numeric variable and a categorical variable (as FE), the model is fitted without errors.
For example, this model works well:

fit = glmmTMB(Y ~ 0 + num1:factor1 + num2:factor1 + factor2 + 
(0 + num3|subject) + (0 + num4|subject) + (1|subject), 
model_data, REML = TRUE, sparseX=c(cond=TRUE))

But when I use any interactions between two categorical variables i.e. the formula looks like this:

fit = glmmTMB(Y ~ 0 + num1:factor1 + factor3:factor1 + factor2 + 
(0 + num2|subject) + (0 + num3|subject) + (1|subject), 
model_data, REML = TRUE, sparseX=c(cond=TRUE)),

I get the following error:

iter: 5  Error in newton(par = c(beta = 1, beta = 1, beta = 1, beta = 1, beta = 1,  : 
  Newton failed to find minimum.
In addition: Warning message:
In (function (start, objective, gradient = NULL, hessian = NULL,  :
  NA/NaN function evaluation
outer mgc:  NaN 
Error in (function (start, objective, gradient = NULL, hessian = NULL,  : 
  gradient function must return a numeric vector of length 4

At the same time, in mixed model theory, interactions between two categorical variables are valid.
Moreover, such model (with interactions between two factors) is successfully fitted with Julia MixedModels package.

Could you help me, please, to understand root of this error?
Is there a way to avoid it in a model with interactions between two categorical variables?
Why does such models work with Julia MixedModels and not work with glmmTMB?

red_quark
  • 971
  • 5
  • 20

0 Answers0