CecileProust-Lima / lcmm

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

Choose number of classes and plot models estimated with thresholds function #146

Closed idborquez closed 1 year ago

idborquez commented 1 year ago

Hi,

I am trying to apply a Latent Class Growth Analysis with the lcmm package with a binary outcome using the threshold function. I have 8649 observations over 21 periods of time. To choose the number of latent classes I first estimated 8 models with the following code:

set.seed(2002)
registerDoParallel(cores=16)
mod=list()
mod[[1]]=lcmm(fixed = treat_use ~ month, 
              random=~1, 
              link="thresholds",
              subject = "id", 
              data = long,
              maxiter = 500,
              verbose = TRUE)

for (k in 2:8){
cl <- makeCluster(16)
clusterExport(cl,list("k"),environment())
mod[[k]]=gridsearch(rep = 20, maxiter = 100, minit = mod[[1]],
                    lcmm(fixed = treat_use ~ month,
                         mixture = ~ month,
                         random=~1, 
                         link="thresholds",
                         subject = "id",
                         ng=k,
                         data = long,
                         maxiter = 500,
                         verbose = TRUE),
                         cl=cl)
stopCluster(cl)
}

After getting the summary of the 8 models I am trying to choose the model but the BIC keeps getting lower, and the LMR-LRT keeps being significant, although I have classes with 3% in the data. Now I want to plot the trajectories but the plot and predictY functions don't work as I am getting this message "This function is not available for thresholds mixed models". Therefore, I was wondering how could I estimate a plot where I could see the prediction of each class in each time point and therefore choose, on a more substantive matter, how many classes I stay with.

Thanks in advance

CecileProust-Lima commented 1 year ago

HI, for selecting the best model, you could also look at the ICL and entropy summaries in the options of the summarytable function. For plotting trajectories from probit models, we indeed did not implement everything in the lcmm function. We did it in the multlcmm function which is more flexible and uses quasiMC for the integration in the likelihood.

I would suggest to use multlcmm instead. Please refer to the vignette:

https://cran.r-project.org/web/packages/lcmm/vignettes/latent_process_model_with_multlcmm_IRT.html

for an example with the predictions included. Cécile

idborquez commented 1 year ago

Thanks Cecile, the work you've done with this package is amazing! I'll review the multlcmm vignette.