10.10 Variable Definition Arrays
Variable definitions can consist of an array of expressions that can be referenced by index. For example, you could create a variable definition like this...
myVarArray = [10; 20; 30; 40]
Then any reference to the variable myVarArray would require an integer index value between 1 and 4, to reference one of the four expressions in the array. For example, myVarArray[3] would return the value 30.
The individual expressions within the array can reference any other variables, trackers, tables, distributions, functions, etc. However, the array cannot refer recursively to itself.
The Special Features tutorial example model, Variable Definition Array, demonstrates this technique.
When you look at the root node definition for varArray in the Define Variable dialog, it is automatically presented in grid format.
The "+" button adds another row to the grid. The "Simple" button presents the variable definition as an array with the individual expressions presented together within square brackets and separated by semicolons.
Use the Simple mode to eliminate rows by deleting an expression and a semicolon.
Using Variable Definition Arrays with Tables
Suppose you wanted to reference different complex expressions within a table. This is not possible with a table alone because tables support only numeric expressions. A variable definition array alone might not be sufficient if you wanted to be able to associate the expressions with specific lookup index values as is done with tables. However, a combination of tables and variable definition arrays provides a possible solution.
For example, let's say you wanted to use different expressions in a Markov model for different age ranges as presented below.
Age | Expression |
---|---|
0 - 10 | cEarly * rr1 |
11 - 20 | cTeen * rr2 |
21 - 40 | cAdult * rr3 |
41 - 60 | cOldest * rr4 |
You could first setup a variable definition array to cover all the individual expressions. The array is shown below in Flat view.
myVarArray = [cEarly * rr1; cTeen * rr2; cAdult * rr3; cOldest * rr4]
You could then setup a table that returns the proper variable array index for each age range (using interpolation).
Index | Value |
---|---|
0 | 1 |
10 | 1 |
11 | 2 |
20 | 2 |
21 | 3 |
40 | 3 |
41 | 4 |
60 | 4 |
The expression would then use the table to determine the proper expression within the variable array as follows.
myVarArray[ myTable[age] ]