Skip to content

Commit

Permalink
Merge pull request #215 from kgoldfeld/fix_trtAssign
Browse files Browse the repository at this point in the history
Fix trt assign
  • Loading branch information
kgoldfeld authored Aug 30, 2023
2 parents d40d33d + 437be5e commit c00370b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# simstudy (development version)

## Breaking Changes
* `trtAssign` with `ratio=NULL` used to produce 0-index values but 1-indexed values if `ratio` was set. This was adjusted so now both versions produce 0-indexed values. This is a potentially breaking change for existing scripts that use the generated treatment values while assuming the old behavior (e.g. using hardcoded values to filter).

## New features
* Function `logisticCoefs` determines the intercept and treatment/exposure
parameter for a data generating process (based on a logistic regression model)
Expand Down
10 changes: 4 additions & 6 deletions R/group_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ trtAssign <- function(dtName, nTrt = 2, balanced = TRUE,
assertNotMissing(dtName = missing(dtName))
assertNotInDataTable(grpName, dtName)
if (!is.null(ratio)) {
assertLengthEqual(var1 = length(ratio), var2 = nTrt)
assertEqual(nTrt = nTrt, val = length(ratio))
}

dt <- copy(dtName)
Expand All @@ -387,16 +387,14 @@ trtAssign <- function(dtName, nTrt = 2, balanced = TRUE,
} else { # balanced is FALSE - strata are not relevant

if (is.null(ratio)) {
if (nTrt == 2) {
formula <- .5
} else {
formula <- rep(1 / nTrt, nTrt)
}
} else { # ratio not null
formula <- round(ratio / sum(ratio), 8)
}

dt <- trtObserve(dt, formulas = formula, logit.link = FALSE, grpName)
if (nTrt == 2) dt[, (grpName) := get(grpName) - 1]

}

return(dt[])
Expand Down Expand Up @@ -637,4 +635,4 @@ trtStepWedge <- function(dtName, clustID, nWaves, lenWaves,

if (lag == 0) dd[, `:=`(xr = NULL)]
return(dd[])
}
}

0 comments on commit c00370b

Please sign in to comment.