Define parameters called to compute the transition matrix
or state values for a Markov model. Parameters can be
time dependent by using the markov_cycle
parameter.
define_parameters(...) define_parameters_(.dots) # S3 method for uneval_parameters modify(.OBJECT, ...)
... | Name-value pairs of expressions defining parameters. |
---|---|
.dots | Used to work around non-standard evaluation. |
.OBJECT | An object of class
|
An object of class uneval_parameters
(actually a named list of lazy
expressions).
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 markov_cycle
(whose length depends on the number of simulation
cycles). Alternatively, dplyr
functions such as
dplyr::n()
or dplyr::row_number()
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.
# parameter 'age' depends on time: # simulating a cohort starting at 60 yo define_parameters( age_start = 60, age = age_start + markov_cycle )#> 2 unevaluated parameters. #> #> age_start = 60 #> age = age_start + markov_cycle# other uses of markov_cycle are possible define_parameters( top_time = ifelse(markov_cycle < 10, 1, 0) )#> 1 unevaluated parameter. #> #> top_time = ifelse(markov_cycle < 10, 1, 0)#> 1 unevaluated parameter. #> #> rate = 1 - exp(-markov_time * 0.5)# dont explicitly state lengths # define_parameters( # var = seq(1, 15, 2) # ) # instead rely on markov_cycle or dplyr # functions such as n() or row_number() define_parameters( var = seq(from = 1, length.out = n(), by = 3), var2 = seq(1, length(markov_cycle), 2) )#> 2 unevaluated parameters. #> #> var = seq(from = 1, length.out = n(), by = 3) #> var2 = seq(1, length(markov_cycle), 2)param <- define_parameters( age_start = 60, age = age_start + markov_cycle ) # modify existing parameters modify( param, age_start = 40 )#> 2 unevaluated parameters. #> #> age_start = 40 #> age = age_start + markov_cycle# cannot add new parameters # modify( # param, # const = 4.4, # age_2 = age ^ 2 # )