philchalmers / mirt

Multidimensional item response theory
199 stars 75 forks source link

Error when using `itemstats()`: `Error in cor(data, use = "complete.obs") : no complete element pairs` #221

Closed isaactpetersen closed 2 years ago

isaactpetersen commented 2 years ago

I receive the following error when using itemstats(): Error in cor(data, use = "complete.obs") : no complete element pairs

For a reproducible example, here is the data file I am using: https://osf.io/8syp5/download

Here is the code that generates the error:

itemstats(data = cnlsy[,c("bpi_antisocialT1_1","bpi_antisocialT1_2","bpi_antisocialT1_3","bpi_antisocialT1_4","bpi_antisocialT1_5","bpi_antisocialT1_6","bpi_antisocialT1_7")],
          group = cnlsy$sex)

However, I don't get an error when I don't specify a grouping variable:

itemstats(data = cnlsy[,c("bpi_antisocialT1_1","bpi_antisocialT1_2","bpi_antisocialT1_3","bpi_antisocialT1_4","bpi_antisocialT1_5","bpi_antisocialT1_6","bpi_antisocialT1_7")])

Here is my sessionInfo():

> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    
system code page: 65001

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

other attached packages:
 [1] tinytex_0.37    here_1.0.1      forcats_0.5.1   stringr_1.4.0   dplyr_1.0.8     purrr_0.3.4     readr_2.1.2    
 [8] tidyr_1.2.0     tibble_3.1.6    ggplot2_3.3.5   tidyverse_1.3.1 mirt_1.36       lattice_0.20-45

loaded via a namespace (and not attached):
  [1] TH.data_1.1-0         colorspace_2.0-3      ellipsis_0.3.2        rprojroot_2.0.2       estimability_1.3     
  [6] htmlTable_2.4.0       base64enc_0.1-3       fs_1.5.2              rstudioapi_0.13       lavaan_0.6-10        
 [11] Deriv_4.1.3           MatrixModels_0.5-0    bit64_4.0.5           fansi_1.0.2           mvtnorm_1.1-3        
 [16] lubridate_1.8.0       xml2_1.3.3            codetools_0.2-18      splines_4.1.2         mnormt_2.0.2         
 [21] knitr_1.37            Formula_1.2-4         jsonlite_1.8.0        broom_0.7.12          cluster_2.1.2        
 [26] dbplyr_2.1.1          png_0.1-7             compiler_4.1.2        httr_1.4.2            emmeans_1.7.2        
 [31] backports_1.4.1       assertthat_0.2.1      Matrix_1.4-0          fastmap_1.1.0         cli_3.2.0            
 [36] htmltools_0.5.2       quantreg_5.88         tools_4.1.2           coda_0.19-4           gtable_0.3.0         
 [41] glue_1.6.2            Rcpp_1.0.8.3          cellranger_1.1.0      vctrs_0.3.8           nlme_3.1-155         
 [46] psych_2.2.3           simsem_0.5-16         xfun_0.30             rvest_1.0.2           lifecycle_1.0.1      
 [51] dcurver_0.9.2         semTools_0.5-5        polspline_1.1.19      MASS_7.3-55           zoo_1.8-9            
 [56] scales_1.1.1          vroom_1.5.7           hms_1.1.1             parallel_4.1.2        sandwich_3.0-1       
 [61] SparseM_1.81          RColorBrewer_1.1-2    yaml_2.3.5            pbapply_1.5-0         gridExtra_2.3        
 [66] rms_6.2-0             rpart_4.1.16          latticeExtra_0.6-29   stringi_1.7.6         checkmate_2.0.0      
 [71] permute_0.9-7         rlang_1.0.2           pkgconfig_2.0.3       evaluate_0.15         htmlwidgets_1.5.4    
 [76] bit_4.0.4             tidyselect_1.1.2      magrittr_2.0.2        bookdown_0.25         R6_2.5.1             
 [81] generics_0.1.2        Hmisc_4.6-0           multcomp_1.4-18       DBI_1.1.2             pillar_1.7.0         
 [86] haven_2.4.3           foreign_0.8-82        withr_2.5.0           mgcv_1.8-39           survival_3.3-1       
 [91] nnet_7.3-17           modelr_0.1.8          crayon_1.5.0          utf8_1.2.2            tmvnsim_1.0-2        
 [96] tzdb_0.2.0            rmarkdown_2.13        jpeg_0.1-9            grid_4.1.2            readxl_1.3.1         
[101] data.table_1.14.2     pbivnorm_0.6.0        vegan_2.5-7           reprex_2.0.1          digest_0.6.29        
[106] xtable_1.8-4          GPArotation_2014.11-1 munsell_0.5.0         fortunes_1.5-4

Any thoughts would be greatly appreciated!

philchalmers commented 2 years ago

The function needed to be more robust in the presence of extreme missingness patterns. There's still chances it could fail in the future (not setup to be completely robust yet), but this should happen with much lower frequency. Thanks for the report

isaactpetersen commented 2 years ago

Many thanks for the fix!