amices / mice

Multivariate Imputation by Chained Equations
https://amices.org/mice/
GNU General Public License v2.0
441 stars 107 forks source link

`Error: object 'mice.impute.2l.pmm' not found` when using `futuremice()` #635

Closed isaactpetersen closed 5 months ago

isaactpetersen commented 5 months ago

I am having an issue with the futuremice() function. I receive an error when using 2l.pmm as the imputation method (from the miceadds package) with the futuremice() function:

Error:
i In index: 1.
Caused by error in `get()`:
! object 'mice.impute.2l.pmm' not found

I do not receive the error when using the mice function.

Here is a reprex:

library("tidyverse")
library("mice")
#> 
#> Attaching package: 'mice'
#> The following object is masked from 'package:stats':
#> 
#>     filter
#> The following objects are masked from 'package:base':
#> 
#>     cbind, rbind
library("miceadds")
#> * miceadds 3.17-44 (2024-01-08 19:08:24)

data(Oxboys, package = "nlme")

Oxboys_addNA <- data.frame(Oxboys)
Oxboys_addNA <- Oxboys_addNA %>% 
  rename(id = Subject)

Oxboys_addNA$id <- as.integer(Oxboys_addNA$id)
Oxboys_addNA$Occasion <- as.integer(Oxboys_addNA$Occasion)

set.seed(52242)
Oxboys_addNA[sample(1:nrow(Oxboys_addNA), 25), "height"] <- NA

dataToImpute <- Oxboys_addNA
varsToImpute <- c("height")
Y <- varsToImpute

numImputations <- 5

meth <- make.method(dataToImpute)
meth[1:length(meth)] <- ""
meth[Y] <- "2l.pmm"

pred <- make.predictorMatrix(dataToImpute)
pred[1:nrow(pred), 1:ncol(pred)] <- 0
pred[Y, "id"] <- (-2) # cluster variable
pred[Y, "Occasion"] <- 1 # fixed effect predictor
pred[Y, "age"] <- 2 # random effect predictor
pred[Y, Y] <- 1 # fixed effect predictor

diag(pred) <- 0

mi_mice <- mice(
  as.data.frame(dataToImpute),
  method = meth,
  predictorMatrix = pred,
  m = numImputations,
  maxit = 5)
#> 
#>  iter imp variable
#>   1   1  height
#>   1   2  height
#>   1   3  height
#>   1   4  height
#>   1   5  height
#>   2   1  height
#>   2   2  height
#>   2   3  height
#>   2   4  height
#>   2   5  height
#>   3   1  height
#>   3   2  height
#>   3   3  height
#>   3   4  height
#>   3   5  height
#>   4   1  height
#>   4   2  height
#>   4   3  height
#>   4   4  height
#>   4   5  height
#>   5   1  height
#>   5   2  height
#>   5   3  height
#>   5   4  height
#>   5   5  height

mi_parallel_mice <- futuremice(
  dataToImpute,
  method = meth,
  predictorMatrix = pred,
  m = numImputations,
  maxit = 5)
#> Error:
#> ℹ In index: 1.
#> Caused by error in `get()`:
#> ! object 'mice.impute.2l.pmm' not found

sessionInfo()
#> R version 4.3.2 (2023-10-31)
#> Platform: x86_64-apple-darwin20 (64-bit)
#> Running under: macOS Sonoma 14.4.1
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRblas.0.dylib 
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0
#> 
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> time zone: America/Chicago
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#>  [1] miceadds_3.17-44 mice_3.16.0      lubridate_1.9.3  forcats_1.0.0   
#>  [5] stringr_1.5.1    dplyr_1.1.4      purrr_1.0.2      readr_2.1.5     
#>  [9] tidyr_1.3.1      tibble_3.2.1     ggplot2_3.5.0    tidyverse_2.0.0 
#> 
#> loaded via a namespace (and not attached):
#>  [1] gtable_0.3.4      shape_1.4.6.1     xfun_0.43         lattice_0.22-6   
#>  [5] tzdb_0.4.0        vctrs_0.6.5       tools_4.3.2       generics_0.1.3   
#>  [9] parallel_4.3.2    fansi_1.0.6       pan_1.9           pkgconfig_2.0.3  
#> [13] jomo_2.7-6        Matrix_1.6-5      lifecycle_1.0.4   compiler_4.3.2   
#> [17] munsell_0.5.1     mitools_2.4       codetools_0.2-20  htmltools_0.5.8.1
#> [21] yaml_2.3.8        glmnet_4.1-8      furrr_0.3.1       pillar_1.9.0     
#> [25] nloptr_2.0.3      MASS_7.3-60.0.1   iterators_1.0.14  rpart_4.1.23     
#> [29] boot_1.3-30       foreach_1.5.2     mitml_0.4-5       parallelly_1.37.1
#> [33] nlme_3.1-164      tidyselect_1.2.1  digest_0.6.35     future_1.33.2    
#> [37] stringi_1.8.3     listenv_0.9.1     splines_4.3.2     fastmap_1.1.1    
#> [41] grid_4.3.2        colorspace_2.1-0  cli_3.6.2         magrittr_2.0.3   
#> [45] survival_3.5-8    utf8_1.2.4        broom_1.0.5       withr_3.0.0      
#> [49] scales_1.3.0      backports_1.4.1   timechange_0.3.0  rmarkdown_2.26   
#> [53] globals_0.16.3    nnet_7.3-19       lme4_1.1-35.3     hms_1.1.3        
#> [57] evaluate_0.23     knitr_1.45        rlang_1.1.3       Rcpp_1.0.12      
#> [61] DBI_1.2.2         glue_1.7.0        reprex_2.1.0      rstudioapi_0.16.0
#> [65] minqa_1.2.6       R6_2.5.1          fs_1.6.3

Created on 2024-04-17 with reprex v2.1.0

stefvanbuuren commented 5 months ago

Try adding the packages argument.

mi_parallel_mice <- futuremice(
  dataToImpute,
  method = meth,
  predictorMatrix = pred,
  m = numImputations,
  maxit = 5, 
  packages = "miceadds")