Generate multi-factorial data

genMultiFac(
  nFactors,
  each,
  levels = 2,
  coding = "dummy",
  colNames = NULL,
  idName = "id"
)

Arguments

nFactors

Number of factors (columns) to generate.

each

Number of replications for each combination of factors. Must be specified.

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.

idName

A string that specifies the id of the record. Defaults to "id".

Value

A data.table that contains the added simulated data. Each column contains an integer.

Examples

genMultiFac(nFactors = 2, each = 5)
#> Key: <id>
#>        id  Var1  Var2
#>     <int> <num> <num>
#>  1:     1     0     0
#>  2:     2     0     0
#>  3:     3     0     0
#>  4:     4     0     0
#>  5:     5     0     0
#>  6:     6     1     0
#>  7:     7     1     0
#>  8:     8     1     0
#>  9:     9     1     0
#> 10:    10     1     0
#> 11:    11     0     1
#> 12:    12     0     1
#> 13:    13     0     1
#> 14:    14     0     1
#> 15:    15     0     1
#> 16:    16     1     1
#> 17:    17     1     1
#> 18:    18     1     1
#> 19:    19     1     1
#> 20:    20     1     1
#>        id  Var1  Var2
genMultiFac(nFactors = 2, each = 4, levels = c(2, 3))
#> Key: <id>
#>        id  Var1  Var2
#>     <int> <int> <int>
#>  1:     1     1     1
#>  2:     2     1     1
#>  3:     3     1     1
#>  4:     4     1     1
#>  5:     5     2     1
#>  6:     6     2     1
#>  7:     7     2     1
#>  8:     8     2     1
#>  9:     9     1     2
#> 10:    10     1     2
#> 11:    11     1     2
#> 12:    12     1     2
#> 13:    13     2     2
#> 14:    14     2     2
#> 15:    15     2     2
#> 16:    16     2     2
#> 17:    17     1     3
#> 18:    18     1     3
#> 19:    19     1     3
#> 20:    20     1     3
#> 21:    21     2     3
#> 22:    22     2     3
#> 23:    23     2     3
#> 24:    24     2     3
#>        id  Var1  Var2
genMultiFac(
  nFactors = 3, each = 1, coding = "effect",
  colNames = c("Fac1", "Fac2", "Fac3"), id = "block"
)
#> Key: <block>
#>    block  Fac1  Fac2  Fac3
#>    <int> <num> <num> <num>
#> 1:     1    -1    -1    -1
#> 2:     2     1    -1    -1
#> 3:     3    -1     1    -1
#> 4:     4     1     1    -1
#> 5:     5    -1    -1     1
#> 6:     6     1    -1     1
#> 7:     7    -1     1     1
#> 8:     8     1     1     1