njtierney / naniar

Tidy data structures, summaries, and visualisations for missing data
http://naniar.njtierney.com/
Other
650 stars 54 forks source link

error in mcar_test due to singular data - maybe just a limitation to document #282

Open LukasWallrich opened 3 years ago

LukasWallrich commented 3 years ago

Thanks for adding mcar_test(). Unfortunately, the function fails for me due to singularity, regardless of how I slice my data. I am not sure whether that is a limitation of the test (which might then benefit from a clearer error message or documentation) or an issue with the implementation? Below a reprex with a small subset of the data, but I get the same issue with 185 rows

gapminder <- tibble::tribble(
  ~life_expectancy, ~fertility, ~population, ~gdp,          
   72.7,             1.9,        360830,      6650151639,   
   NA,               2.14,       1261319,     14178489076,  
   68.8,             2.28,       151616777,   82979485251,  
   75.2,             NA,         279566,      NA,           
   70.2,             1.46,       9492122,     26002131603,  
   80.1,             1.84,       10929978,    267143096398, 
   71.2,             NA,        321609,      1221526439,   
   60.8,             5.1,        9509798,     3336801340,   
   71.4,             2.38,       720246,      961365501.9,  
   71.8,             3.36,       9918245,     12240412986
)

naniar::mcar_test(gapminder)
#> Error: Problem with `mutate()` input `d2`.
#> x system is computationally singular: reciprocal condition number = 5.00265e-23
#> i Input `d2` is `purrr::pmap_dbl(...)`.
#> i The error occurred in group 1: miss_pattern = 1.

Created on 2021-04-07 by the reprex package (v1.0.0)

njtierney commented 3 years ago

Hi there!

Thanks so much for posting a reprex for this issue.

It was indeed @andrewheiss who implemented this, so thanks to him! :)

I confirm that I am getting this issue as well,

 gapminder <- tibble::tribble(
  ~life_expectancy, ~fertility, ~population, ~gdp,          
  72.7,             1.9,        360830,      6650151639,   
  NA,               2.14,       1261319,     14178489076,  
  68.8,             2.28,       151616777,   82979485251,  
  75.2,             NA,         279566,      NA,           
  70.2,             1.46,       9492122,     26002131603,  
  80.1,             1.84,       10929978,    267143096398, 
  71.2,             NA,        321609,      1221526439,   
  60.8,             5.1,        9509798,     3336801340,   
  71.4,             2.38,       720246,      961365501.9,  
  71.8,             3.36,       9918245,     12240412986
)

naniar::mcar_test(gapminder)
#> Error: Problem with `mutate()` input `d2`.
#> x system is computationally singular: reciprocal condition number = 5.00265e-23
#> ℹ Input `d2` is `purrr::pmap_dbl(...)`.
#> ℹ The error occurred in group 1: miss_pattern = 1.

Created on 2021-04-20 by the reprex package (v2.0.0)

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.0.3 (2020-10-10) #> os macOS Big Sur 10.16 #> system x86_64, darwin17.0 #> ui X11 #> language (EN) #> collate en_AU.UTF-8 #> ctype en_AU.UTF-8 #> tz Australia/Perth #> date 2021-04-20 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [1] standard (@0.2.1) #> backports 1.2.1 2020-12-09 [1] standard (@1.2.1) #> cli 2.4.0 2021-04-05 [1] CRAN (R 4.0.2) #> colorspace 2.0-0 2020-11-11 [1] standard (@2.0-0) #> crayon 1.4.1 2021-02-08 [1] CRAN (R 4.0.2) #> DBI 1.1.1 2021-01-15 [1] CRAN (R 4.0.2) #> digest 0.6.27 2020-10-24 [1] standard (@0.6.27) #> dplyr 1.0.5 2021-03-05 [1] CRAN (R 4.0.2) #> ellipsis 0.3.1 2020-05-15 [1] standard (@0.3.1) #> evaluate 0.14 2019-05-28 [1] standard (@0.14) #> fansi 0.4.2 2021-01-15 [1] CRAN (R 4.0.2) #> fs 1.5.0 2020-07-31 [1] standard (@1.5.0) #> generics 0.1.0 2020-10-31 [1] standard (@0.1.0) #> ggplot2 3.3.3 2020-12-30 [1] CRAN (R 4.0.2) #> glue 1.4.2 2020-08-27 [1] standard (@1.4.2) #> gtable 0.3.0 2019-03-25 [1] standard (@0.3.0) #> highr 0.8 2019-03-20 [1] standard (@0.8) #> htmltools 0.5.1.1 2021-01-22 [1] CRAN (R 4.0.2) #> knitr 1.31 2021-01-27 [1] CRAN (R 4.0.2) #> lifecycle 1.0.0 2021-02-15 [1] CRAN (R 4.0.2) #> magrittr 2.0.1 2020-11-17 [1] standard (@2.0.1) #> munsell 0.5.0 2018-06-12 [1] standard (@0.5.0) #> naniar 0.6.0.9000 2020-12-23 [1] local #> norm 1.0-9.5 2013-02-28 [1] CRAN (R 4.0.2) #> pillar 1.5.1 2021-03-05 [1] CRAN (R 4.0.2) #> pkgconfig 2.0.3 2019-09-22 [1] standard (@2.0.3) #> purrr 0.3.4 2020-04-17 [1] standard (@0.3.4) #> R6 2.5.0 2020-10-28 [1] standard (@2.5.0) #> reprex 2.0.0 2021-04-02 [1] CRAN (R 4.0.2) #> rlang 0.4.10 2020-12-30 [1] CRAN (R 4.0.2) #> rmarkdown 2.7 2021-02-19 [1] CRAN (R 4.0.2) #> rstudioapi 0.13 2020-11-12 [1] standard (@0.13) #> scales 1.1.1 2020-05-11 [1] standard (@1.1.1) #> sessioninfo 1.1.1 2018-11-05 [1] standard (@1.1.1) #> stringi 1.5.3 2020-09-09 [1] standard (@1.5.3) #> stringr 1.4.0 2019-02-10 [1] standard (@1.4.0) #> styler 1.3.2 2020-02-23 [1] standard (@1.3.2) #> tibble 3.1.0 2021-02-25 [1] CRAN (R 4.0.2) #> tidyr 1.1.3 2021-03-03 [1] CRAN (R 4.0.2) #> tidyselect 1.1.0 2020-05-11 [1] standard (@1.1.0) #> utf8 1.2.1 2021-03-12 [1] CRAN (R 4.0.2) #> vctrs 0.3.7 2021-03-29 [1] CRAN (R 4.0.3) #> visdat 0.5.3 2019-02-15 [1] CRAN (R 4.0.2) #> withr 2.4.1 2021-01-26 [1] CRAN (R 4.0.2) #> xfun 0.22 2021-03-11 [1] CRAN (R 4.0.2) #> yaml 2.2.1 2020-02-01 [1] standard (@2.2.1) #> #> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library ```

I've had a bit of a poke around, and it looks like this is happening when running solve here.

This sort of error can happen when you cannot invert a matrix - see this SE thread.

@andrewheiss have you run into this issue?

When I have time, I'll take a look at providing some suggested workarounds for this kind of problem, and trying to document some ways to avoid this.

andrewheiss commented 3 years ago

I have run into this issue, but haven't figured out a way around it yet. ☹️

fmartinssp commented 1 year ago

Hello everyone, everything good? Has anyone found a solution to this problem? I have yet to see any so far.

lorenzoFabbri commented 1 year ago

@andrewheiss Has anyone looked into this? I keep receiving the following error messages for just one group of my dataset:

Error in `dplyr::mutate()`:
ℹ In argument: `d2 = purrr::pmap_dbl(...)`.
ℹ In group 1: `miss_pattern = 1`.
Caused by error in `purrr::pmap_dbl()`:
ℹ In index: 1.
Caused by error in `solve.default()`:
! Lapack routine dgesv: system is exactly singular: U[30,30] = 0