cjvanlissa / tidySEM

54 stars 7 forks source link

estimate_mplus does not work #46

Open albertostefanelli opened 2 years ago

albertostefanelli commented 2 years ago

As per title, estimate_mplus() does not work. This might be related to the fact that Mplus_command is not passed to mplusModeler. Also mplusAvailable() does not return anything. estimate_lavaan and estimate_mx do work.

Note that on my case the exe of mplus is not in the global path.

df <- HolzingerSwineford1939
names(df)[grepl("^x", names(df))] <- c("vis_1", "vis_2", "vis_3", "tex_1", "tex_2", "tex_3", "spe_1", "spe_2", "spe_3")

df |> tidy_sem() |> measurement() |> estimate_mplus(Mplus_command = "/Applications/Mplus_mac/mplus")

R version 4.1.2 (2021-11-01)
Platform: aarch64-apple-darwin21.1.0 (64-bit)
Running under: macOS Monterey 12.2.1

Matrix products: default
LAPACK: /opt/homebrew/Cellar/r/4.1.2/lib/R/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] tidySEM_0.2.1         OpenMx_2.20.3         ggrepel_0.9.1         gtsummary_1.5.2      
 [5] lavaanPlot_0.6.2      emmeans_1.7.2         ggprism_1.0.3         janitor_2.1.0        
 [9] rstatix_0.7.0         filesstrings_3.2.2    stringr_1.4.0         glue_1.6.1           
[13] here_1.0.1            purrr_0.3.4           ggplot2_3.3.5         MplusAutomation_1.0.0
[17] patchwork_1.1.1       semTable_1.8          lavaan_0.6-10         naniar_0.6.1         
[21] dplyr_1.0.8          

loaded via a namespace (and not attached):
  [1] backports_1.4.1        jtools_2.1.4           Hmisc_4.6-0            systemfonts_1.0.3     
  [5] igraph_1.2.11          plyr_1.8.6             ltm_1.2-0              splines_4.1.2         
  [9] polycor_0.8-1          digest_0.6.29          interactions_1.1.5     htmltools_0.5.2       
 [13] fansi_1.0.2            magrittr_2.0.2         checkmate_2.0.0        strex_1.4.2           
 [17] paletteer_1.4.0        cluster_2.1.2          tzdb_0.2.0             openxlsx_4.2.5        
 [21] readr_2.1.1            RcppParallel_5.1.5     sandwich_3.0-1         jpeg_0.1-9            
 [25] colorspace_2.0-2       textshaping_0.3.6      haven_2.4.3            xfun_0.29             
 [29] crayon_1.4.2           jsonlite_1.7.3         zeallot_0.1.0          zoo_1.8-9             
 [33] survival_3.2-13        gtable_0.3.0           V8_4.1.0               statsExpressions_1.3.0
 [37] car_3.0-12             abind_1.4-5            scales_1.1.1           mvtnorm_1.1-3         
 [41] DBI_1.1.2              Rcpp_1.0.8             xtable_1.8-4           performance_0.8.0     
 [45] htmlTable_2.4.0        tmvnsim_1.0-2          latex2exp_0.9.3        foreign_0.8-81        
 [49] Formula_1.2-4          stats4_4.1.2           rsvg_2.2.0             datawizard_0.2.3      
 [53] htmlwidgets_1.5.4      httr_1.4.2             DiagrammeR_1.0.9       RColorBrewer_1.1-2    
 [57] ellipsis_0.3.2         reshape_0.8.8          pkgconfig_2.0.3        farver_2.1.0          
 [61] nnet_7.3-16            sass_0.4.0             kutils_1.70            utf8_1.2.2            
 [65] effectsize_0.6.0.1     tidyselect_1.1.1       labeling_0.4.2         rlang_1.0.1           
 [69] munsell_0.5.0          tools_4.1.2            visNetwork_2.1.0       cli_3.1.1             
 [73] gsubfn_0.7             generics_0.1.2         broom_0.7.12           evaluate_0.14         
 [77] fastmap_1.1.0          yaml_2.2.2             ragg_1.2.1             rematch2_2.1.2        
 [81] knitr_1.37             stationery_1.0         zip_2.2.0              pander_0.6.4          
 [85] admisc_0.25            visdat_0.5.3           nlme_3.1-153           WRS2_1.1-3            
 [89] correlation_0.8.0      compiler_4.1.2         rstudioapi_0.13        curl_4.3.2            
 [93] png_0.1-7              ggsignif_0.6.3         gt_0.3.1               DiagrammeRsvg_0.1     
 [97] tibble_3.1.6           broom.helpers_1.6.0    pbivnorm_0.6.0         stringi_1.7.6         
[101] parameters_0.16.0      forcats_0.5.1          lattice_0.20-45        texreg_1.37.5         
[105] Matrix_1.3-4           psych_2.1.9            commonmark_1.7         vctrs_0.3.8           
[109] msm_1.6.9              mc2d_0.1-21            pillar_1.7.0           lifecycle_1.0.1       
[113] estimability_1.3       cowplot_1.1.1          data.table_1.14.2      insight_0.15.0        
[117] R6_2.5.1               latticeExtra_0.6-29    gridExtra_2.3          boot_1.3-28           
[121] fastDummies_1.6.3      MASS_7.3-54            assertthat_0.2.1       proto_1.0.0           
[125] rprojroot_2.0.2        withr_2.4.3            mnormt_2.0.2           bayestestR_0.11.5     
[129] expm_0.999-6           parallel_4.1.2         hms_1.1.1              grid_4.1.2            
[133] rpart_4.1-15           labelled_2.9.0         tidyr_1.2.0            coda_0.19-4           
[137] rmarkdown_2.11         snakecase_0.11.0       carData_3.0-5          ggpubr_0.4.0          
[141] lubridate_1.8.0        base64enc_0.1-3        ggstatsplot_0.9.1     
cjvanlissa commented 2 years ago

Could you try to install the version I just pushed to this repository?

albertostefanelli commented 2 years ago

with 65bdebc1 still returns NULL. no other errors are given

cjvanlissa commented 2 years ago

And if you run a model manually using MplusAutomation, does it work?

albertostefanelli commented 2 years ago

yes, it does work but need to specify Mplus_command = "/Applications/Mplus_mac/mplus"

cjvanlissa commented 2 years ago

This is hard for me to debug, because it's related to your situation which requires Mplus_command. Looking at the code, it should get passed down to mplusModeler

albertostefanelli commented 2 years ago

ofc I understand. I was trying to figure it if any argument is passed and when I set hashfilename = FALSE, estimate_mplus returns When hashfilename = FALSE, writeData cannot be 'ifmissing', setting to 'always'. So, arguments are passed to MplusAutomation but the output is not retrieved. could it be the location of the .out file ?

cjvanlissa commented 2 years ago

That's possible; could you try specifying an absolute and a relative file path to modelout =?

albertostefanelli commented 2 years ago

specifying themodelout = "my/working/path/model.inp" I am able to generate the syntax. in the syntax the data argument is "model.dat" but this is not generated. Any idea ?

cjvanlissa commented 2 years ago

And if you additionally specify the dataout?

albertostefanelli commented 2 years ago

specifying dataout with writeData = 'always', hashfilename = FALSE does not return any error and only the syntax.

cjvanlissa commented 2 years ago

You mean, it works but the resulting object does not contain a $results element?

albertostefanelli commented 2 years ago

sorry I did not explain this properly.

 estimate_mplus(modelout = "path/model.inp",
                 dataout = "path/model.dat",
                 writeData = 'always',
                 Mplus_command = "/Applications/Mplus_mac/mplus",
                 hashfilename = FALSE)

returns only the syntax (model.inp) but not the .dat in the specified path. And so the function returns NULL

cjvanlissa commented 2 years ago

Dear Alberto, I'm going to leave this issue open in case anyone wants to address it, but I won't be actively working on it because I don't know how to reproduce your use case on a Windows pc with Mplus on the path.