Skip to content

Commit

Permalink
Adding option for user to turn off the check gFormulaImpute does, whe…
Browse files Browse the repository at this point in the history
…n passed a regular data frame, that there are no missing values.
  • Loading branch information
jwb133 committed Feb 7, 2024
1 parent 72cb89f commit ce09daf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: gFormulaMI
Title: G-Formula for Causal Inference via Multiple Imputation
Version: 1.0.0
Version: 1.0.1
Authors@R:
c(person("Jonathan", "Bartlett", email = "jonathan.bartlett1@lshtm.ac.uk", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-7117-0195")),
Expand Down
13 changes: 9 additions & 4 deletions R/gFormulaImpute.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
#' @param predictorMatrix An optional predictor matrix to specify which variables to use
#' as predictors in the imputation models. The default is to impute sequentially, i.e. impute
#' using all variables to the left of the variable being imputed as covariates
#' @param missingDataCheck TRUE/FALSE indicating whether `gFormulaMI` checks, when
#' passed a regular data frame, whether there any missing values.
#'
#' @returns an S3 object of class mids (multiply imputed dataset)
#'
Expand Down Expand Up @@ -78,7 +80,8 @@
#'
gFormulaImpute <- function(data, M=50, trtVars, trtRegimes,
nSim=NULL, micePrintFlag=FALSE,silent=FALSE,
method=NULL,predictorMatrix=NULL) {
method=NULL,predictorMatrix=NULL,
missingDataCheck=TRUE) {

if (inherits(data, "mids")) {
missingData <- TRUE
Expand All @@ -98,9 +101,11 @@ gFormulaImpute <- function(data, M=50, trtVars, trtRegimes,
if (silent==FALSE) {
print("Input data is a regular data frame.")
}
#check there are no missing values
if (sum(is.na(data))>0) {
stop("Missing values detected - please multiply impute these and pass a mids type object as input.")
#check there are no missing values, unless user has turned off this check
if (missingDataCheck==TRUE) {
if (sum(is.na(data))>0) {
stop("Missing values detected - please multiply impute these and pass a mids type object as input.")
}
}
} else {
stop("Input dataset should either be a data frame or a mids object created by mice.")
Expand Down

0 comments on commit ce09daf

Please sign in to comment.