trtObserve {simstudy} | R Documentation |
Observed exposure or treatment
Description
Observed exposure or treatment
Usage
trtObserve(dt, formulas, logit.link = FALSE, grpName = "trtGrp")
Arguments
dt |
data table |
formulas |
collection of formulas that determine probabilities |
logit.link |
indicator that specifies link. If TRUE, then logit link is used. If FALSE, the identity link is used. |
grpName |
character string representing name of treatment/exposure group variable |
Value
An integer (group) ranging from 1 to length of the probability vector
See Also
Examples
def <- defData(varname = "male", dist = "binary", formula = .5, id = "cid")
def <- defData(def, varname = "over65", dist = "binary", formula = "-1.7 + .8*male", link = "logit")
def <- defData(def, varname = "baseDBP", dist = "normal", formula = 70, variance = 40)
dtstudy <- genData(1000, def)
dtstudy
formula1 <- c("-2 + 2*male - .5*over65", "-1 + 2*male + .5*over65")
dtObs <- trtObserve(dtstudy, formulas = formula1, logit.link = TRUE, grpName = "exposure")
dtObs
# Check actual distributions
dtObs[, .(pctMale = round(mean(male), 2)), keyby = exposure]
dtObs[, .(pctMale = round(mean(over65), 2)), keyby = exposure]
dtSum <- dtObs[, .N, keyby = .(male, over65, exposure)]
dtSum[, grpPct := round(N / sum(N), 2), keyby = .(male, over65)]
dtSum
[Package simstudy version 0.8.1 Index]