CecileProust-Lima / lcmm

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

Number of iterations in result of models run with gridsearch() #257

Closed LauraSirucek closed 2 months ago

LauraSirucek commented 3 months ago

Dear Cécile,

I am using your lcmm package and the function hlme() to identify latent classes in how "ppt" (pressure pain thresholds; a measure of pain sensitivity) changes over time/in response to an intervention (categorical variable; "before"/"during"/"after" the intervention) in a sample of patients with chronic pain and pain-free volunteers (id_num).

As instructed in your paper, I first ran a 1-Class model. In this model, gender turned out to be a significant predictor of ppt, thus we also included it in the baseline model. I then ran a 2-Class model with the initial parameter values from the 1-Class model as starting point. After that, I wanted to try the gridsearch() option because trying multiple random vectors of initial values made sense to me.

Now, what surprised me is, that the 2-Class model with the initial parameter values from the 1-Class model converged after 11 iterations, while the gridsearch() approach converged after only one iteration. I also ran a 3-Class and a 4-Class model and, to better understand the LCMM approach, with different "rep" and "maxiter" values. Surprisingly, all gridsearch() approaches resulted in number of iteration = 1 for almost all models (while the respective models without gridsearch() all converged after a higher number of iterations).

Thus, my questions are:

  1. Does it make sense that the model without gridsearch() always results in a different number of iterations for the optimization algorithm than the model with gridsearch()?
  2. Should I be worried when the model converges after 1 iteration?
  3. Or is there simply an error in the code or am I misinterpreting the meaning of "number of iterations"? :)

Here is my code and the results displaying the number of iterations:

1-Class Model:

lcmm_ppt_cpm_m1.2 <- hlme(ppt ~ timepoint + gender, random=~1, subject="id_num", data =cpm_ppt_con, ng=1)
summary(lcmm_ppt_cpm_m1.2)

Result:

hlme(fixed = ppt ~ timepoint + gender, random = ~1, subject = "id_num", ng = 1, data = cpm_ppt_con)

Statistical Model:

Dataset: cpm_ppt_con Number of subjects: 140 Number of observations: 417 Number of observations deleted: 3 Number of latent classes: 1 Number of parameters: 6

Iteration process: Convergence criteria satisfied Number of iterations: 6 Convergence criteria: parameters= 3.2e-07 : likelihood= 6.9e-06 : second derivatives= 4.7e-13

2-Class Model - Without gridsearch:

set.seed(200)
lcmm_ppt_cpm_m2 <- hlme(ppt ~ timepoint + gender , random=~1,mixture=~timepoint, subject="id_num", data =cpm_ppt_con, ng=2, B=lcmm_ppt_cpm_m1.2)

summary(lcmm_ppt_cpm_m2)

Result:

hlme(fixed = ppt ~ timepoint + gender, mixture = ~timepoint, random = ~1, subject = "id_num", ng = 2, data = cpm_ppt_con)

Statistical Model: Dataset: cpm_ppt_con Number of subjects: 140 Number of observations: 417 Number of observations deleted: 3 Number of latent classes: 2 Number of parameters: 10

Iteration process: Convergence criteria satisfied Number of iterations: 11 Convergence criteria: parameters= 3.7e-08 : likelihood= 7.9e-08 : second derivatives= 1.3e-14

2-Class Model - With gridsearch:

set.seed(200)
lcmm_ppt_cpm_m2_iter <- gridsearch(hlme(ppt ~ timepoint + gender, random=~1,mixture=~timepoint, subject="id_num", data =cpm_ppt_con, ng=2), rep=30, maxiter=15, minit=lcmm_ppt_cpm_m1.2)

summary(lcmm_ppt_cpm_m2_iter)

Result:

hlme(fixed = ppt ~ timepoint + gender, mixture = ~timepoint, random = ~1, subject = "id_num", ng = 2, data = cpm_ppt_con)

Statistical Model: Dataset: cpm_ppt_con Number of subjects: 140 Number of observations: 417 Number of observations deleted: 3 Number of latent classes: 2 Number of parameters: 10

Iteration process: Convergence criteria satisfied Number of iterations: 1 Convergence criteria: parameters= 4.1e-11 : likelihood= 3e-10 : second derivatives= 6e-11

Thank you very much in advance for your help with this issue and kind regards, Laura

VivianePhilipps commented 3 months ago

Hi Laura,

it is not a problem that the model converged in 1 iteration. It corresponds to the number of iterations after the 15 iterations (because you specified maxiter = 15) you did as a first step in the gridsearch.

Viviane