CecileProust-Lima / lcmm

R package lcmm
https://CecileProust-Lima.github.io/lcmm/
54 stars 13 forks source link

hlme computing error #223

Closed LeaChauveau closed 9 months ago

LeaChauveau commented 11 months ago

Dear developers,

Thanks a lot for providing the lcmm package! I'm currently learning how to use it. Most of the time, it works well but sometimes when I'm trying to compute more than 2 classes with several class memberships in hlme, I'm facing this error:

Numerical problem by computing fn value of function is : NaN

The error has already been documented, and you advised to try with different initial values in argument B. I'm currently using the estimated parameters of the 1-class hlme model but I've read that I could specified my own vector values. However, I do know exactly which values I should choose and if this would fix the error. (I'v also tried to change the max number of iterations)

Here is my current code:

hlme1 <- hlme(Y ~ X1 + c1+ c2+ c3+ c4, random = ~ X1, subject = "id", ng = 1, data = df.analyses)
summary(hlme1)

hlme2 <- hlme(Y ~ X1 + c1+ c2+ c3+ c4, random = ~ X1, subject = "id", ng = 2, data = df.analyses, mixture = ~ X1, classmb = ~ X2+ X3, B = hlme1)
summary(hlme2)

hlme3 <- hlme(Y ~ X1 + c1+ c2+ c3+ c4, random = ~ X1, subject = "id", ng = 3, data = df.analyses, mixture = ~ X1, classmb = ~ X2+ X3, B = hlme1)
summary(hlme3)

hlme4 <- hlme(Y ~ X1 + c1+ c2+ c3+ c4, random = ~ X1, subject = "id", ng = 4, data = df.analyses, mixture = ~ X1, classmb = ~ X2+ X3, B = hlme1)
summary(hlme4)

hlme5 <- hlme(Y ~ X1 + c1+ c2+ c3+ c4, random = ~ X1, subject = "id", ng = 5, data = df.analyses, mixture = ~ X1, classmb = ~ X2+ X3, B = hlme1)
summary(hlme5) 

The error occurs at hlme3, hlme4 and hlme5. Curiously, when changing Y values, models hlme3 and hlme4 are computed.

Surprisingly, when I'm scaling X3, hlme3 is computed but the variance-covariance matrix of the random-effects seems empty. When I'm completely removing X3, all 5 models are computed (but no p-values from hlme4).

Although I don't think a high number of classes is relevant to my analysis, I'd still like to be able to compare models to support my choice of a lower number of classes.

Do you have any suggestion to fix the error?

Thank you in advance!

VivianePhilipps commented 10 months ago

Hi,

this should be fixed by changing the initial values. See my answer in #220. Here you could try by running the models with B=random(hlme1), or better with gridsearch, to start from different sets of initial values.

Viviane