genData {simstudy} | R Documentation |
Calling function to simulate data
Description
Calling function to simulate data
Usage
genData(n, dtDefs = NULL, id = "id", envir = parent.frame())
Arguments
n |
the number of observations required in the data set. |
dtDefs |
name of definitions data.table/data.frame. If no definitions are provided a data set with ids only is generated. |
id |
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'. |
envir |
Environment the data definitions are evaluated in. Defaults to base::parent.frame. |
Value
A data.table that contains the simulated data.
Examples
genData(5)
genData(5, id = "grpID")
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
genData(5, def)
[Package simstudy version 0.8.1 Index]