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

Error with multivariable flexmix model #161

Open
danielapacella opened this issue Nov 30, 2024 · 2 comments
Open

Error with multivariable flexmix model #161

danielapacella opened this issue Nov 30, 2024 · 2 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@danielapacella
Copy link

When the method <- lcMethodFlexmix includes a multivariable model hence with covariates (e.g. in the form y~ a+ b + c), ClusterTrajectories and plotClusterTrajectories return an error from the predict function
Error in eval(predvars, data, env) : object 'c' not found.

This happens because of this part of the code below

setMethod('clusterTrajectories', 'lcModel', function(object, at = time(object), what = 'mu', ...) {
  newdata = data.table(
    Cluster = rep(clusterNames(object, factor = TRUE), each = length(at)),
    Time = at
  ) %>%
    setnames('Time', timeVariable(object))

where simulated data is created without taking into account covariates.

@niekdt niekdt added the bug Something isn't working label Dec 3, 2024
@niekdt
Copy link
Collaborator

niekdt commented Dec 3, 2024

Hi Daniela, thanks for reporting this. That is quite the oversight when I implemented the method, oops. I'll need to look into what's the best way to add support for this.

In the meantime, you can compute the cluster trajectories yourself, as it's really just a helper function that relies on the predict implementation of the outputted model.

Something like:

library(data.table)
newdata = data.table(
    Cluster = rep(clusterNames(model, factor = TRUE), each = length(at)),
    Time = at,
    a = 0, # change this to desired value
    b = 0, #
    c = 0 #
  ) %>%
    setnames('Time', timeVariable(object))

dfClusterTrajectories = predict(model, newdata = newdata, what = 'mu')

Please let me know if this works. Covariate support is a bit finicky across models.

@niekdt niekdt self-assigned this Dec 3, 2024
@danielapacella
Copy link
Author

Thanks for the answer. Yes, I had already solved temporarily the issue adding the covariates the same way you showed. Unfortunately, most of the functions after the model fitting rely on helper functions that call predict, including plots etc. so I needed to extract them from the code and running them manually. I hope you will add support for that in the future.

@niekdt niekdt added this to the 1.6.2 milestone Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants