From 9d4e10ce2aca0af8db480092da54d8294cc04ac6 Mon Sep 17 00:00:00 2001 From: Fan Bu Date: Tue, 26 Mar 2024 16:14:19 -0400 Subject: [PATCH] patch on covariate balance computing function --- R/CovariateBalance.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/CovariateBalance.R b/R/CovariateBalance.R index d2e90e28..d9b01909 100644 --- a/R/CovariateBalance.R +++ b/R/CovariateBalance.R @@ -163,12 +163,16 @@ computeBalance <- function(subset, stratifiedPop <- CohortMethod::stratifyByPs(population = studyPop, numberOfStrata = stratifyByPsArgs$numberOfStrata, baseSelection = stratifyByPsArgs$baseSelection) + + ## Patch: what if PS model is degenerated so stratification is ill-behaved? + fileName <- file.path(balanceFolder, paste0("bal_t", subset$targetId[1], "_c", subset$comparatorId[1], "_a6.rds")) # analysisId == ITT stratification - if (!file.exists(fileName)) { + ## check to make sure the population table is workable + if (!file.exists(fileName) && nrow(stratifiedPop) > 0 && "stratumId" %in% names(stratifiedPop)) { ParallelLogger::logTrace("Creating stratified balance file " , fileName) balance <- CohortMethod::computeCovariateBalance(population = stratifiedPop, cohortMethodData = cmData)