larch.ModelGroup#

class ModelGroup(models, title=None)[source]#

Bases: ConstrainedModel, MutableSequence

A group of models that can be treated as a single model for estimation.

This structure collects a group of models for simultaneous estimation. Each component model is a separate Model object, but they can share parameters. This sharing is controlled by parameter names, in that if two models in the group have a parameter with the same name, they will be treated as a common parameter. There is no requirement that the linked parameters be used in the same way in each model, but since they are treated as a single parameter, they will be estimated together, and must have the same bounds and constraints.

The model group object acts like a list of Model objects (i.e., a MutableSequence), and can be indexed, sliced, and iterated over.

Parameters:
  • models (list of Model or ModelGroup) – A list of models to include in the group. Each model can be a Model object or another ModelGroup object. If a ModelGroup is included, its submodels are each included in the group, and the ModelGroup itself is not included.

  • title (str, optional) – A title for the model group. This is used for display purposes and does not affect the estimation.

__init__(models, title=None)[source]#

Methods

__init__(models[, title])

add_parameter_array(name, values)

append(value)

S.append(value) -- append value to the end of the sequence

availability_def([new_def])

Get or set the definition of the availability variable.

bhhh([x, return_dataframe])

calculate_parameter_covariance([pvals, robust])

Calculate the parameter covariance matrix.

choice_def([new_def])

Get or set the definition of the choice variable.

clear()

clear_cache()

Remove all cached log likelihood values and estimation results.

constraint_violation([on_violation, ...])

Check if constraints are currently violated.

count(value)

d2_loglike([x, start_case, stop_case, step_case])

Compute the Hessian matrix of the log likelihood.

d_loglike([x, return_series])

Compute the gradient of the log likelihood of the group of models.

d_logloss([x, start_case, stop_case, step_case])

distribution_on_idca_variable(x[, xlabel, ...])

Generate a figure of observed and modeled choices over a range of variable values.

distribution_on_idco_variable(x[, xlabel, ...])

Generate a figure of variables over a range of variable values.

doctor(**kwargs)

Run diagnostics, checking for common problems and inconsistencies.

estimate(*args, **kwargs)

Maximize loglike, and then calculate parameter covariance.

estimation_statistics([compute_loglike_null])

Create an XHTML summary of estimation statistics.

estimation_statistics_raw([compute_loglike_null])

Compile estimation statistics as a pandas Series.

extend(values)

S.extend(iterable) -- extend sequence by appending elements from the iterable

fit_bhhh(*args, **kwargs)

get_param_loc(name)

Get the position of a named parameter.

get_value(name, *[, default, kind])

index(value, [start, [stop]])

Raises ValueError if the value is not present.

initialize_graph([alternative_codes, ...])

Write a nesting tree graph for a MNL model.

insert(i, value)

S.insert(index, value) -- insert value before index

load_data(*args, **kwargs)

No-op.

lock_value([name, value])

Set a fixed value for a model parameter.

loglike([x, check_if_best])

Compute the log likelihood of the group of models.

loglike2_bhhh([x, return_series])

loglike_casewise([x])

Compute the log likelihood case-by-case for the group of models.

loglike_null([use_cache])

Compute the log likelihood at null values.

logloss([x, start_case, stop_case, ...])

mangle([data, structure])

maximize_loglike(*args, **kwargs)

Maximize the log likelihood.

parameter_summary()

Create a tabular summary of parameter values.

plock([values])

Lock the values of one or more parameters.

pop([index])

Raise IndexError if list is empty or index is out of range.

pretty_table()

reflow_data_arrays()

Reload the internal data_arrays so they are consistent with the datatree.

remove(value)

S.remove(value) -- remove first occurrence of value.

required_data()

Report what data is required in DataFrames for this model to be used.

reverse()

S.reverse() -- reverse IN PLACE

set_cap([cap])

Set limiting values for one or more parameters.

set_value(name[, value, initvalue, ...])

Set the value one or more attributes of a single parameter.

set_values([values])

Set the parameter values for one or more parameters.

swap_datatree(tree[, should_mangle])

Swap the current datatree with a new datatree.

to_xlsx(filename[, save_now, ...])

Write the estimation results to an Excel file.

total_weight()

Compute the total weight across all models in the group.

unmangle([force, structure_only])

update_parameters(x)

utility_functions([subset, resolve_parameters])

Generate an XHTML output of the utility function(s).

Attributes

autoscale_weights

Whether to automatically scale case weights.

availability_any

A flag indicating whether availability should be inferred from the data.

availability_ca_var

An idca variable or expression indicating if alternatives are available.

availability_co_vars

A mapping giving idco expressions that evaluate to availability indicators.

availability_var

choice_any

choice_ca_var

An idca variable giving the choices as indicator values.

choice_co_code

An idco variable giving the choices as alternative id's.

choice_co_vars

A mapping giving idco expressions that evaluate to indicator values.

compute_engine

constraint_intensity

A simple attribute descriptor.

constraint_sharpness

A simple attribute descriptor.

constraints

data

dataset

Data arrays as loaded for model computation.

datatree

A source for data for the model.

graph

ident

Getter method for the ident property.

is_mangled

logsum_parameter

mixtures

most_recent_estimation_result

A copy of the result dict from most recent likelihood maximization.

n_cases

Total number of cases in all submodels.

n_params

ordering

A simple attribute descriptor.

parameters

pbounds

A copy of the current min-max bounds of the parameters.

pf

A DataFrame of the model parameters.

pholdfast

An array indicating which parameters are marked as holdfast.

pinitvals

An array of the initial parameter values.

pmaximum

An array of the current parameter maximum values.

pminimum

An array of the current parameter minimum values.

pnames

An array of the current parameter names.

pnullvals

An array of the current parameter null values.

possible_overspecification

Possible overspecification of the model.

pstderr

An array of the current parameter standard errors.

pvals

An array of the current parameter values.

quantity_ca

The portion of the quantity function computed from idca data.

quantity_scale

rename_parameters

A simple attribute descriptor.

title

A simple attribute descriptor.

use_streaming

utility_ca

The portion of the utility function computed from idca data.

utility_co

The portion of the utility function computed from idco data.

weight_co_var