Calculating Risk


Risk is the probability of an event occurring at some point in the future. The type of event depends on the underlying model on which the method is called. For example, for the MPoRT model, the event is death.

Before calculating risk, we need to build an instance of the Model class. Follow the tutorial on building models before proceeding to the next step.

Once we have a model instance, we can use the getRiskToTime method on the instance to calculate risk.

The getRiskToTime method takes 2 arguments,

  1. A data argument
  2. An optional time argument

The data argument is of type Data and represents the profile of an individual on whom we want to calculate a certain measure. The data argument is required on all our measure calculation methods. For more information on the data argument, please go here

For the code examples below we will be working with the MPoRT model.

For this model, age and sex are required variables and variables such as BMI and HeartDis_cat are optional. The following code example builds the data argument using these variables.

const mportData = [
  {
    name: "age",
    coefficent: 21
  },
  {
    name: "sex",
    coefficent: "female"
  },
  {
    name: "BMI",
    coefficent: 10.5
  },
  {
    name: "HeartDis_cat",
    coefficent: 1
  }
];

The time argument specifies the time at which the risk should be calculated. If not specified, it is defaulted to the maximum valid time for the algorithm. For MPoRT, this value is 5 years.

The final code that calculates risk using the MPoRT model is shown below.

/* Import the model we previously built. Look at the Building Model section to learn more */
const { mportModel } = require("./building-models");

/* Here we provide age and sex which are mandatory for the MPoRT model and BMI 
and HeartDis_cat which are part of the MPoRT specifications but optional. */
const mportData = [
  {
    name: "age",
    coefficent: 21
  },
  {
    name: "sex",
    coefficent: "female"
  },
  {
    name: "QSHeavyCont_df",
    coefficent: 1
  }
];

/* The outcome of the MOPoRT model is death. So calling getRiskToTime would 
return the risk of death in 5 years*/
const riskOfDeathInFiveYears = mportModel
  .getAlgorithmForData(mportData)
  .getRiskToTime(mportData);
console.log(`Risk of death in 5 years: ${riskOfDeathInFiveYears}`);

/* The following lines of code calculates the irks of death one year from now */
const moment = require("moment");
const oneYearFromToday = moment();
oneYearFromToday.add(1, "year");
const riskOfDeathInOneYear = mportModel
  .getAlgorithmForData(mportData)
  .getRiskToTime(mportData, oneYearFromToday);
console.log(`Risk of death in 1 year: ${riskOfDeathInOneYear}`);

results matching ""

    No results matching ""