define_parameters | R Documentation |
Define parameters called to compute the transition matrix
or state values for a Markov model. Parameters can be
time dependent by using the model_time
parameter.
define_parameters(...)
define_parameters_(.dots)
## S3 method for class 'uneval_parameters'
modify(.OBJECT, ...)
... |
Name-value pairs of expressions defining parameters. |
.dots |
Used to work around non-standard evaluation. |
.OBJECT |
An object of class
|
Parameters are defined sequentially, parameters defined earlier can be called in later expressions.
Vector length should not be explicitly set, but should
instead be stated relatively to model_time
(whose length depends on the number of simulation
cycles). Alternatively, dplyr
functions such as
dplyr::n()
can be used.
This function relies heavily on the dplyr
package.
Parameter definitions should thus mimic the use of
functions such as dplyr::mutate()
.
Variable names are searched first in the parameter
definition (only parameters defined earlier are visible)
then in the environment where define_parameters
was called.
For the modify
function, existing parameters are
modified, but no new parameter can be added. Parameter
order matters since only parameters defined earlier can
be referenced in later expressions.
An object of class uneval_parameters
(actually a named list of quosures).
# parameter 'age' depends on time:
# simulating a cohort starting at 60 yo
define_parameters(
age_start = 60,
age = age_start + model_time
)
# other uses of model_time are possible
define_parameters(
top_time = ifelse(model_time < 10, 1, 0)
)
# more elaborate: risk function
define_parameters(
rate = 1 - exp(- model_time * .5)
)
# dont explicitly state lengths
# define_parameters(
# var = seq(1, 15, 2)
# )
# instead rely on model_time or dplyr
# functions such as n() or row_number()
define_parameters(
var = seq(from = 1, length.out = n(), by = 3),
var2 = seq(1, length(model_time), 2)
)
param <- define_parameters(
age_start = 60,
age = age_start + model_time
)
# modify existing parameters
modify(
param,
age_start = 40
)
# cannot add new parameters
# modify(
# param,
# const = 4.4,
# age_2 = age ^ 2
# )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.