Closed marklhc closed 2 months ago
Indeed. That is not ok. Something must be wrong with the internal indices. I will investigate.
Ok. After many hours, I think I have finally found the problem. In lav_data_patterns.R (around line 80), we obtain the unique cluster numbers per missing pattern, and a few lines later, we use table() to count the number of cases for this cluster number. But table() seems to automatically sort() the cluster numbers first, leading to a mismatch in some cases...
Fixed on github.
Can you confirm this works for you?
Thank you @yrosseel. I just checked my example and a few others and it works! Ya I remember table()
sometimes have unexpected behaviors.
Closing this now.
I've been having some convergence issues when running multilevel SEM with FIML. One observation I have is that the estimation is more likely to fail when the cluster ID is not sorted. Below is a reproducible example. As you can see, I randomly created missing values on 10 observations on one variable with the built-in
Demo.twolevel
data set, and both listwise deletion and FIML work. However, when I change the order of the observations, only listwise deletion works, but FIML fails. Does the multilevel SEM estimation currently requires the cluster ID to be sorted? Thank you very much.Created on 2024-08-15 with reprex v2.1.0
Session info
``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.4.1 (2024-06-14) #> os Ubuntu 22.04.4 LTS #> system x86_64, linux-gnu #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/Los_Angeles #> date 2024-08-15 #> pandoc 3.1.9 @ /usr/bin/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> cli 3.6.3 2024-06-21 [1] CRAN (R 4.4.1) #> digest 0.6.36 2024-06-23 [1] CRAN (R 4.4.1) #> evaluate 0.23 2023-11-01 [3] CRAN (R 4.3.2) #> fastmap 1.2.0 2024-05-15 [1] CRAN (R 4.4.1) #> fs 1.6.4 2024-04-25 [1] CRAN (R 4.4.1) #> glue 1.7.0 2024-01-09 [3] CRAN (R 4.3.2) #> htmltools 0.5.8.1 2024-04-04 [1] CRAN (R 4.4.1) #> knitr 1.45 2023-10-30 [3] CRAN (R 4.3.2) #> lavaan * 0.6-19.2180 2024-08-16 [1] Github (yrosseel/lavaan@56b8a11) #> lifecycle 1.0.4 2023-11-07 [3] CRAN (R 4.3.2) #> magrittr 2.0.3 2022-03-30 [3] CRAN (R 4.2.0) #> mnormt 2.1.1 2022-09-26 [3] CRAN (R 4.2.1) #> pbivnorm 0.6.0 2015-01-23 [3] CRAN (R 4.0.2) #> purrr 1.0.2 2023-08-10 [3] CRAN (R 4.3.1) #> quadprog 1.5-8 2019-11-20 [3] CRAN (R 4.2.0) #> R.cache 0.16.0 2022-07-21 [3] CRAN (R 4.3.2) #> R.methodsS3 1.8.2 2022-06-13 [3] CRAN (R 4.2.1) #> R.oo 1.26.0 2024-01-24 [3] CRAN (R 4.3.2) #> R.utils 2.12.3 2023-11-18 [3] CRAN (R 4.3.2) #> reprex 2.1.0 2024-01-11 [3] CRAN (R 4.3.2) #> rlang 1.1.4 2024-06-04 [1] CRAN (R 4.4.1) #> rmarkdown 2.25 2023-09-18 [3] CRAN (R 4.3.1) #> sessioninfo 1.2.2 2021-12-06 [3] CRAN (R 4.2.0) #> styler 1.10.2 2023-08-29 [3] CRAN (R 4.3.1) #> vctrs 0.6.5 2023-12-01 [3] CRAN (R 4.3.2) #> withr 3.0.0 2024-01-16 [3] CRAN (R 4.3.2) #> xfun 0.41 2023-11-01 [3] CRAN (R 4.3.2) #> yaml 2.3.8 2023-12-11 [3] CRAN (R 4.3.2) #> #> [1] /home/markl/R/x86_64-pc-linux-gnu-library/4.4 #> [2] /usr/local/lib/R/site-library #> [3] /usr/lib/R/site-library #> [4] /usr/lib/R/library #> #> ────────────────────────────────────────────────────────────────────────────── ```