| simulate_study | R Documentation |
Simulate a declaratively specified study
simulate_study(
n,
specification,
id = "id",
seed = NULL,
envir = parent.frame(),
batch = NULL
)
n |
Number of observational units. |
specification |
A tidy definition table created with
|
id |
Name of the identifier column. |
seed |
Optional random seed. The caller's random-number state is restored on exit. |
envir |
Environment used to resolve functions and external values named
by a |
batch |
Optional single positive whole number. When given, the
simulator runs |
A simulab_sim base data.frame with n rows: the identifier
column followed by one column per variable. Use
as.data.frame(x, what = "definitions") for the generating definitions.
# `formula` is the mean or linear predictor and may refer to variables
# defined earlier. `variance` is a variance, not a standard deviation, so
# age has sd 10 and outcome has residual sd 2.
simulate_study(
n = 20,
specification = define_variables(
define_variable("age", formula = 40, variance = 100, distribution = "normal"),
define_variable("treated", formula = 0.5, distribution = "binary"),
define_variable("outcome", formula = "10 + 2 * treated", variance = 4,
distribution = "normal")
),
seed = 1
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.