Calculating Life Expectancy


Life expectancy of an individual as calculated by the engine, is the age at which the mortality of said individual takes place.

This tutorial depends on the model built in the Building Models section.

The method to calculate life expectancy is available on an instance of the UnAbridgedLifeExpectancy class. The constructor for the class has 2 arguments,

  1. An instance of the Model class. The underlying model should be one whose event is mortality.
  2. A JSON object that describes a life table

A life table is a table which tracks a certain population's survival from birth to death. So each row in the table represents a year and has columns like the number of people who died that year, the number of people from the previous year who survived etc. We provide a life table with the pbl-calculator-engine-assets node module within the relevant model folders called lifetable.json. However the life tables are developed for Canada, if you are calculating life expectancy for individuals of another country you will need to find a life table for that country and format it to look like the lifetable.json file.

The following example goes through constructing an instance of the UnAbridgedLifeExpectancy class as well using the calculate method on the constructed method to calculate the life expectancy of an individual. Before proceeding, take a look at the Building your Data section which goes through building the profile of an individual.

/* The builder object for the life table functions */
const {
  UnAbridgedLifeExpectancy
} = require("@ottawamhealth/pbl-calculator-engine/lib/life-expectancy");
/* Import the MPoRT model we previously built. Look at the Building Models section for more information */
const { mportModel } = require("./building-models");

/* The Life table we will be using. This is for Canada. If you are doing 
this calculation on individuals from another country please use a life table 
from that country */
const canadaLifeTable = require("@ottawamhealth/pbl-calculator-engine-assets/MPoRT/life-table.json");

/* Construct an object which has the life expectancy functions using the above 
MPoRT model and lifetable*/
const unAbridgedLifeExpectancy = new UnAbridgedLifeExpectancy(
  mportModel,
  canadaLifeTable
);

/* Construct the data for the individual whose life expectancy we need to calculate 
For more information look at the Building Your Data section*/
const individualData = [
  { name: "age", coefficent: 50 },
  { name: "sex", coefficent: "male" },
  { name: "Cancer_cat", coefficent: 0 },
  { name: "Diabetes_cat", coefficent: 0 }
];

/* Calculate life expectancy */
const lifeExpectancy = unAbridgedLifeExpectancy.calculateForIndividual(
  individualData
);

/* Log the calculated life expectancy */
console.log(`Normal Life Expectancy: ${lifeExpectancy}`);

/* Export the built object so we can use it elsewhere */
module.exports = { unAbridgedLifeExpectancy };

results matching ""

    No results matching ""