fertility: Add a child when a birth transition occurs

View source: R/subsystem_fertility.R

fertilityR Documentation

Add a child when a birth transition occurs

Description

Creates a subsystem for add_subsystem(): whenever one of the births transitions happens, a child is added to the population, with the mother recorded and a state drawn from the newborn rule.

Usage

fertility(births, newborn, mothers = NULL, name = "fertility")

Arguments

births

Declared transitions that create a child: a move() or moves_of() selector, a list of them, or a character vector of transition labels such as "female/0->female/1".

newborn

The state a child is born into: a newborn_rule(), or a table-form rule from new_newborn_rule().

mothers

Optional condition on the state variables, e.g. sex == "female". When given, every birth transition must start in a state satisfying it, or the model is refused.

name

The subsystem's name in the model and in result$extensions.

Details

The births themselves are ordinary transitions with ordinary rates, usually a parity variable going up by one:

transition(move("parity", "0", "1", where = sex == "female"), first_birth)

fertility() only says which of those transitions create a child. Nothing about it depends on what the states are called: there is no reserved label for women. Whoever has a birth transition is a mother. If you want that checked, give mothers, and every birth transition must start in a state satisfying it.

At each birth the subsystem

  1. draws the newborn's state from newborn, given the state the mother has just moved INTO;

  2. registers the child, born at the event's date, with motherID set and every duration clock starting at birth;

  3. schedules the child's first event.

The result's pop then carries a motherID column.

Value

A subsystem, for add_subsystem().

Report

After a run, result$extensions[[name]] holds

n_births

the number of children born during the run;

births

one row per birth: motherID, childID, date (yyyymmdd), motherAge (years, two decimals), transition (the mother's birth transition, "from -> to") and childState (the state the child was born into);

by_transition

births per birth transition, a named integer vector that lists transitions without births as zero;

by_child_state

births per state of the newborn.

After a parallel run the identifiers are those of pop.

See Also

add_subsystem(), newborn_rule(), moves_of()

Examples

fertility(
  births  = moves_of("parity"),
  newborn = newborn_rule(sex = c(male = 0.515, female = 0.485),
                         parity = "0"),
  mothers = sex == "female"
)


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