Difference between revisions of "Table Splicing"

(Functionality of defaults filled in.)
(correspondence method)
Line 87: Line 87:
  
 
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.
 
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, Analytica must determine the correspondence between the previous and new values of the index.  This correspondence determines how tables that depend on the index are adjusted, and which data within a table are preserved or lost.
 +
 +
Three methods are possible:
 +
* Purely positional correspondence
 +
* Purely associational correspondence
 +
* Flexible correspondence (the default)
 +
 +
With positional correspondence, the data in the first row of your table will remain in the first row, the data in the second row remains in the second row, etc.
 +
 +
With associational, the data in the row with index element 'a' will remain in the row corresponding to index element 'a', even if other rows are inserted.  If the index elements are permuted (such as being sorted or shuffled), the data in the table is also sorted/shuffled.  If an element's name changes, data in that row of the table will be lost.
 +
 +
Flexible correspondence preserves associational correspondences wherever possible, but also recognizes spaces between matched labels positionally.  Thus, if a section of labels are renamed, the data for those rows will not be lost.  This is the default method. 
 +
 +
You can control the correspondence method using the '''''CorrespondenceMethod''''' attribute.  '''''Important:''''' The correspondence method is an attribute of the index, not of individual tables.  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 }

Revision as of 00:26, 7 March 2007

(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.

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

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, Analytica must determine the correspondence between the previous and new values of the index. This correspondence determines how tables that depend on the index are adjusted, and which data within a table are preserved or lost.

Three methods are possible:

  • Purely positional correspondence
  • Purely associational correspondence
  • Flexible correspondence (the default)

With positional correspondence, the data in the first row of your table will remain in the first row, the data in the second row remains in the second row, etc.

With associational, the data in the row with index element 'a' will remain in the row corresponding to index element 'a', even if other rows are inserted. If the index elements are permuted (such as being sorted or shuffled), the data in the table is also sorted/shuffled. If an element's name changes, data in that row of the table will be lost.

Flexible correspondence preserves associational correspondences wherever possible, but also recognizes spaces between matched labels positionally. Thus, if a section of labels are renamed, the data for those rows will not be lost. This is the default method.

You can control the correspondence method using the CorrespondenceMethod attribute. Important: The correspondence method is an attribute of the index, not of individual tables. 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 }
Comments


You are not allowed to post comments.