Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement gridsearch from lcmm? #126

Closed
knokknok opened this issue Feb 6, 2023 · 8 comments
Closed

Implement gridsearch from lcmm? #126

knokknok opened this issue Feb 6, 2023 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@knokknok
Copy link

knokknok commented Feb 6, 2023

No description provided.

@niekdt niekdt added the enhancement New feature or request label Feb 6, 2023
@niekdt
Copy link
Collaborator

niekdt commented Feb 6, 2023

Thanks for the suggestion. I will implement this in the coming weeks

Note that for repeated fitting with automatic selection of the best result you can already use the lcFitRepMin method modifier. Still, the gridsearch approach will be faster since it does an initial quick exploration for different random starts.

library(latrend)
data(latrendData)
method <- lcMethodLcmmGMM(
    fixed = Y ~ Time,
    mixture = ~ Time,
    random = ~ 1,
    id = "Id",
    time = "Time", ,
    nClusters = 2
)

# fit the method but only get the best result out of 10 fits
gmm <- latrend(
  lcFitRepMin(method, rep = 10, metric = 'BIC'),
  data = latrendData
)

@niekdt
Copy link
Collaborator

niekdt commented Mar 14, 2023

@knokknok I've implemented gridsearch initialization, including parallel computation support. See the lcmethodLcmmGMM documentation for details.

Example specification:

  method <- lcMethodLcmmGMM(
    fixed = Y ~ Time,
    mixture = ~ Time,
    random = ~ 1,
    id = "Id",
    time = "Time",
    nClusters = 3,
    init = "gridsearch",
    gridsearch.maxiter = 10,
    gridsearch.rep = 50,
    gridsearch.parallel = TRUE
  )

Let me know if you run into any issues.

@knokknok
Copy link
Author

Thanks!
Out of curiosity, why did you reimplement the grid search functionality instead of calling lcmm's?

@niekdt
Copy link
Collaborator

niekdt commented Mar 15, 2023

Mainly because I already had a custom implementation that I created 4 years ago for a simulation study (see here), which was the basis for creating this package.

I (probably) had a good reason for it at the time but which I don't quite remember haha. Most likely an issue with the hlme call evaluation outside of the global environment, or the annoyance of (re)constructing that call dynamically.

Anyways, using the same parallel back-end as the rest of the latrend package is a nice bonus :)

@niekdt niekdt closed this as completed Mar 16, 2023
@knokknok
Copy link
Author

Sorry to reopen but I get an error when the number of clusters includes 1 in lcMethods (I think it is the trigger):

Error in { :
  task 1 failed - "hasName(x = envir, name = "lme") is not TRUE"

@niekdt
Copy link
Collaborator

niekdt commented Mar 16, 2023

Thanks, I've added this as a test case. Gridsearch init is now ignored for nClusters = 1 so it's easier to estimate lcmm for 1:N clusters.

@niekdt
Copy link
Collaborator

niekdt commented Mar 16, 2023

Unfortunately I submitted the 1.5.1 CRAN release a couple of hours ago so this fix will not be pushed to CRAN until 2 weeks later at minimum.

@niekdt niekdt modified the milestone: 1.5.2 Mar 16, 2023
@niekdt
Copy link
Collaborator

niekdt commented Mar 17, 2023

Since there was a problem with the CRAN submission this fix will be on the 1.5.1 CRAN release.

@niekdt niekdt closed this as completed Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants