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 10.93330 27.57796 135 1 398.06632 0
#> 2: 2 7 16.05016 34.93925 51 1 25.68982 0
#> 3: 3 7 18.69675 44.25973 29 1 27.43340 0
#> 4: 4 7 14.32982 34.23531 62 3 1176.83789 0
#> 5: 5 7 17.46953 35.67560 29 2 2221.55655 0