Calculating Effect of a Risk Factor


Another metric that can be calculated using the engine is the effect of a certain risk factor on another metric. This allows you to answer questions like:

  • How would my life expectancy change if I stopped smoking?
  • Does my risk of stroke increase or decrease if I drank less and exercised more?

To start with we need a Cause Effect Reference object. We provide a cause effect reference file with the object for each model in the pbl-calculator-engine-assets node module (for installation instructions go here). The file is called cause-effect-ref.json and each model folder has one. For life expectancy functions please use the Cause Effect Reference object for the MPoRT model.

You will also need to know the risk factors you are allowed to work with. This piece of information is available in the risk-factors.js (or risk-factors-ts.ts file if you are using Typescript) within the model folder whose metric you wish to calculate in the pbl-calculator-engine-assets node module (for installation instructions go here). For life expectancy functions please use the file for the MPoRT model.

The following example shows how to calculate the effect of smoking on an individual's life expectancy

/* Import the function which builds out the cause effect function for a certain 
risk factor */
import { getForRiskFactorFunction } from "@ottawamhealth/pbl-calculator-engine";
/* Import the risk factors we are allowed to get the effect for for life expectancy. For 
all life expectancy functions we use the MPoRT models's risk factor */
import { Smoking } from "@ottawamhealth/pbl-calculator-engine-assets/MPoRT/risk-factors";

/* Import the LifeTableFunctions object we built previously. For more information look at the Calculating Life Expectancy section */
import { LifeTableFunctions } from "../calculating-life-expectancy";

/* Get the Cause Effect Reference object from the MPoRT folder since we are using 
the life expectancy function */
const mportCauseEffectRef = require("@ottawamhealth/pbl-calculator-engine-assets/MPoRT/cause-effect-ref.json");

/* Build out the cause effect function using the above reference object */
const forMportRiskFactor = getForRiskFactorFunction(mportCauseEffectRef);

/* The data for the individual who is a smoker. Look at the Building Your Data 
section for more information on how we built this array */
const individualData = [
  { name: "age", coefficent: 21 },
  { name: "sex", coefficent: "male" },
  { name: "QSHeavyCont_df", coefficent: 1 }
];

/* Calculate the normal life expectancy for the above indiviudual */
const lifeExpectancyForIndividual = LifeTableFunctions.getLifeExpectancy(
  individualData
);

/* Calculate the life expectancy for the individual as if they were a non smoker */

const lifeExpectancyForNonSmokerIndividual = forMportRiskFactor
  /*We first pass in the risk factor whose 
    cause effect we want */
  .withRiskFactor(Smoking)
  /* We then pass in the function whose effect we want to calculate. Since we want life expectany we pass in .getLifeExpectancy */
  .getCauseEffect(LifeTableFunctions.getLifeExpectancy)
  /* Finally we pass in the arguments we would normally pass into the function which is just a data argument */
  .withData(individualData);

/* This calculation gives us the life years the above individual has lost to smoking */
const lifeYearsLostDueToSmoking =
  lifeExpectancyForNonSmokerIndividual - lifeExpectancyForIndividual;

/* Log the result */
console.log(`Life Years Lost due to Smoking: ${lifeYearsLostDueToSmoking}`);

The following example shows how to calculate the effect of alcohol and physical activity on the risk of stroke. One important take away from this example is that the effect of 2 risk factors is not equal to the effect of one plus the effect of another but to use the withRiskFactors function and pass in an array of risk factors.

/* Import the function which builds out the cause effect function for a certain risk factor */
import { getForRiskFactorFunction } from '@ottawamhealth/pbl-calculator-engine';
/* Import the risk factors we are allowed to get the effect for for the risk of stroke.
Use the risk factors from the SPoRT model folder */
import { RiskFactors } from '@ottawamhealth/pbl-calculator-engine-assets/SPoRT/risk-factors';

/* Assume this has been initialized. See the Building Models section for more information */
const SportModelFunctions;

/* Get the Cause Effect Reference object from the SPoRT folder since we are using the
getRiskToTime function*/
const sportCauseEffectRef = require(
    '@ottawamhealth/pbl-calculator-engine-assets/SPoRT/cause-effect-ref.json'
);

/* Build out the cause effect function using the above reference object */
const forSportRiskFactor = getForRiskFactorFunction(sportCauseEffectRef);

/* The data for the individual who is a moderate drinker and has 2 mets/day.
Look at the Building Your Data section for more information on how we built this array */
const individualData = [
    {name: 'age', coefficent: 30},
    {name: 'gender', coefficent: 'male'},
    {name: 'AlcoholType', coefficent: 1 },
    {name: 'PhysicalActivity', coefficent: 2}
];

/* Calculate the stroke risk for the above individual as if they were a non drinker and had
higher physical activity */
const affectedStrokeRisk = forSportRiskFactors
    /* We first pass in the risk factors whose
    cause effect we want. Notice the
    difference as compared to the previous
    example where we used withRiskFactor
    function as opposed to here where we are
    using the withRiskFactors function */
    .withRiskFactors([RiskFactors.Alcohol, RiskFactors.PhysicalActivity])
    /* We then pass in the function whose effect we want to calculate. Since we
    want stroke risk we pass in .getRiskToTime */
    .getCauseEffect(SportModelFunctions.getRiskToTime)
    /* Finally we pass in the arguments we would normally pass into the function
    which is a data argument and an optinal time argument */
    .withData(individualData);

results matching ""

    No results matching ""