| MicSim-concepts | R Documentation |
A glossary of the terms and symbols that appear in MicSim's documentation and source code.
A categorical attribute used to
describe an individual in the model, with a set of possible values.
For example, an education variable might take the values "none",
"primary" and "secondary". Another variable might record the
number of children ever born, also called parity. A state variable
need not change during a person's simulated life course.
The combination of one value from each
state variable, describing an individual's current situation.
With variables for sex, nationality and parity, "f/DE/1" could
describe a German woman with one child. MicSim joins the values
with "/", in the order the variables were supplied.
A state that can be left again.
A state from which the model allows no
further transitions. Death is a common example; leaving the study
population permanently is another. In micsim_model(), a
transition destination outside the transient state space is
treated as absorbing. Its label need not be "dead".
A condition on the state variables, such as
sex == "female", by which a model or a subsystem says what a state
means. No label has a built-in meaning; see move().
An additional rule for events that ordinary
transitions alone cannot describe. A birth changes the
mother's state but also adds a child to the population:
fertility() supplies that extra action. school_enrolment()
adjusts event dates to follow a specified school-enrolment calendar.
Use add_subsystem() to add these rules to a model.
Each individual has their own random-number stream, derived from the run's seed and the individual's ID; a newborn's stream comes from the mother's. Each time an individual's next event is scheduled, one uniform is drawn for every possible destination, also for destinations whose rate is zero or infinite.
A consequence of the random number streams is that results do not depend on the number of cores or on who else is simulated, and two scenarios simulated with the same seed use the same random numbers for every individual whose rates do not differ (common random numbers).
A measure of how quickly a particular transition
can occur, written \lambda(t). In MicSim, rates are expressed
per year. A rate is not a probability and can exceed one.
The rate accumulated
over a period of time. If the rate stays at 2 per year for half a year,
the integrated hazard is 2 * 0.5 = 1. When the rate changes over
time, the calculation accounts for those changes. For example, a rate
of 0.2 per year for one year, followed by 0.4 per year for another,
gives an integrated hazard of 0.6.
This accumulated risk is written as
\Lambda(\tau) = \int_0^{\tau} \lambda(s)\,\mathrm{d}s,
where \tau is the interval's length in years. It represents
the individual's total exposure to the risk of this particular
transition over that interval.
How long the individual stays in the current state before a transition occurs.
A method for turning a random draw into a waiting time that follows the supplied rate. For an ordinary finite rate, MicSim draws a positive random threshold, then calculates when the integrated hazard reaches it. That time is the candidate waiting time. For example, with a constant rate of 2 per year and a threshold of 1, the candidate is half a year away. If the threshold is not reached within the remaining observation period, there is no candidate event in that period.
The threshold, written u, is drawn from an exponential
distribution with mean one. The calculation finds \tau
such that \Lambda(\tau) = u. Each draw generally gives a
different threshold and hence a different waiting time.
A transition whose rate is Inf at some
point, encoding an event that happens on a known date rather than
at random. Elementary-school enrolment is a common example.
Several transitions may be possible from the same state. For example, someone who is a former smoker might resume smoking or die. These possibilities compete because whichever happens first ends the current stay in that state.
MicSim draws a candidate waiting time for each possible destination, as if that transition were the only one possible. If the draw places relapse two years away and death five years away, MicSim schedules relapse. After relapse, it draws new candidates from the person's new state, including a new candidate for death if that transition is allowed. A school-calendar rule adjusts the relevant candidates before the earliest is selected.
The random draws for the different candidates are independent. This is part of the sampling method; it does not claim that real-world causes are unrelated.
A transition rate can use three ways of measuring time:
Time since the individual's birth.
When something happens in the study period,
such as 2020 rather than 2010. A rate using calTime can therefore
represent changes over historical time, such as falling mortality.
Time since the last change of the state variable
that the transition would change. If quitting moves someone from
"current_smoker" to "former_smoker" during the simulation, a
relapse rate can use duration to measure time since quitting.
All three advance together as time passes. Someone aged 35 who quit two years earlier in the simulation will be 36 with three years since quitting after another year of abstinence. Calendar time also advances by one year. If they resume smoking and later quit again, the new abstinent spell starts with duration zero. Until the first simulated change in a state variable, MicSim measures its duration from birth.
One uninterrupted stay in a state during observation, recorded with a start and an end date. A person who starts childless, has a first child and then remains in the one-child state until observation ends has two episodes.
We know the individual was in a state at the start of observation but not when they entered it. Every member of the starting population is left-truncated.
Observation ends before the state is left. Everyone still alive at the end of the simulation horizon is right-censored.
The number of relevant events divided by the total time individuals were able to experience them. That time is called exposure or person-time at risk. For a first-birth rate, for example, count first births and sum the observed time spent in the eligible childless states.
Ten events during 200 person-years give 10 / 200 = 0.05 events
per person-year. One person observed for two years contributes
two person-years, as do two people observed for one year each.
This estimates a rate, not the proportion of individuals with an
event. It can be compared with the supplied rate when sufficient
events and exposure are available. Sampling variation and how rates
change within the estimation intervals affect this comparison.
A simulation that processes events in time order instead of updating everyone at fixed time steps. If the next scheduled event is on 5 March, the engine advances directly to it rather than processing each intervening day. Individuals remain in their current states between events, although their ages and transition rates can change.
The list of events already scheduled but not yet processed. Each entry identifies a person, a destination state and an event time. The queue lets the engine find the next event across the whole population. A person has at most one active pending event, chosen from their competing candidates.
The date of the soonest pending event. It only ever moves forward.
| Symbol | Meaning | Name in the code |
\lambda(x) | transition rate x years from now | lambda |
\Lambda(\tau) | rate accumulated over tau years | integrated_hazard |
u | standard-exponential draw | u |
\tau | waiting time, in years | tau_years |
E | number of events in a run | - |
N | number of individuals | - |
Many internal names end with a suffix that helps identify the value:
_daysDays since 1970-01-01 for dates, or elapsed days for ages and durations. Values may include fractions of a day.
_yearsTime in fractional years, using 365.25 days per year.
_ymdA date written as year, month and day without separators,
for example 20201103 for 3 November 2020.
_idxA state's number in the internal mapping between labels and numbers.
_slotA person's row number in the internal person store.
_idA person identifier used in the inputs or output, such as
ID or motherID. It need not equal their row number in the store.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.