20.8 Custom Functions

Custom functions allow you to create a single commonly used commands/formula, which can then be used with different arguments for different contexts within the tree. We give two examples below both which show how to create custom formula.

Custom formula to delay Discounting using the Discount function

When using the Global Discount method and an associated discount rate, set at the beginning of the model calculation, it is not possible to change the discount rate dependent on the cycle.

The Special Features example, Custom Function Discount.trex, demonstrates how to delay the discounting by applying a custom function when using the Manual Discount function. This function delays discounting into the future for 5 cycles and then starts discounting as though it is the first stage.

Let value be the variable we want to discount. Define the following:

CustomDiscount(value) = Discount(value; if(_stage<discount_stage;0;0.01); _stage - discount_stage + 1)

discount_stage = 5

int_rate = 0.01

Combined, this function will return the value argument discounted at 1% delayed for 5 years. You can run the Markov Cohort Analysis to check the numbers in the model provided.

Custom formula to store variables via the Global Matrix functions

The DES tutorial example, Osteo DES Model.trex, demonstrates this technique.

Note the variable zgStoreColFunction. The variable name itself includes a reference to arguments within parentheses, which designates this variable as a custom function. This function specifically stores data in a global matrix based on the input parameters inMatrix, inCol and inValue.

Note the variables zgStoreCol01_patient, zgStoreCol02_event_no, etc. Each of those variables calls the zgStoreCol function, with each passing the appropriate values for the input parameters.