trtAssign {simstudy} | R Documentation |
Assign treatment
Description
Assign treatment
Usage
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]
dt2 <- trtAssign(dt, nTrt = 3, balanced = FALSE)
dt2[, .N, keyby = trtGrp]
def <- defData(varname = "male", formula = .4, dist = "binary")
dt <- genData(1000, def)
dt
dt3 <- trtAssign(dt, nTrt = 5, strata = "male", balanced = TRUE, grpName = "Group")
dt3
dt3[, .N, keyby = .(male, Group)]
dt3[, .N, keyby = .(Group)]
dt4 <- trtAssign(dt, nTrt = 5, strata = "male", balanced = FALSE, grpName = "Group")
dt4[, .N, keyby = .(male, Group)]
dt4[, .N, keyby = .(Group)]
dt5 <- trtAssign(dt, nTrt = 5, balanced = TRUE, grpName = "Group")
dt5[, .N, keyby = .(male, Group)]
dt5[, .N, keyby = .(Group)]
dt6 <- trtAssign(dt, nTrt = 3, ratio = c(1, 2, 2), grpName = "Group")
dt6[, .N, keyby = .(Group)]
[Package simstudy version 0.8.1 Index]