Skip to content

Commit 046f229

Browse files
authored
Merge pull request #191 from suchard-group/IptwTrimFix
fix trimming
2 parents a54fba1 + 869c1f6 commit 046f229

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

R/PsFunctions.R

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -740,16 +740,13 @@ trimByPs <- function(population, trimByPsArgs = createTrimByPsArgs(trimFraction
740740
checkmate::assertR6(trimByPsArgs, "TrimByPsArgs", add = errorMessages)
741741
checkmate::reportAssertions(collection = errorMessages)
742742

743-
beforeCountTarget <- sum(population$treatment == 1)
744-
beforeCountComparator <- sum(population$treatment == 0)
745-
746743
if (!is.null(trimByPsArgs$trimFraction)) {
747-
cutoffTarget <- quantile(population$propensityScore[population$treatment == 1],
748-
trimByPsArgs$trimFraction)
749-
cutoffComparator <- quantile(population$propensityScore[population$treatment == 0],
750-
1 - trimByPsArgs$trimFraction)
751-
population <- population[(population$propensityScore >= cutoffTarget & population$treatment == 1) |
752-
(population$propensityScore <= cutoffComparator & population$treatment == 0), ]
744+
cutoffTarget <- quantile(population$propensityScore[population$treatment == 1],
745+
1 - trimFraction)
746+
cutoffComparator <- quantile(population$propensityScore[population$treatment == 0],
747+
trimFraction)
748+
population <- population[(population$propensityScore <= cutoffTarget & population$treatment == 1) |
749+
(population$propensityScore >= cutoffComparator & population$treatment == 0), ]
753750
if (!is.null(attr(population, "metaData"))) {
754751
attr(
755752
population,

0 commit comments

Comments
 (0)