CecileProust-Lima / lcmm

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

Error in mla(b=b, m=length(b), fn=logliklcmm, clustertype=clustertype,: NA/ NaN/ Inf in foreign function call (arg 1) #272

Closed eugealcalde closed 1 month ago

eugealcalde commented 2 months ago

Dear Cécile, dear Viviane,

First, thank you very much for the amazing work you have achieved with this package.

I'm having issues while trying to model trajectories based on an outcome with a skewed distribution (count data). I removed outliers to obtain different distributions (following Tukey's rule with an inner face at the 10th and 90th deciles and the 15th and 85th...) Even if it is still far from being Gaussian, I was able to use a spline link function (default option) in my lcmm command, and the models converged properly (after long hours/days).

Somehow, in my last attempts in which I slightly modified my models (filtered some IDs based on inclusion criteria and re-cleaned my outcome), I got this error message: "Error in mla(b=b, m=length(b), fn=logliklcmm, clustertype=clustertype,: NA/ NaN/ Inf in foreign function call (arg 1)

Model having only 1 class ran perfectly using "splines", but models 3 and 4 stopped running after 100ish iterations.

mod1 <- lcmm(outcome ~ ns(months,knots=(12,50),Boundary.knots=c(0,80)), random= ~ns(months,knots=(12,50),Boundary.knots=c(0,80)), subject="Id", maxiter=200, link="splines", data=data, nproc=6, verbose=TRUE)

mod4 <- lcmm(outcome ~ ns(months,knots=(12,50),Boundary.knots=c(0,80)), random= ~ns(months,knots=(12,50),Boundary.knots=c(0,80)), mixture=~ns(months,knots=(12,50),Boundary.knots=c(0,80)), B=mod1, posfix=34, ng=4, subject="Id", maxiter=2000, link="splines", data=data, nproc=6, verbose=TRUE) (--> posfix=34 because I noticed this parameter was close to 0 while iterating (~10−^4) )

Any suggestions? Any help or insights would be very much appreciated.

My data set has around 4800 IDs with 91100 observations. I'm using lcmm version 2.1.0 and R 4.3.0.

VivianePhilipps commented 2 months ago

Hi,

this message indicates that the algorithm got infinite parameters. In order to avoid losing all the computations, you can go sequentially by launching the model with maxiter = 50 and then do a second run by starting form the previous results, and so on. So, if the 3rd run results in an error, you keep the 100 first iterations and can try to modify slightly theses values. It can be enough to avoid the "infinite parameter area". I see that you are not using the gridsearch for the 4 class model. This would be better as it tries for you many different starting values.

Best,

Viviane