Skip to main content

Creating a Basic Cohort Model

  • Chapter
  • First Online:
Microsimulation and Population Dynamics

Abstract

In this chapter our main aim is to introduce you to the Modgen software and to the Visual Studio programming software, guiding you through the creation of a first basic model. This model will be based on one single type of event: death. Although this will yield only a small number of results, such as life expectancy at birth, it will allow us to demonstrate and to practise the use of several of the basic ideas in Modgen. We will move on to the calculation and presentation of other elements of the life table in the next chapter.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 99.00
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 129.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info
Hardcover Book
USD 129.99
Price excludes VAT (USA)
  • Durable hardcover edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    The probability of dying represents the probability for an individual at a given exact age x of dying before his or her next birthay.

  2. 2.

    In other words, an imaginary cohort whose individual members were all born at the same time.

  3. 3.

    Exact age is the age of an individual on the day of his or her birthday.

  4. 4.

    See Box 1.2 and consult a C++ manual for more details.

  5. 5.

    A double type variable contains 64 bits, which corresponds to a number with 15 digits. See a C++ manual for more details.

  6. 6.

    Suppose that during a simulation a birth and a death happen in the same year. The order in which these events take place will have an effect on the results of the simulation. If the mother’s death happens first, there will be no birth. On the other hand, if the birth happens first, a new actor will be added to the simulation. The risk of dying and the risk of giving birth are here defined as competitive. In a discrete-time model, because the time unit is generally one year, events forecast for the same year conflict; in other words, the time until the two events take place is identical and there is no way of knowing which one will take place first. The model designer therefore has to add supplementary rules to determine which event will take precedence. In a continuous-time model, the probability of two events happening simultaneously is infinitely small so there is no need to draw up supplementary rules for ordering conflicting events.

  7. 7.

    Remember that the complete code can be found in the appendix to this chapter. Numbers refer directly to the corresponding lines in the appendix.

  8. 8.

    A loop is a sequence of code which is repeated a predetermined number of times. Consult a C++ programming instruction manual for more details.

  9. 9.

    Derived states such as the ones used in tables can be thought of as functions extracting information about an actor’s states, such as the duration of time spent in a given state or the number of times the value of a given state has changed. In that sense, even though they are called derived states, it would be more appropriate to think of them as derived “from” states.

  10. 10.

    The action of compiling transforms the high level code (Modgen, C++) written by the programmer into an independent executable file. Here, the executable file is the actual microsimulation model, which includes the execution library and the user interface.

Author information

Authors and Affiliations

Authors

Appendices

Appendices

1.1.1 Appendix 1.1 ModgenExample.mpp

Code Sections: Header (lines 1 to 24), CaseSimulation() Function (lines 25 to 62), Simulation() Function (lines 63 to 97)

1  //LABEL(ModgenExample, EN) Core simulation functions 2 3  /* NOTE(ModgenExample, EN) 4     This module contains core simulation functions and definitions. 5  */ 6 7   // The model version number 8   version 1, 0, 0, 0; 9 10  // The model type 11  model_type case_based; 12 13  // The data type used to represent time 14  time_type double; 15 16  // Supported languages 17  languages { 18      EN // English 19  }; 20 21  // The CaseSimulation function simulates a single case, 22  // and is called by the Simulation function declared later 23  // in this module. 24 25  void CaseSimulation( ) 26  { 27      // Initialize the first actor in the case. 28      Person *poFirstActor = new Person(); 29      poFirstActor->Start( ); 30 31      // Continue processing events until there are no more. 32      // Model code is responsible for ending the case by calling 33      // Finish on all existant actors. 34 35      // The Modgen run-time implements 36      // the global event queue gpoEventQueue. 37      while ( !gpoEventQueue->Empty() ) 38      { 39          // The global variables gbCancelled and gbErrors 40          // are maintained by the Modgen run-time. 41          if ( gbCancelled || gbErrors ) 42          { 43              // The user cancelled the simulation, 44              // or run-time errors occurred. 45              // Terminate the case immediately. 46              gpoEventQueue->FinishAllActors(); 47          } 48          else 49          { 50              // Age all actors to the time of the next event. 51              gpoEventQueue->WaitUntil( gpoEventQueue->NextEvent() ); 52     53              // Implement the next event. 54              gpoEventQueue->Implement(); 55          } 56      } 57 58      // Note that Modgen handles memory cleanup 59      // when Finish is called on an actor. 60  } 61 62 63  // The Simulation function is called by Modgen to simulate a set of cases. 64  void Simulation() 65  { 66      // counter for cases simulated 67      long lCase = 0; 68 69      // The Modgen run-time implements CASES (used below), 70      // which supplies the number of cases to simulate 71      // in a particular thread. 72      // 73      // The following loop for cases is stopped if 74      // - the simulation is cancelled by the user, 75      // with partial reports (gbInterrupted) 76      // - the simulation is cancelled by the user, 77      // with no partial reports (gbCancelled) 78      // - a run-time error occurs (gbErrors) 79      // 80      // The global variables gbInterrupted, gbCancelled and gbErrors 81      // are maintained by the Modgen run-time. 82      for ( lCase = 0; lCase < CASES() && !gbInterrupted && !gbCancelled 83          && !gbErrors; lCase++ ) 84      { 85          // Simulate a case. 86 87          // Tell the Modgen run-time to prepare to simulate a new case. 88          StartCase(); 89 90          // Call the CaseSimulation function 91          // defined earlier in this module. 92          CaseSimulation(); 93 94          // Tell the Modgen run-time that the case has been completed. 95          SignalCase(); 96      } 97  }

1.1.2 Appendix 1.2 PersonCore.mpp

Code Sections: Header, Parameters, Actor Person and functions, Tables

1   //LABEL(PersonCore, EN) Core functionality of the Person actor 2 3   /* NOTE(PersonCore, EN) 4       This module contains the basic information which defines 5       the Person case. 6   */ 7 8   parameters 9   { 10      //EN Annual hazard of death 11      double MortalityHazard; 12      /* NOTE(MortalityHazard, EN) 13          A constant hazard of death results in an exponential 14          survival function. 15      */ 16  }; 17 18  actor Person     //EN Individual 19 { 20      // The variables time and age are automatically defined by Modgen. 21      // Model-specific labels and notes are supplied below. 22 23      //LABEL(Person.time, EN) Time 24      /*NOTE(Person.time, EN) 25          Time is a continuous quantity in this model. 26          A unit of time is a year. 27      */ 28 29      //LABEL(Person.age, EN) Age 30      /*NOTE(Person.age, EN) 31          Age is a continuous quantity in this model. 32          A unit of age is a year. 33      */ 34 35      //EN Alive 36         ogical alive = {TRUE}; 37      /*NOTE(Person.alive, EN) 38          Set to TRUE when the actor starts, and to FALSE just 39          before the actor finishes. Since the numeric value 40          of TRUE is 1 and FALSE is 0, this variable 41          can also be used to count actors in tables. 42      */ 43 44      event timeMortalityEvent, MortalityEvent; //EN Mortality event 45 46      //LABEL(Person.Start, EN) Starts the actor 47      void Start(); 48 49      //LABEL(Person.Finish, EN) Finishes the actor 50      void Finish(); 51  }; 52 53  /*NOTE(Person.MortalityEvent, EN) 54      This event implements a constant hazard of death. 55  */ 56 57  // The time function of MortalityEvent 58  TIME Person::timeMortalityEvent() 59  { 60      TIME tEventTime = TIME_INFINITE; 61 62      // Draw a random waiting time to death 63      // from an exponential distribution 64      // based on the constant hazard MortalityHazard. 65      tEventTime = WAIT( - TIME( log( RandUniform(1) ) / 66          MortalityHazard ) ); 67 68      return tEventTime; 69 } 70 71  // The implement function of MortalityEvent 72  void Person::MortalityEvent() 73  { 74      alive = FALSE; 75 76      // Remove the actor from the simulation. 77      Finish(); 78  } 79 80  /*NOTE(Person.Start, EN) 81      The Start function initializes actor variables before simulation 82      of the actor commences. 83  */ 84  void Person::Start() 85  { 86      // Modgen initializes all actor variables 87      // before the code in this function is executed. 88 89      age = 0; 90      time = 0; 91 92      // After the code in this function is executed, 93      // Modgen initializes events and tables for the actor. 94      // Modgen also outputs starting values to the 95      // tracking file if requested. 96  } 97 98 /*NOTE(Person.Finish, EN) 99      The Finish function terminates the simulation of an actor. 100  */ 101  void Person::Finish() 102  { 103      // After the code in this function is executed, 104      // Modgen removes the actor from tables and from the simulation. 105      // Modgen also recuperates any memory used by the actor. 106  } 107 108  /*NOTE(DurationOfLife, EN) 109      This table contains statistics related to the duration of life. 110  */ 111  table Person DurationOfLife //EN Duration of Life 112  { 113      { 114          //EN Population size 115          value_in(alive), 116          //EN Minimum duration of life decimals=4 117          min_value_out(duration()), 118          //EN Maximum duration of life decimals=4 119          max_value_out(duration()), 120          //EN Life expectancy decimals=4 121          duration() / value_in(alive) 122 123      }   //EN Demographic characteristics 124  };

Rights and permissions

Reprints and permissions

Copyright information

© 2017 Springer International Publishing Switzerland

About this chapter

Cite this chapter

Bélanger, A., Sabourin, P. (2017). Creating a Basic Cohort Model. In: Microsimulation and Population Dynamics. The Springer Series on Demographic Methods and Population Analysis, vol 43. Springer, Cham. https://doi.org/10.1007/978-3-319-44663-9_1

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-44663-9_1

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-44662-2

  • Online ISBN: 978-3-319-44663-9

  • eBook Packages: Social SciencesSocial Sciences (R0)

Publish with us

Policies and ethics