This is particularly designed for use within the fn_list_next_gen
parameter
of sim_branching_process()
to allow age group contract matrices to be applied
for example (assuming a categorical age).
Value
a function that given an input will return samples of the output class according to the probability distributions.
Examples
age = rep(c("child","adult","elderly"),100)
fn = cfg_transition_fn(tibble::tribble(
~input, ~output, ~probability,
"child", "child", 0.5,
"child", "adult", 0.5,
"adult", "child", 0.5,
"adult", "adult", 0.3,
"adult", "elderly", 0.2,
"elderly","elderly", 0.5,
"elderly","adult", 0.5,
))
table(fn(age),age)
#> age
#> adult child elderly
#> adult 33 37 63
#> child 48 63 0
#> elderly 19 0 37