Skip to contents

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.

Usage

define_parameters(...)

define_parameters_(.dots)

# S3 method for class 'uneval_parameters'
modify(.OBJECT, ...)

Arguments

...

Name-value pairs of expressions defining parameters.

.dots

Used to work around non-standard evaluation.

.OBJECT

An object of class uneval_parameters.

Value

An object of class uneval_parameters (actually a named list of quosures).

Details

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.

Examples


# parameter 'age' depends on time:
# simulating a cohort starting at 60 yo

define_parameters(
  age_start = 60,
  age = age_start + model_time
)
#> 2 unevaluated 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)
)
#> 1 unevaluated parameter.
#> 
#> top_time = ifelse(model_time < 10, 1, 0)

# more elaborate: risk function

define_parameters(
  rate = 1 - exp(- model_time * .5)
)
#> 1 unevaluated parameter.
#> 
#> rate = 1 - exp(-model_time * 0.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)
)
#> 2 unevaluated 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
)
#> 2 unevaluated parameters.
#> 
#> age_start = 40
#> age = age_start + model_time

# cannot add new parameters

# modify(
#   param,
#   const = 4.4,
#   age_2 = age ^ 2
# )