Skip to content

Commit

Permalink
Merge pull request #67 from istallworthy/run-through
Browse files Browse the repository at this point in the history
catch NA
  • Loading branch information
istallworthy authored Sep 15, 2023
2 parents c0e20e1 + 1eac1c8 commit a7a221c
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions R/assessBalance.R
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ assessBalance <- function(home_dir, data, exposure, exposure_time_pts, outcome,

bal_stats <- lapply(seq_len(m), function(k) {
d <- as.data.frame(mice::complete(data, k))
if (which(is.na(d)) > 0){
stop("This code requires complete data. Consider imputation if missingness < 20% and is reasonably Missing at Random (MAR).",
call. = FALSE)
}
exposure_type <- ifelse(inherits(d[, paste0(exposure, '.',
exposure_time_pts[1])], "numeric"), "continuous", "binary")

Expand All @@ -270,7 +274,10 @@ assessBalance <- function(home_dir, data, exposure, exposure_time_pts, outcome,

bal_stats <- lapply(seq_len(m), function(k) {
d <- data[[k]]

if (which(is.na(d)) > 0){
stop("This code requires complete data. Consider imputation if missingness < 20% and is reasonably Missing at Random (MAR).",
call. = FALSE)
}
exposure_type <- ifelse(inherits(d[, paste0(exposure, '.',
exposure_time_pts[1])], "numeric"), "continuous", "binary")

Expand Down Expand Up @@ -333,7 +340,10 @@ assessBalance <- function(home_dir, data, exposure, exposure_time_pts, outcome,
if (sum(duplicated(data$"ID")) > 0){
stop("Please provide wide dataset with a single row per ID.", call. = FALSE)
}

if (which(is.na(data)) > 0){
stop("This code requires complete data. Consider imputation if missingness < 20% and is reasonably Missing at Random (MAR).",
call. = FALSE)
}
exposure_type <- ifelse(inherits(data[, paste0(exposure, '.', exposure_time_pts[1])], "numeric"), "continuous", "binary")

bal_stats <- calcBalStats(home_dir, data, formulas, exposure, exposure_time_pts, outcome,
Expand Down Expand Up @@ -367,7 +377,10 @@ assessBalance <- function(home_dir, data, exposure, exposure_time_pts, outcome,

bal_stats <- lapply(seq_len(m), function(k) {
d <- as.data.frame(mice::complete(data, k))

if (which(is.na(d)) > 0){
stop("This code requires complete data. Consider imputation if missingness < 20% and is reasonably Missing at Random (MAR).",
call. = FALSE)
}
if (sum(duplicated(d$"ID")) > 0){
stop("Please provide wide imputed datasets with a single row per ID.", call. = FALSE)
}
Expand All @@ -384,7 +397,10 @@ assessBalance <- function(home_dir, data, exposure, exposure_time_pts, outcome,
m = length(data)
bal_stats <- lapply(seq_len(m), function(k) {
d <- data[[k]]

if (which(is.na(d)) > 0){
stop("This code requires complete data. Consider imputation if missingness < 20% and is reasonably Missing at Random (MAR).",
call. = FALSE)
}
if (sum(duplicated(d$"ID")) > 0){
stop("Please provide wide imputed datasets with a single row per ID.", call. = FALSE)
}
Expand Down

0 comments on commit a7a221c

Please sign in to comment.