Assign treatment

trtAssign(
  dtName,
  nTrt = 2,
  balanced = TRUE,
  strata = NULL,
  grpName = "trtGrp",
  ratio = NULL
)

Arguments

dtName

data table

nTrt

number of treatment groups

balanced

indicator for treatment assignment process

strata

vector of strings representing stratifying variables

grpName

string representing variable name for treatment or exposure group

ratio

vector of values indicating relative proportion of group assignment

Value

An integer (group) ranging from 1 to length of the probability vector

See also

Examples

dt <- genData(15) dt1 <- trtAssign(dt, nTrt = 3, balanced = TRUE) dt1[, .N, keyby = trtGrp]
#> trtGrp N #> 1: 1 5 #> 2: 2 5 #> 3: 3 5
dt2 <- trtAssign(dt, nTrt = 3, balanced = FALSE) dt2[, .N, keyby = trtGrp]
#> trtGrp N #> 1: 1 4 #> 2: 2 3 #> 3: 3 8
def <- defData(varname = "male", formula = .4, dist = "binary") dt <- genData(1000, def) dt
#> id male #> 1: 1 0 #> 2: 2 1 #> 3: 3 1 #> 4: 4 1 #> 5: 5 0 #> --- #> 996: 996 1 #> 997: 997 0 #> 998: 998 0 #> 999: 999 1 #> 1000: 1000 0
dt3 <- trtAssign(dt, nTrt = 5, strata = "male", balanced = TRUE, grpName = "Group") dt3
#> id male Group #> 1: 1 0 3 #> 2: 2 1 2 #> 3: 3 1 5 #> 4: 4 1 4 #> 5: 5 0 1 #> --- #> 996: 996 1 1 #> 997: 997 0 3 #> 998: 998 0 3 #> 999: 999 1 2 #> 1000: 1000 0 5
dt3[, .N, keyby = .(male, Group)]
#> male Group N #> 1: 0 1 122 #> 2: 0 2 122 #> 3: 0 3 122 #> 4: 0 4 121 #> 5: 0 5 121 #> 6: 1 1 79 #> 7: 1 2 78 #> 8: 1 3 78 #> 9: 1 4 78 #> 10: 1 5 79
dt3[, .N, keyby = .(Group)]
#> Group N #> 1: 1 201 #> 2: 2 200 #> 3: 3 200 #> 4: 4 199 #> 5: 5 200
dt4 <- trtAssign(dt, nTrt = 5, strata = "male", balanced = FALSE, grpName = "Group") dt4[, .N, keyby = .(male, Group)]
#> male Group N #> 1: 0 1 119 #> 2: 0 2 125 #> 3: 0 3 117 #> 4: 0 4 124 #> 5: 0 5 123 #> 6: 1 1 70 #> 7: 1 2 91 #> 8: 1 3 66 #> 9: 1 4 84 #> 10: 1 5 81
dt4[, .N, keyby = .(Group)]
#> Group N #> 1: 1 189 #> 2: 2 216 #> 3: 3 183 #> 4: 4 208 #> 5: 5 204
dt5 <- trtAssign(dt, nTrt = 5, balanced = TRUE, grpName = "Group") dt5[, .N, keyby = .(male, Group)]
#> male Group N #> 1: 0 1 122 #> 2: 0 2 122 #> 3: 0 3 117 #> 4: 0 4 119 #> 5: 0 5 128 #> 6: 1 1 78 #> 7: 1 2 78 #> 8: 1 3 83 #> 9: 1 4 81 #> 10: 1 5 72
dt5[, .N, keyby = .(Group)]
#> Group N #> 1: 1 200 #> 2: 2 200 #> 3: 3 200 #> 4: 4 200 #> 5: 5 200
dt6 <- trtAssign(dt, nTrt = 3, ratio = c(1, 2, 2), grpName = "Group") dt6[, .N, keyby = .(Group)]
#> Group N #> 1: 1 200 #> 2: 2 400 #> 3: 3 400