addMultiFac: Add multi-factorial data

Description Usage Arguments Value Examples

View source: R/addMultiFac.R

Description

Add multi-factorial data

Usage

1
2
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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)]

kgoldfeld/simstudy documentation built on Nov. 8, 2018, 7:41 p.m.