# Queries for a Single idco Format Table¶

class larch.core.QuerySetSimpleCO

This subclass of core.QuerySet is used when the data consists exclusively of a single idco Format format table.

Note

This is similar to the data format required by Biogeme. Unlike Biogeme, the Larch DB allows non-numeric values in the source data.

idco_query

This attribute defines a SQL query that evaluates to an larch_idco table. The table should have the following features:

• Column 1: caseid (integer) a key for every case observed in the sample
• Column 2+ can contain any explanatory data, typically numeric data, although non-numeric data is allowable.

If the main table is named “data” typically this query will be:

SELECT _rowid_ AS caseid, * FROM data

alts_query

This attribute defines a SQL query that evaluates to an larch_alternatives table. The table should have the following features:

• Column 1: id (integer) a key for every alternative observed in the sample
• Column 2: name (text) a name for each alternative
alts_values

This attribute defines a set of alternative codes and names, as a dictionary that contains {integer:string} key/value pairs, where each key is an integer value corresponding to an alternative code, and each value is a string giving a descriptive name for the alternative. When assigning to this attribute, a query is defined that can be used with no table.

Warning

Using this method will overwrite alts_query

choice

This attributes defines the choices. It has two styles

• When set to a string, the string names the column of the main table that identifies the choice for each case. The indicated column should contain integer values corresponding to the alternative codes.
• When set to a dict, the dict should contain {integer:string} key/value pairs, where each key is an integer value corresponding to an alternative code, and each value is a string identifying a column in the main table; that column should contain a value indication whether the alternative was chosen. Usually this will be a binary dummy variable, although it need not be. For certain specialized models, values other than 0 or 1 may be appropriate.

The choice of style is a matter of convenience; the same data can be expressed with either style as long as the choices are binary.

avail

This attributes defines the availability of alternatives for each case. If set to True, then all alternatives are available to all cases. Otherwise, this attribute should be a dict that contains {integer:string} key/value pairs, where each key is an integer value corresponding to an alternative code, and each value is a string identifying a column in the main table; that column should contain a value indicating whether the alternative is available. This must be a binary dummy variable.

weight

This attribute names the column in the main table that defines the weight for each case. Set it to an empty string, or 1.0, to assign all cases equal weight.