
missr tests how your data went missing, and tells you in plain English:
missr(): one call that runs the tests below and reports
whether the data are consistent with MCAR, MAR or MNAR.mcar(): are the data missing completely at random
(MCAR)?mar() / mnar(): are the data missing at
random (MAR), or is there evidence they are missing not at random
(MNAR)? Both names run the same tests.Every function prints a one-sentence verdict. Add
verbose = TRUE to see the statistics behind it.
You can install missr from CRAN:
install.packages("missr")Or you can install the development version on github using remotes:
# install.packages("remotes")
remotes::install_github("NoahHellen/missr")library(missr)
missr(healthcheck)
#> Not MCAR, consistent with MAR: the recorded values differ between rows with
#> and without missing values, but there is no evidence of MNAR (this does not
#> prove MAR).
#>
#> MCAR (Little's test): not MCAR (p = 0.029)
#> MNAR (score test): no evidence of MNAR (smallest adjusted p = 0.31)
#>
#> Tip: this check is much more reliable with an instrument: a fully recorded
#> column linked to the column with gaps that doesn't affect whether it is
#> missing (e.g. the same measurement from last year).
#> No candidate for `rbc`: consider adding one to your data.
#>
#> For the statistics behind this, use verbose = TRUE.missr() runs mcar() and mar()
for you. You can also call them on their own:
mcar(healthcheck)
#> Evidence the data are not MCAR: the recorded values differ between rows with and without missing values.
#>
#> For the statistics behind this, use verbose = TRUE.
mar(healthcheck)
#> No evidence of MNAR: the data are consistent with MAR (this does not prove MAR).
#>
#> Tip: this check is much more reliable with an instrument: a fully recorded
#> column linked to the column with gaps that doesn't affect whether it is
#> missing (e.g. the same measurement from last year).
#> No candidate for `rbc`: consider adding one to your data.
#>
#> For the statistics behind this, use verbose = TRUE.companydata is MNAR: firms with fewer employees tend to
leave employees blank. On its own, mar() can
miss this, so it suggests an instrument:
missr(companydata)
#> Not MCAR, consistent with MAR: the recorded values differ between rows with
#> and without missing values, but there is no evidence of MNAR (this does not
#> prove MAR).
#>
#> MCAR (Little's test): not MCAR (p < 0.001)
#> MNAR (score test): no evidence of MNAR (smallest adjusted p = 0.84)
#>
#> Tip: this check is much more reliable with an instrument: a fully recorded
#> column linked to the column with gaps that doesn't affect whether it is
#> missing (e.g. the same measurement from last year).
#> Try: missr(data, instrument = c(employees = "employees_last_year"))
#> No candidate for `product_rating`: consider adding one to your data.
#>
#> For the statistics behind this, use verbose = TRUE.An instrument is a fully recorded column that is linked to the column with gaps but doesn’t affect whether values go missing. Here, last year’s headcount predicts this year’s, but it’s this year’s size that makes a firm skip the question. Naming it lets missr find the MNAR:
missr(companydata, instrument = c(employees = "employees_last_year"))
#> Evidence of MNAR in `employees`: whether a value is missing appears to
#> depend on the missing value itself.
#>
#> MCAR (Little's test): not MCAR (p < 0.001)
#> MNAR (score + instrument tests): evidence of MNAR (smallest adjusted p < 0.001)
#>
#> For the statistics behind this, use verbose = TRUE.If your data has no such column, consider adding one, such as the same measurement from an earlier time or another source.
A test can find evidence against an assumption, but it can never prove one. So missr never says “the data are MAR”. At best it says “No evidence of MNAR: the data are consistent with MAR”.
Telling MAR from MNAR is impossible from the data alone, because the
evidence is in the values that are missing. mar() therefore
makes a stated assumption, explained in ?mar and
vignette("background").
missr_benchmarks holds 60 datasets, built from real data
that ships with R, with values removed by known rules: 20 MCAR, 20 MAR
and 20 MNAR. Before each release, missr’s own tests require that:
mcar() classifies them correctly (allowing the usual 1
in 20 false alarm on MCAR data);mar() wrongly reports MNAR on at most 2 of the 40 MCAR
and MAR datasets;mar() catches every MNAR dataset when given an
instrument. Without one it catches about half.missr has an MIT license, as found in the LICENSE file.