| add_subsystem | R Documentation |
Switches on a mechanism that ordinary transitions cannot express, such
as transitions that create a newborn (fertility()) or a calendar rule
for when a transition takes place (school_enrolment()).
add_subsystem(model, subsystem)
model |
A |
subsystem |
A subsystem, from either
|
Subsystems are added one at a time, and the call returns the model. Thus, a workflow can look like this:
model <- micsim_model(...) |>
add_subsystem(fertility(births = moves_of("parity"), newborn = nb)) |>
add_subsystem(school_enrolment(move("edu", "none", "primary"), month = 9))
Adding a subsystem compiles it against the model. That means every selector is resolved into the model's declared transitions and every parameter is checked. If there is a mistake, it is reported and names the subsystem. Two subsystems with the same name, or two that claim the same transition for the same purpose, will give an error.
Subsystems take effect in the order they were added. Their per-run
state is created fresh at the start of every simulate() call, and
whatever they report is returned in result$extensions, under their
name.
The model with the subsystem installed.
fertility(), school_enrolment(), move(), MicSim-concepts
mortality <- function(age) 0.00003 * exp(0.1 * age)
first_birth <- function(age) ifelse(age > 15 & age < 45, 0.1, 0)
model <- micsim_model(
state_space = state_space(sex = c("male", "female"), parity = c("0", "1")),
transitions = transitions(
transition(move("parity", "0", "1", where = sex == "female"), first_birth),
transition(NA, "deceased", mortality)
),
population = data.frame(ID = 1:20, birthDate = "19850101",
initState = "female/0"),
horizon = c(20140101, 20241231)
) |>
add_subsystem(fertility(
births = moves_of("parity"),
newborn = newborn_rule(sex = c(male = 0.515, female = 0.485),
parity = "0")
))
model
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.