Skip to content

Commit

Permalink
Handling edge case when exporting preference distribution and the tar…
Browse files Browse the repository at this point in the history
…get or comparator only has 1 subject.
  • Loading branch information
Admin_mschuemi authored and Admin_mschuemi committed Nov 7, 2023
1 parent 73e299e commit c93d0fb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ Changes:

Bugfixes:

3. Fixing `runCmAnalyses()` when using `refitPsForEveryOutcome = TRUE`.
1. Fixing `runCmAnalyses()` when using `refitPsForEveryOutcome = TRUE`.

2. Handling edge case when exporting preference distribution and the target or comparator only has 1 subject.


CohortMethod 5.1.0
Expand Down
5 changes: 4 additions & 1 deletion R/Export.R
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,10 @@ exportPreferenceScoreDistribution <- function(outputFolder,
# rows <- split(reference, reference$sharedPsFile)[[2]]
preparePlot <- function(rows) {
ps <- readRDS(file.path(outputFolder, rows$sharedPsFile[1]))
if (nrow(ps) > 0 && min(ps$propensityScore) < max(ps$propensityScore)) {
if (nrow(ps) > 0 &&
min(ps$propensityScore) < max(ps$propensityScore) &&
sum(ps$treatment == 1) > 1 &&
sum(ps$treatment == 0) > 1 ) {
ps <- computePreferenceScore(ps)
d1 <- density(ps$preferenceScore[ps$treatment == 1], from = 0, to = 1, n = 100)
d0 <- density(ps$preferenceScore[ps$treatment == 0], from = 0, to = 1, n = 100)
Expand Down

0 comments on commit c93d0fb

Please sign in to comment.