transition: Describe one allowed transition

View source: R/class_model.R

transitionR Documentation

Describe one allowed transition

Description

Describes an allowed move from one state to another and supplies the function giving its rate.

Usage

transition(from, to, rate)

Arguments

from

Origin state label(s), NA for "every transient state except to", or a move() selector.

to

Destination state label. Omitted when from is a move(), which names its own destinations.

rate

A function that returns transition rates, supplied as a function object rather than its name. It may accept any subset of age, calTime and duration, each measured in fractional years. It must work with vector inputs, returning one numeric rate for each corresponding set of input values. For a constant rate, you may instead supply a function with no arguments that returns a single numeric value.

Details

Three ways to say which states:

transition("female/0", "female/1", rate)

full state labels. from may be a vector of labels.

transition(NA, "deceased", rate)

NA means every transient state, which is how mortality is normally written.

transition(move("edu", "none", "primary"), rate)

one state variable changes and everything else stays, for every state (or those satisfying the edge's where). See move().

A destination that is not a transient state is an absorbing state: the model creates it, under whatever name you give it.

Value

A transition, for passing to transitions().

See Also

transitions(), move(), micsim_model()

Examples

states <- state_space(
  sex = c("female", "male"),
  country = c("DE", "AT"),
  parity = c("0", "1", "2")
)
states

# Full state labels follow the order of the variables in `states`.

# A constant rate is used for all moves between countries.
# This move from Germany to Austria applies to women with no children.
move_to_at <- function() 0.02
transition(from = "female/DE/0", to = "female/AT/0", rate = move_to_at)

# A move from Austria to Germany applies to everyone living in Austria.
# Only the country changes. All other state variables remain constant.
move_to_de <- function() 0.03
transition(move("country", from = "AT", to = "DE"), rate = move_to_de)

# Two origin states share the same emigration rate, and emigration is
# an absorbing state, as "abroad" is not in the state space.
emigration_rate <- function() 0.01
transition(from = c("female/DE/0", "male/DE/0"),
           to = "abroad", rate = emigration_rate)

# First and second births change parity for women in either country.
first_birth <- function(age) ifelse(age >= 18 & age < 45, 0.10, 0)
second_birth <- function(age) ifelse(age >= 18 & age < 45, 0.08, 0)
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)

# Mortality applies in every transient state.
mortality <- function(age) 0.00003 * exp(0.1 * age)
transition(from = NA, to = "deceased", rate = mortality)


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