Building Models


A model is a collection of related algorithms with conditions for selecting an algorithm for an individual. For example, the MPoRT model consists of two algorithms, both of which calculate the probability of death with one targeting males and the other females. An instance of the Model class is required for calculating all the measures that the engine API offers.

The constructor for the Model class takes only one argument, a JSON object which represents the model you want to work with. All the models we offer along with their JSON files are available in the @ottawamhealth/pbl-calculator-engine-assets library. The following code example creates an instance of the Model class for the MPoRT model.

Before looking at the example below, take a look at the following tutorial on how to build the data to represent an individual.

/* Import the Model class */
const { Model } = require("@ottawamhealth/pbl-calculator-engine/lib/model");

/* Get the model json for the MPoRT model. Replace the modelName const with the 
 name of the model you want to build */
const modelName = "MPoRT";
/* The pbl-calculator-engine-assets library has all the models we offer. 
The names of the root folders correspond to the name of the model within that folder */
const mportModelJson = require(`@ottawamhealth/pbl-calculator-engine-assets/${modelName}/model.json`);

/* Build the model */
const mportModel = new Model(mportModelJson);

/* Represent a male individual using your data */
const male = [
  {
    name: "sex",
    coefficent: "male"
  }
];

/* Get the male algorithm for your data. For certain measures such as risk, 
you will always need to call the getAlgorithmForData function before calling 
the method for calculating the measure */
const maleAlgorithm = mportModel.getAlgorithmForData(male);

/* Export the model so we can use it in another module */
module.exports = { mportModel };

Next steps

Like was said before, the model object is needed to calculate all the measures that our engine offers. Check out the list of measures available here, clicking on any leads to a tutorial on calculating that measure.

results matching ""

    No results matching ""