Closed HJardel closed 1 year ago
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.
Tom, thanks. I understand #550 has solved the problem, so I'm closing.
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")
)
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.