Skip to content

Commit

Permalink
Add informative warning when all missing data patterns are dropped; c…
Browse files Browse the repository at this point in the history
…loses #605
  • Loading branch information
cjvanlissa committed Nov 30, 2023
1 parent 1e1b0cd commit 13d0d11
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion R/mcar.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,12 @@ mcar.data.frame <- function(x,
}
remove_pats <- as.numeric(rownames(pats))[-nrow(pats)] <= min_n
if (any(remove_pats)) {
out$removed_patterns <- pats[remove_pats, ]
out$removed_patterns <- pats[which(remove_pats), ]
pats <- pats[-nrow(pats), colnames(missings)]
idmiss <- do.call(paste, as.data.frame(missings))
idpats <- do.call(paste, as.data.frame(pats == 0))
remove_these <- idmiss %in% idpats[remove_pats]
if(all(remove_these)) stop("After dropping missing data patterns with fewer than ", min_n, " cases, there were no remaining valid cases in the dataset. Consider lowering 'min_n', and be cautious about interpreting the results; these data might not be suitable for an MCAR test.")
out$removed_rows <- remove_these
newdata <- x[!remove_these, , drop = FALSE]
imputed <- lapply(imputed, `[`, i = !remove_these, j = colnames(newdata), drop = FALSE)
Expand Down

0 comments on commit 13d0d11

Please sign in to comment.