addMultiFac {simstudy} | R Documentation |
Add multi-factorial data
Description
Add multi-factorial data
Usage
addMultiFac(dtOld, nFactors, levels = 2, coding = "dummy", colNames = NULL)
Arguments
dtOld |
data.table that is to be modified |
nFactors |
Number of factors (columns) to generate. |
levels |
Vector or scalar. If a vector is specified, it must be the same length as nFatctors. Each value of the vector represents the number of levels of each corresponding factor. If a scalar is specified, each factor will have the same number of levels. The default is 2 levels for each factor. |
coding |
String value to specify if "dummy" or "effect" coding is used. Defaults to "dummy". |
colNames |
A vector of strings, with a length of nFactors. The strings represent the name for each factor. |
Value
A data.table that contains the added simulated data. Each new column contains an integer.
Examples
defD <- defData(varname = "x", formula = 0, variance = 1)
DT <- genData(360, defD)
DT <- addMultiFac(DT, nFactors = 3, levels = c(2, 3, 3), colNames = c("A", "B", "C"))
DT
DT[, .N, keyby = .(A, B, C)]
DT <- genData(300, defD)
DT <- addMultiFac(DT, nFactors = 3, levels = 2)
DT[, .N, keyby = .(Var1, Var2, Var3)]
[Package simstudy version 0.8.1 Index]