Skip to content

Commit

Permalink
Merge pull request #606 from cjvanlissa/master
Browse files Browse the repository at this point in the history
Add informative warning
  • Loading branch information
stefvanbuuren authored Nov 30, 2023
2 parents 1e1b0cd + 13d0d11 commit c924a74
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 c924a74

Please sign in to comment.