Calling function to simulate data
genData(n, dtDefs = NULL, id = "id", envir = parent.frame())
the number of observations required in the data set.
name of definitions data.table/data.frame. If no definitions are provided a data set with ids only is generated.
The string defining the id of the record. Will override previously set id name with a warning (unless the old value is 'id'). If the id attribute in dtDefs is NULL will default to 'id'.
Environment the data definitions are evaluated in. Defaults to base::parent.frame.
A data.table that contains the simulated data.
genData(5)
#> Key: <id>
#> id
#> <int>
#> 1: 1
#> 2: 2
#> 3: 3
#> 4: 4
#> 5: 5
genData(5, id = "grpID")
#> Key: <grpID>
#> grpID
#> <int>
#> 1: 1
#> 2: 2
#> 3: 3
#> 4: 4
#> 5: 5
def <- defData(
varname = "xNr", dist = "nonrandom", formula = 7,
id = "idnum"
)
def <- defData(def,
varname = "xUni", dist = "uniform",
formula = "10;20"
)
def <- defData(def,
varname = "xNorm", formula = "xNr + xUni * 2",
dist = "normal", variance = 8
)
def <- defData(def,
varname = "xPois", dist = "poisson",
formula = "xNr - 0.2 * xUni", link = "log"
)
def <- defData(def,
varname = "xCat", formula = "0.3;0.2;0.5",
dist = "categorical"
)
def <- defData(def,
varname = "xGamma", dist = "gamma", formula = "5+xCat",
variance = 1, link = "log"
)
def <- defData(def,
varname = "xBin", dist = "binary", formula = "-3 + xCat",
link = "logit"
)
def
#> varname formula variance dist link
#> <char> <char> <num> <char> <char>
#> 1: xNr 7 0 nonrandom identity
#> 2: xUni 10;20 0 uniform identity
#> 3: xNorm xNr + xUni * 2 8 normal identity
#> 4: xPois xNr - 0.2 * xUni 0 poisson log
#> 5: xCat 0.3;0.2;0.5 0 categorical identity
#> 6: xGamma 5+xCat 1 gamma log
#> 7: xBin -3 + xCat 0 binary logit
genData(5, def)
#> Key: <idnum>
#> idnum xNr xUni xNorm xPois xCat xGamma xBin
#> <int> <num> <num> <num> <int> <int> <num> <int>
#> 1: 1 7 16.46757 33.67167 36 3 6038.8168 1
#> 2: 2 7 14.81139 39.89321 62 3 2250.1798 1
#> 3: 3 7 14.63655 39.24079 65 3 2372.2070 1
#> 4: 4 7 13.07279 34.93328 82 3 3504.0556 1
#> 5: 5 7 11.59734 30.09331 121 3 596.8649 0