donaldRwilliams / BGGM

Bayesian Gaussian Graphical Models
https://donaldrwilliams.github.io/BGGM/
GNU General Public License v2.0
54 stars 14 forks source link

GSS example gives `wishrnd` error #89

Closed jflournoy closed 7 months ago

jflournoy commented 1 year ago

Hi Donnie, this is a great package and I'm excited to finally start using it. I was walking through the example from the website and encountered the following error:

Script:

remotes::install_github("donaldRwilliams/BGGM")
# dev version
library(BGGM)
library(psych)

# data
Y <- gss

# histogram for each node
psych::multi.hist(Y, density = FALSE)
fit <- estimate(Y, type = "mixed")

Output:

> fit <- estimate(Y, type = "mixed")
BGGM: Posterior Sampling 
0%   10   20   30   40   50   60   70   80   90   100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Error in estimate(Y, type = "mixed") : 
  wishrnd(): given matrix is not symmetric positive definite

Session Info:

R version 4.2.1 (2022-06-23)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.5 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] psych_2.2.9 BGGM_2.1.0 

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.9           mvtnorm_1.1-3        lattice_0.20-45      prettyunits_1.1.1    ps_1.7.1            
 [6] digest_0.6.29        assertthat_0.2.1     rprojroot_2.0.3      utf8_1.2.2           R6_2.5.1            
[11] plyr_1.8.7           ggridges_0.5.3       stats4_4.2.1         coda_0.19-4          pracma_2.4.2        
[16] ggplot2_3.3.6        pillar_1.8.1         Rdpack_2.4           rlang_1.0.5          curl_4.3.2          
[21] rstudioapi_0.14      minqa_1.2.5          callr_3.7.2          nloptr_2.0.3         Matrix_1.4-1        
[26] pbivnorm_0.6.0       sna_2.7-1            labeling_0.4.2       splines_4.2.1        lme4_1.1-31         
[31] munsell_0.5.0        compiler_4.2.1       pkgconfig_2.0.3      mnormt_2.1.1         pkgbuild_1.3.1      
[36] BFpack_1.0.0         tidyselect_1.1.2     tibble_3.1.8         statnet.common_4.8.0 reshape_0.8.9       
[41] fansi_1.0.3          crayon_1.5.1         dplyr_1.0.10         bain_0.2.8           withr_2.5.0         
[46] MASS_7.3-57          rbibutils_2.2.13     grid_4.2.1           nlme_3.1-157         GGally_2.1.2        
[51] gtable_0.3.1         lifecycle_1.0.1      DBI_1.1.3            magrittr_2.0.3       scales_1.2.1        
[56] cli_3.3.0            farver_2.1.1         remotes_2.4.2        generics_0.1.3       vctrs_0.4.1         
[61] boot_1.3-28          RColorBrewer_1.1-3   tools_4.2.1          glue_1.6.2           purrr_0.3.4         
[66] network_1.18.1       processx_3.7.0       parallel_4.2.1       colorspace_2.0-3     extraDistr_1.9.1    
[71] sessioninfo_1.2.2    lavaan_0.6-13      
ph-rast commented 8 months ago

Hi @jflournoy - is this still an issue? We upgraded to 2.1.1 there's a good chance that this issue has been resolved.

jflournoy commented 7 months ago

Hmm, just updated and I get the same thing. If it's helpful, this is the container I'm running in: https://hub.docker.com/r/jflournoy/verse-cmdstan:

> fit <- estimate(Y, type = "mixed")
BGGM: Posterior Sampling 
0%   10   20   30   40   50   60   70   80   90   100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Error: wishrnd(): given matrix is not symmetric positive definite
In addition: There were 50 or more warnings (use warnings() to see the first 50)
> warnings()
Warning messages:
1: In doTryCatch(return(expr), name, parentenv, handler) :
  "dcol" is not a graphical parameter
2: In doTryCatch(return(expr), name, parentenv, handler) :
  "dlty" is not a graphical parameter
> sessionInfo()
R version 4.3.2 (2023-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Etc/UTC
tzcode source: system (glibc)

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

other attached packages:
[1] psych_2.4.3 BGGM_2.1.1 

loaded via a namespace (and not attached):
 [1] gtable_0.3.4             ggplot2_3.5.0            remotes_2.4.2.1          GGally_2.2.0            
 [5] rle_0.9.2                lattice_0.21-9           numDeriv_2016.8-1.1      quadprog_1.5-8          
 [9] vctrs_0.6.5              tools_4.3.2              Rdpack_2.6               generics_0.1.3          
[13] stats4_4.3.2             curl_5.2.0               parallel_4.3.2           sandwich_3.1-0          
[17] tibble_3.2.1             fansi_1.0.6              QRM_0.4-31               DEoptimR_1.1-3          
[21] pkgconfig_2.0.3          Matrix_1.6-1.1           RColorBrewer_1.1-3       ggridges_0.5.6          
[25] lifecycle_1.0.4          compiler_4.3.2           munsell_0.5.1            mnormt_2.1.1            
[29] pracma_2.4.4             tidyr_1.3.1              pillar_1.9.0             nloptr_2.0.3            
[33] MASS_7.3-60              cachem_1.0.8             trust_0.1-8              boot_1.3-28.1           
[37] nlme_3.1-163             ergm_4.6.0               robustbase_0.99-2        lavaan_0.6-17           
[41] ggstats_0.5.1            network_1.18.2           tidyselect_1.2.1         mvtnorm_1.2-4           
[45] dplyr_1.1.4              purrr_1.0.2              splines_4.3.2            gsl_2.1-8               
[49] fastmap_1.1.1            grid_4.3.2               colorspace_2.1-0         cli_3.6.2               
[53] magrittr_2.0.3           utf8_1.2.4               pbivnorm_0.6.0           scales_1.3.0            
[57] extraDistr_1.10.0        lme4_1.1-35.1            timeDate_4032.109        zoo_1.8-12              
[61] BFpack_1.2.3             timeSeries_4032.109      sna_2.7-2                coda_0.19-4.1           
[65] memoise_2.0.1            lpSolveAPI_5.5.2.0-17.11 rbibutils_2.2.16         mgcv_1.9-0              
[69] rlang_1.1.3              Rcpp_1.0.12              glue_1.7.0               reshape_0.8.9           
[73] rstudioapi_0.15.0        minqa_1.2.6              plyr_1.8.9               R6_2.5.1                
[77] bain_0.2.10              statnet.common_4.9.0 
ph-rast commented 7 months ago

Indeed - I can reproduce it with the same Ubuntu version. I'm looking into it

ph-rast commented 7 months ago

@jflournoy I pushed a bit too early, was going to add some tests, and my comment closed your issue. Nonetheless, I fixed the source of the problem which was due to the initialization of one of the Matrix-F matrices. In the case of missing values in Y the init matrix contained NA's that broke the PD requirement. It's fixed now - you can give it a try with

remotes::install_github("donaldRwilliams/BGGM")

Feel free to reopen if it's not working.