Easy Tricks for Better Models


Choice Dropdowns
One of the biggest missed opportunities we see at Lumina when reviewing customer & client models is the infrequent use of the Choice() and MultiChoice() functions. Making use of these will not only make your model more clear from a client perspective, but will also make your model more flexible should something like an index change in the future.

To demonstrate this you can view the video below or read on:

Choice Label Variables: Choice() as a Label Variable (2 minutes)


Choices as Labels
When trying to make our model more flexible we should think of using Choice() as a "label variable". A label variable, as we describe it, is a node that uses Choice() to reference a value from an index. The value of using label variables should become more apparent from the following example.


Scenario
I've created a model that references values in my index called "Fruits". However, I notice midway through development that I've actually made a typo in my index:
Choice Tips 1.jpg

If I fix the typo in my index then everywhere else I reference it in the model will break. This headache could've been easily avoided by making use of label variables. Here's how that structure might look:
Choice Tips 2.jpg

Label variables take care of issues like typos because all references point to a single label variable node that grabs its value based on the position in an index.

To use label variables, find the parts of the model that reference an element from the index and then instead of typing something like:
[Fruits = 'Apples']

you would type:
[Fruits = Apples_Label]


Other Benefits from Label Variables
Once label variables have been set up, you can drag and move around elements in your index and Analytica will automatically make sure your labels still point to the correct elements. This includes using "Insert Cell" & "Delete Cell". Additionally, if you make an assignment to the index, as long as the original element remains for its respective label variable the label will still point to the correct element. However, you can not overwrite elements (remember, this is based on position).

Another reason to use label variables is to help track where specific elements of an index are being used. If I needed to find every place 'Apples' was used in my model, I could look at the object window for Apples_Label and view the list of Outputs:
Choice Tips 3.jpg

But what about tables?
Choice() can also be used in tables. Simply type the definition inside a table cell and Analytica will handle the rest:
Choice Tips 4.jpg Choice Tips 5.jpg

Can label variables help with reindexing?
Yes (section pending)


If you'd like to play with the model used in this page, you can download it here:
Download: Choice_Types.ana

Comments


You are not allowed to post comments.