View source: R/specification.R
| define_variables | R Documentation |
Combine variable definitions into a specification
define_variables(...)
... |
One of three forms. Distribution calls. Specification columns given as named vectors ( Objects created by The forms cannot be mixed in one call. In the column form, |
A simulab_spec base data.frame, shaped by the form it was given.
Distribution calls give one row per distribution parameter, with columns
variable, distribution, parameter and value. The column form and
the constructor form give one row per variable, with columns variable,
distribution, formula, variance and link. Both forms are accepted
by simulate_study() and augment_study().
# Distribution calls. The variable name is the argument name.
define_variables(
age = normal(mean = 50, sd = 10),
treated = binary(prob = 0.5),
outcome = normal(mean = 10 + 0.2 * age + 2 * treated, sd = 2)
)
# Parameters may be positional, in the order list_distributions() reports.
define_variables(y = normal(5, 1), count = poisson(3))
# Specification columns. `formula` is the mean or linear predictor and may
# refer to variables defined earlier. `variance` is a variance, not a
# standard deviation.
define_variables(
variable = c("baseline", "treatment", "outcome"),
formula = c("0", "0.5", "0.4 * baseline + 0.8 * treatment"),
variance = c("1", "0", "1"),
distribution = c("normal", "binary", "normal")
)
# A column given once is recycled, so a specification that shares one
# distribution stays short.
define_variables(
variable = c("x1", "x2", "x3"),
formula = "0",
variance = "1"
)
# Definitions built one at a time are still accepted.
define_variables(
define_variable("age", formula = 40, variance = 100, distribution = "normal"),
define_variable("treated", formula = 0.5, distribution = "binary")
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.