njtierney / naniar

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

Add Little's MCAR test #279

Closed andrewheiss closed 3 years ago

andrewheiss commented 3 years ago

I added mcar_test() for calculating Little's MCAR statistic. The function returns a broom::glance()-like tibble with one row and four columns:

mcar_test(airquality)
#> # A tibble: 1 x 4
#>   statistic    df p.value missing.patterns
#>       <dbl> <dbl>   <dbl>            <int>
#> 1      35.1    14 0.00142                4

Description

I adapted LittleMCAR() from the now-orphaned {BaylorEdPsych} package, which was archived by CRAN because {mvnmle} was also archived.

Eric Stemmler updated the function to work with {norm} for ML estimation instead. I rewrote and readapted his code to work with {purrr}, so it should go faster (and it handles edge cases where every value in a row is NA)

Example

mcar_test(airquality)
#> # A tibble: 1 x 4
#>   statistic    df p.value missing.patterns
#>       <dbl> <dbl>   <dbl>            <int>
#> 1      35.1    14 0.00142                4

Tests

The function has 100% test coverage.

njtierney commented 3 years ago

Awesome! Just added a few small cosmetic changes, thanks so much for providing such a fully-fledged PR with tests and great docs!