Table Splicing
(New to Analytica 4.0)
Splicing Overview
Analytica 4.0 contains several new and powerful features that allow you to base Edit Tables, DetermTables and ProbTables on computed indexes. When these indexes change, the elements of the table are automatically adjusted. In the process, some slices may be added, some deleted, and some slices may be re-ordered. This process is called "Splicing".
From ADE, when index definitions change, this same splicing functionality updates table definitions automatically, something that did not occur earlier versions of ADE.
When a computed index changes, there may be correspondence ambiguity -- i.e., there may be an inherent ambiguity in how the previous values map to the new values. This impacts how tables are spliced, and how much data gets lost. You can specify whether an index should be positionally corresponded, associationally corresponded, or flexibly corresponded.
Analytica 4.0 also introduces a new SubTable function, which allows you to display a portion of a table as if it were its own edit table, but where changes to the SubTable actually cause the values in the main table to be changed. The slices (rows/cols) of the subtable may even re-ordered, and the values may appear in input controls on a diagram.
When new slices are added to an index, so that new cells are added to tables based on that index, you can control what values the new cells receive. It is even possible to specify a different cell default for each column (and these may include choice pulldowns). One option (new to 4.0) are blank cells (no contents), such that the new table cells have nothing in them. Blank cells receive some special treatment.
Finally, if you need to highly optimize model startup time, you can take advantage of commands that force tables to be spliced immediately. Doing this prior to saving your model means splicing will not have to occur when the user of your model accesses or evaluates the tables. For these, see SpliceIndex and SpliceTable.
Tables Based on Computed Indexes
As a general rule, it is usually preferable to base Edit Tables on indexes defined as explicit lists. Changes (inserting or deleting elements) to these indexes can then be performed through the Analytica GUI, with no chance of ambiguity.
However, numerous applications do arise in which it is desirable to compute an index. Two common cases are indexes computed from the Concat or Subset functions. In each of these common cases, using a SubTable is generally a better option than basing your table on computed indexes. But should the need arise, you can define a Table, DetermTable or ProbTable on a computed index. A computed index should have an index value that evaluates to a list.
In the case of DetermTables and ProbTables, you can also set the domain of a table variable to an index (an index domain), which is computed. The domain will use the computed index values.
Default Values
Default cell values for tables can be specified; however, the mechanisms for controlling defaults are not exposed through the Analytica Graphical User Interface (GUI), and must be set up through typescript. Currently, these mechanisms are somewhat "fragile", in that they may not handle error conditions gracefully, which is also part of the reason it is not yet exposed more prominently.
Sys_TableCellDefault
The system variable Sys_TableCellDefault contains the scalar default used to populate new table cells when rows/columns/slices are added or inserted into a table. The system variable contains a text value, which is inserted verbatim, and thus should be a valid expression.
Currently this system variable can only be changed using the typescript window. To do this, access the typescript window by pressing CNTL-' (control-appostrophe).
Any of the following typescript commands can be used to change the default cell value, for example to 0, blank (empty), or Null:
Sys_TableCellDefault : 0 Sys_TableCellDefault : Sys_TableCellDefault : Null
Blank (empty) Default Cells
Analytica 4.0 now supports empty cells -- an indication that the table cell hasn't yet been filled in. If you attempt to evaluate a table containing empty cells, a warning is issued. The warning is helpful in identifying table cells that still need to be filled in.
When you change an index, for example, adding new values, Analytica will automatically propagate the changes through your model. However, you also need to remember to fill in new cells in tables based on that index. Using the blank default helps prevent bad results should you forget to fill in a table. Rather than just assuming the value is zero, a blank value causes a warning, and if you ignore the warning, the empty cells evaluate to Null, which will generally propagate through your model and make it obvious that values are missing.
Although not yet available as a feature, in the future tables with blank cells will also be listed on the "Show Invalid Variables" dialog.
When blank cells are present, the textual table definition will contain commas with nothing between them. For example:
Table(I)(1,,,,4,,,5,)
This table definition has three cells with values and six empty cells. While previous versions of Analytica accepted a syntax in which cell expressions were separated by spaces, the commas are now a required part of the Analytica syntax. (Note: tables not containing commas are automatically re-written with commas when a legacy model is loaded).
Suppressing Empty Cell Warnings
Sysvar Sys_WarnUndefCell
Suppression or activation of the empty cell warning is controlled by system variable Sys_WarnUndefCell. If this is true, a warning is issued when a table containing empty cells is evaluated. Setting this to zero (false) de-activates this warning. This warning can be suppressed without de-activing warnings in general.
This preference is currently not available from the Analytica GUI, and thus can only be set via typescript. To access typescript, press CTRL-'. To activate empty cell warnings, type:
Sys_WarnUndefCell:1
To suppress these warnings, type:
Sys_WarnUndefCell:0
When warnings are suppressed, empty cells evaluate to Null.
Table-Specific Default
Attribute TableCellDefault
An individual table may also contain its own default value, which overrides the global cell default. Also, unlike the global default, the table-specific default can specify a different value for each column. For example, if you want one column to always contain a particular Choice pulldown, this can be specified.
The table's default is specified using the Attribute TableCellDefault. This attribute is not presented on the Analytica GUI, and so must be set using the typescript interface.
To specify the same default for every cell that is added to the table, either specify a number, Null, or a quoted string. If you specify a quoted string, the contents of the string should either be empty (an empty cell) or a valid expression (where the outer quotes are not included as part of the expression). For example, the following typescript commands all specify useful defaults that are the same for all cells:
TableCellDefault A : 0 { Use numeric zero as default } TableCellDefault A : "" { Use empty cell as default } TableCellDefault A : Null { Use Null as the default } TableCellDefault A : "'n/a'" { Use the quoted string 'n/a' as the default }
You should not specify defaults that are syntactically invalid. For example, do not use:
TableCellDefault A : '<<fill in>>'
For more complex defaults, such as table where each column gets a different default expression, you should set up a separate edit table to hold the defaults, and then specify its identifier in the TableCellDefault attribute. For example:
Index Columns := ['a','b','c'] Variable A_default := Table(Columns)(0,Choice(Regions,1),) TableCellDefault A := A_default definition A := Table(Rows,Columns)(....)
In this example, A_default is an edit table containing 0 in the first column, a choice pulldown in the second column, and an empty cell in the final column. These are the column defaults for the edit table in A. When an element is added to the Row index, so that a row is added to the table A, the values in the edit table for A_default are used, with the first column defaulting to 0, the second to a choice pulldown, and the third column to an empty cell.
Correspondence
Attribute CorrespondenceMethod
When a computed index changes so that items have different labels, are added, or reorderd, it must determine how the new index values correspond to the old ones ineditable tables that use this index. This correspondence determines how to adjust tables, and which data from the table are preserved or lost.
There are three correspondence methods for splicing:
- Positional correspondence
- The first slice (row, column, subarray) of the table over the changing index remains the first; the second remains the second; and so on. If the index becomes smaller, the extra slices at the end are deleted. If it becomes larger, the new slices contain default values.
- Associational correspondence
- Any slice for an index element whose label is the same, say 'A', is retained, even if other items are inserted before it, or if the items are reordered or shuffled. If the label of an index item changes, say 'A' to 'Alpha', it will lose the data for any slice identified by that label, replacing them by the default values.
- Flexible correspondence
- This is the default method. It preserves associational correspondence wherever index values remain the same. If it finds new index values that didn't exist in the old index,, it tries to match them positionally. So, if the labels change for a section of the index, it uses positional correspondence for them, retaining the old data.
You can control the correspondence method using the CorrespondenceMethod attribute. Important: The correspondence method is an attribute of the index, not of individual tables that use it. All tables based on a given index will be treated identically.
The CorrespondenceMethod attribute is not reflected by the Analytica GUI. Changes to the default correspondence method must be done through typescript (press CTRL-' to access the Typescript window). You can alter the settings as follows:
CorrespondenceMethod I : 0 { Default method } CorrespondenceMethod I : 1 { Positional Correspondence } CorrespondenceMethod I : 2 { Associational Correspondence } CorrespondenceMethod I : 3 { Flex correspondence }
Enable comment auto-refresher