transitions: Collect the transitions of a model

View source: R/class_model.R

transitionsR Documentation

Collect the transitions of a model

Description

Collects the individual transition() declarations into one object for micsim_model(). Each declaration describes an origin, destination and rate function; the collection describes which moves the model allows.

Usage

transitions(...)

Arguments

...

Objects from transition().

Details

Order matters only for readability. Each destination receives its random numbers in the order of the state space, so declaring the same transitions in a different order gives the same population under the same seed.

Value

An object of class micsim_transitions.

See Also

transition(), micsim_model()

Examples

# Set the rates for the allowed transitions 
first_birth <- function(age) ifelse(age >= 18 & age < 45, 0.10, 0)
second_birth <- function(age) ifelse(age >= 18 & age < 45, 0.08, 0)
mortality <- function(age) 0.00003 * exp(0.1 * age)

# Collect all the allowed transitions in one object
trans <- transitions(
  transition(move("parity", from = "0", to = "1", where = sex == "female"),
             rate = first_birth),
  transition(move("parity", from = "1", to = "2", where = sex == "female"),
             rate = second_birth),
  transition(from = NA, to = "deceased", rate = mortality)
)
trans


MicSim documentation built on Dec. 2, 2026, 1:09 a.m.