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

locally defined imputation method does not work with futuremice #529

Closed
HJardel opened this issue Jan 11, 2023 · 3 comments
Closed

locally defined imputation method does not work with futuremice #529

HJardel opened this issue Jan 11, 2023 · 3 comments

Comments

@HJardel
Copy link

HJardel commented Jan 11, 2023

I have code using mice that works fine but takes a long time. It uses a custom function as a default (called mice.impute.logreg_2). When I try to use futuremice (just changing "mice" from "futuremice"), I get an error:
Error in get(fn) : object 'mice.impute.logreg_2' not found.
My best guess is this is has to do with how the futures package is called and needing to specify it as an additional global. I figured it might be worth a patch to make futuremice as interchangeable with mice as possible.

@thomvolker
Copy link
Member

As a quick fix, you can clone the mice package from GitHub, add your function as an imputation function and rebuild the package. In this way, I presume that futuremice will locate your function, which then means that you can proceed.

I will dive in the issue, but don't have time to do so right now.

@stefvanbuuren
Copy link
Member

Tom, thanks. I understand #550 has solved the problem, so I'm closing.

@oloverm
Copy link

oloverm commented Mar 11, 2024

For reference, the solution is to pass in any locally defined functions, as well as objects (such as the predictor matrix or vector of methods), to globals. For example:

imputed <- mice::futuremice(
  to_impute, 
  predictorMatrix = imputation_predictor_matrix,
  method = imputation_methods,
  globals = c("imd_score_to_quintile", "imputation_predictor_matrix", "imputation_methods")
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants