Step 3: Base Mortality
Model Description
At this step we add a module for mortality based on a period life table of projected mortality rates. This is the base version of Mortality resembling a typical macro population projection approach.
The new module: MortalityStandardLifeTable.mpp
This module implements a simple model of mortality. People can die at any moment of time based on age-specific period mortality rates. At death, the state is_alive is set to FALSE and the Modgen function Finish() is called which clears up memory space.
This module is a typical implementation of a stochastic event depending on hazard rates. The time function calculates a random waiting time to death based on the age-specific hazard rates of death. The time function is very typical for time functions scheduling an event in continuous time. If a person is at risk of the event, an exponentially distributed random waiting time is drawn and the event time returned. Whenever a state that influences the waiting time changes (in this case only integer_age), a new waiting time is drawn automatically based on the updated rate and the event is automatically re-scheduled.
The module is prepared for being combined with or replaced by a refined model accounting for more detailed personal characteristics than age and sex. For this purpose a logical state use_base_mortality is introduced and initialized with TRUE; Other modules can override the waiting time function of this module by setting the state to FALSE whenever an alternative model is applied.
////////////////////////////////////////////////////////////////////////////////////////////////////
// Parameters
////////////////////////////////////////////////////////////////////////////////////////////////////
parameters
{
double MortalityTable[SEX][AGE_RANGE][SIM_YEAR_RANGE]; //EN Mortality hazard by age
};
parameter_group PG02_OverallMortality //EN Overall mortality
{
MortalityTable
};
////////////////////////////////////////////////////////////////////////////////////////////////////
// Actor states and functions
////////////////////////////////////////////////////////////////////////////////////////////////////
actor Person
{
logical use_base_mortality = { TRUE }; //EN Use the base version
event timeMortalityEvent, MortalityEvent; //EN Mortality event
};
////////////////////////////////////////////////////////////////////////////////////////////////////
// Implementation of functions and events
////////////////////////////////////////////////////////////////////////////////////////////////////
TIME Person::timeMortalityEvent()
{
TIME dEventTime = TIME_INFINITE;
double dMortalityHazard
= MortalityTable[sex][integer_age][RANGE_POS(SIM_YEAR_RANGE, calendar_year)];
// check if a person is at risk
if (dMortalityHazard > 0.0 && in_projected_time && ever_resident && use_base_mortality)
{
// determine the event time
// the formula [ -log(rand) / hazard ] calculates an exponentially distributed waiting time
// based on a uniform distributed random number and a given hazard rate
dEventTime = WAIT(-log(RandUniform(3)) / dMortalityHazard);
}
// return the event time, if the maximum age is not reached at that point
if (dEventTime < time_of_birth + MAX(AGE_RANGE) + 1.0) return dEventTime;
// otherwise, return the moment, at which the maximum age is reached
else return time_of_birth + MAX(AGE_RANGE) + 0.9999;
}
void Person::MortalityEvent()
{
is_alive = FALSE;
Finish(); // Remove the actor from the simulation.
}