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 when using multiple imputation and multicore = TRUE: no method found for function 'coef' and signature lavaan.mi #78

Open
isaactpetersen opened this issue Jul 8, 2022 · 0 comments

Comments

@isaactpetersen
Copy link

isaactpetersen commented Jul 8, 2022

I receive the following error when using multiple imputation and multicore = TRUE on Windows:

Error in checkForRemoteErrors(val): one node produced an error: no method found for function 'coef' and signature lavaan.mi

Here's a reprex:

library("lavaan")
#> This is lavaan 0.6-12
#> lavaan is FREE software! Please report any bugs.
library("semTools")
#> 
#> ###############################################################################
#> This is semTools 0.5-6
#> All users of R (or SEM) are invited to submit functions or ideas for functions.
#> ###############################################################################
library("simsem")
#> 
#> #################################################################
#> This is simsem 0.5-16
#> simsem is BETA software! Please report any bugs.
#> simsem was first developed at the University of Kansas Center for
#> Research Methods and Data Analysis, under NSF Grant 1053160.
#> #################################################################
#> 
#> Attaching package: 'simsem'
#> The following object is masked from 'package:lavaan':
#> 
#>     inspect

# Specify population model
populationModel <- '
 #Factor loadings
 ind60 =~ .75*x1 + .75*x2 + .75*x3
 dem60 =~ .75*y1 + .75*y2 + .75*y3 + .75*y4
 dem65 =~ .75*y5 + .75*y6 + .75*y7 + .75*y8

 #Specify regression coefficients
 dem60 ~ .4*ind60
 dem65 ~ .2*ind60 + .45*dem60
 
 #Fix latent means to zero
 ind60 ~ 0
 dem60 ~ 0
 dem65 ~ 0
 
 #Fix latent variances to one
 ind60 ~~ 1*ind60
 dem60 ~~ 1*dem60
 dem65 ~~ 1*dem65
 
 #Specify residual variances of manifest variables
 x1 ~~ (1-.75^2)*x1
 x2 ~~ (1-.75^2)*x2
 x3 ~~ (1-.75^2)*x3
 y1 ~~ (1-.75^2)*y1
 y2 ~~ (1-.75^2)*y2
 y3 ~~ (1-.75^2)*y3
 y4 ~~ (1-.75^2)*y4
 y5 ~~ (1-.75^2)*y5
 y6 ~~ (1-.75^2)*y6
 y7 ~~ (1-.75^2)*y7
 y8 ~~ (1-.75^2)*y8
 
 #Specify intercepts of manifest variables
 x1 ~ 0*1
 x2 ~ 0*1
 x3 ~ 0*1
 y1 ~ 0*1
 y2 ~ 0*1
 y3 ~ 0*1
 y4 ~ 0*1
 y5 ~ 0*1
 y6 ~ 0*1
 y7 ~ 0*1
 y8 ~ 0*1
'

populationModelFit <- lavaan(populationModel, do.fit = FALSE)

# Specify analysis model
analysisModelSyntax <- '
 #Factor loadings
 ind60 =~ NA*x1 + x2 + x3
 dem60 =~ NA*y1 + y2 + y3 + y4
 dem65 =~ NA*y5 + y6 + y7 + y8

 #Regression paths
 dem60 ~ ind60
 dem65 ~ ind60 + dem60
 
 #Fix latent means to zero
 ind60 ~ 0
 dem60 ~ 0
 dem65 ~ 0
 
 #Fix latent variances to one
 ind60 ~~ 1*ind60
 dem60 ~~ 1*dem60
 dem65 ~~ 1*dem65
 
 #Estimate residual variances of manifest variables
 x1 ~~ x1
 x2 ~~ x2
 x3 ~~ x3
 y1 ~~ y1
 y2 ~~ y2
 y3 ~~ y3
 y4 ~~ y4
 y5 ~~ y5
 y6 ~~ y6
 y7 ~~ y7
 y8 ~~ y8
 
 #Free intercepts of manifest variables
 x1 ~ intx1*1
 x2 ~ intx2*1
 x3 ~ intx3*1
 y1 ~ inty1*1
 y2 ~ inty2*1
 y3 ~ inty3*1
 y4 ~ inty4*1
 y5 ~ inty5*1
 y6 ~ inty6*1
 y7 ~ inty7*1
 y8 ~ inty8*1
'

numberOfIndicators <- length(fitted(populationModelFit)$mean)

indicatorDistributions <- bindDist(p = numberOfIndicators,
                                   skewness = rep(2.5, 11),
                                   kurtosis = rep(5, 11))

percentMissingByVariable <- '
  x1 ~ p(0.10)
  x2 ~ p(0.10)
  x3 ~ p(0.10)
  y1 ~ p(0.10)
  y2 ~ p(0.10)
  y3 ~ p(0.10)
  y4 ~ p(0.10)
  y5 ~ p(0.10)
  y6 ~ p(0.10)
  y7 ~ p(0.10)
  y8 ~ p(0.10)
'

missingnessModelMI <- miss(logit = percentMissingByVariable, m = 5)

output <- simsem::sim(n = 100,
                      model = analysisModelSyntax,
                      generate = populationModel,
                      miss = missingnessModelMI,
                      seed = 52242,
                      multicore = TRUE)
#> Progress tracker is not available when 'multicore' is TRUE.
#> Error in checkForRemoteErrors(val): one node produced an error: no method found for function 'coef' and signature lavaan.mi

sessionInfo()
#> R version 4.2.0 (2022-04-22 ucrt)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19044)
#> 
#> Matrix products: default
#> 
#> Random number generation:
#>  RNG:     L'Ecuyer-CMRG 
#>  Normal:  Inversion 
#>  Sample:  Rejection 
#>  
#> locale:
#> [1] LC_COLLATE=English_United States.utf8 
#> [2] LC_CTYPE=English_United States.utf8   
#> [3] LC_MONETARY=English_United States.utf8
#> [4] LC_NUMERIC=C                          
#> [5] LC_TIME=English_United States.utf8    
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] simsem_0.5-16  semTools_0.5-6 lavaan_0.6-12 
#> 
#> loaded via a namespace (and not attached):
#>  [1] styler_1.7.0      zoo_1.8-10        xfun_0.31         purrr_0.3.4      
#>  [5] splines_4.2.0     lattice_0.20-45   vctrs_0.4.1       snow_0.4-4       
#>  [9] htmltools_0.5.2   stats4_4.2.0      yaml_2.3.5        utf8_1.2.2       
#> [13] survival_3.3-1    rlang_1.0.3       R.oo_1.25.0       pillar_1.7.0     
#> [17] glue_1.6.2        withr_2.5.0       R.utils_2.12.0    emmeans_1.7.5    
#> [21] multcomp_1.4-19   R.cache_0.15.0    lifecycle_1.0.1   stringr_1.4.0    
#> [25] R.methodsS3_1.8.2 mvtnorm_1.1-3     codetools_0.2-18  coda_0.19-4      
#> [29] evaluate_0.15     knitr_1.39        fastmap_1.1.0     parallel_4.2.0   
#> [33] fansi_1.0.3       highr_0.9         TH.data_1.1-1     xtable_1.8-4     
#> [37] fs_1.5.2          mnormt_2.1.0      digest_0.6.29     stringi_1.7.6    
#> [41] grid_4.2.0        cli_3.3.0         tools_4.2.0       sandwich_3.0-2   
#> [45] magrittr_2.0.3    tibble_3.1.7      crayon_1.5.1      pbivnorm_0.6.0   
#> [49] pkgconfig_2.0.3   ellipsis_0.3.2    MASS_7.3-57       Matrix_1.4-1     
#> [53] estimability_1.4  reprex_2.0.1      rmarkdown_2.14    rstudioapi_0.13  
#> [57] compiler_4.2.0

Created on 2022-07-07 by the reprex package (v2.0.1)

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

1 participant